Datasets:
AI4M
/

text
stringlengths
0
3.34M
import combinatorics.simple_graph.coloring --OUTPUT 1 theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := begin split, { assume h1 : G.colorable 2, have h2 : ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from exists.intro (fintype.elems G.V) (exists.intro (fintype.elems G.V) (exists.intro rfl)), show ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from h2, }, { assume h1 : ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), have h2 : G.colorable 2, from h1.elim (assume A, assume B, assume h, assume h1, h1), show G.colorable 2, from h2, }, end --OUTPUT 2 theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := sorry /--`theorem` -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [f end --Needs more than 2000 tokens! --OUTPUT 3 theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := begin split, { assume h, have h1 : ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h, cast_le, simple_graph.subset_iff_subgraph, bipartite_iff_two_colorable], show (G.colorable 2) → (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)), from by auto [h1], }, { assume h, have h1 : ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h], show (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) → (G.colorable 2), from by auto [h1, cast_le, simple_graph.subset_iff_subgraph, bipartite_iff_two_colorable], }, end --OUTPUT 4 theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := begin split, { assume h1, rcases h1 with ⟨f, hf⟩, let A := {x | f x = 0}, let B := {x | f x = 1}, have h2 : (A ⊕ B) = V, from by auto [set.ext, set.mem_def, set.mem_set_of_eq], have h3 : (A ⊕ B) ≃ V, from by auto [h2, equiv.set.ext], have h4 : (A ⊕ B) ≃ V, from by auto [h2, equiv.set.ext], have h5 : cast (congr_arg _ h3) (complete_bipartite_graph A B) = complete_bipartite_graph A B, from by auto [cast_eq_of_heq], have h6 : G ≤ cast (congr_arg _ h2) (complete_bipartite_graph A B), from by auto [h5, hf, set.subset_def, set.mem_def, set.mem_set_of_eq, set.mem_set_of_eq], show ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h2, h6], }, { assume h1, rcases h1 with ⟨A, B, h2, h3⟩, let f : V → fin 2, from by auto [h2, cast_eq_of_heq, complete_bipartite_graph.colorable_of_bipartite], have h4 : G.colorable 2, from by auto [f], show G.colorable 2, from by auto [h4], }, end --OUTPUT 5 theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := begin split, { assume h1 : G.colorable 2, have h2 : ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from begin let A := {v : V | (G.coloring v) = 1}, let B := {v : V | (G.coloring v) = 2}, have h2 : (A ⊕ B) = V, from by auto [set.ext, set.mem_union, set.mem_compl, set.mem_set_of_eq], have h3 : G ≤ cast (congr_arg _ h2) (complete_bipartite_graph A B), from begin assume (u v : V), assume h3 : G.adj u v, have h4 : (G.coloring u) ≠ (G.coloring v), from by auto [h1, h3], have h5 : (G.coloring u) = 1 ∨ (G.coloring u) = 2, from by auto [h1], have h6 : (G.coloring v) = 1 ∨ (G.coloring v) = 2, from by auto [h1], have h7 : u ∈ A ∨ u ∈ B, from by auto [h5], have h8 : v ∈ A ∨ v ∈ B, from by auto [h6], have h9 : (cast (congr_arg _ h2) (complete_bipartite_graph A B)).adj u v, from by auto [h7, h8, set.mem_union, set.mem_compl, set.mem_set_of_eq, complete_bipartite_graph, h4], show G.adj u v, from by auto [h9], end, show ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h2, h3], end, show (G.colorable 2) → (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)), from by auto [h2], }, { assume h1 : (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)), have h2 : (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)), from by auto [h1], have h3 : G.colorable 2, from begin let A := {v : V | (G.coloring v) = 1}, let B := {v : V | (G.coloring v) = 2}, have h3 : (A ⊕ B) = V, from by auto [set.ext, set.mem_union, set.mem_compl, set.mem_set_of_eq], have h4 : G ≤ cast (congr_arg _ h3) (complete_bipartite_graph A B), from begin assume (u v : V), assume h4 : G.adj u v, have h5 : (G.coloring u) ≠ (G.coloring v), from by auto [h1, h4], have h6 : (G.coloring u) = 1 ∨ (G.coloring u) = 2, from by auto [h1], have h7 : (G.coloring v) = 1 ∨ (G.coloring v) = 2, from by auto [h1], have h8 : u ∈ A ∨ u ∈ B, from by auto [h6], have h9 : v ∈ A ∨ v ∈ B, from by auto [h7], have h10 : (cast (congr_arg _ h3) (complete_bipartite_graph A B)).adj u v, from by auto [h8, h9, set.mem_union, set.mem_compl, set.mem_set_of_eq, complete_bipartite_graph, h5], show G.adj u v, from by auto [h10], end, have h5 : (G.coloring 1) = 1 ∧ (G.coloring 2) = 2, from by auto [h4, complete_bipartite_graph, set.mem_union, set.mem_compl, set.mem_set_of_eq], have h6 : (G.coloring 1) = 1 ∨ (G.coloring 1) = 2, from by auto [h5], have h7 : (G.coloring 2) = 1 ∨ (G.coloring 2) = 2, from by auto [h5], have h8 : (G.coloring 1) ≠ (G.coloring 2), from by auto [h6, h7], show G.colorable 2, from by auto [h6, h7, h8], end, show (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) → (G.colorable 2), from by auto [h3], }, end --OUTPUT 6 theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := begin split, { assume h1, have h2 : ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h1, complete_bipartite_graph, graph.colorable_def, graph.edge, graph.vertex, graph.edge_def, graph.vertex_def, graph.subgraph_def, graph.subgraph_def, graph.subgraph_def], show ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h2], }, { assume h1, have h2 : ∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B), from by auto [h1], have h3 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h2], have h4 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h3], have h5 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h4], have h6 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h5], have h7 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h6], have h8 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h7], have h9 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h8], have h10 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h9], have h11 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h10], have h12 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h11], have h13 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h12], have h14 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h13], have h15 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h14], have h16 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h15], have h17 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h16], have h18 : ∃ (A B : Type*) (h : (A ⊕ B) = V), ∀ (x y : A ⊕ B), (x ≠ y) → (G.edge x y) → (x.elim (λ x, y.elim (λ y, ff) (λ y, tt)) (λ x, y.elim (λ y, tt) (λ y, ff))), from by auto [h17], end --Needs more than 2000 tokens! /- FEW SHOT PROMPTS TO CODEX(START) /--`theorem` Power Set is Closed under Intersection Let $S$ be a set. Let $\powerset S$ be the power set of $S$. Then: :$\forall A, B \in \powerset S: A \cap B \in \powerset S$ `proof` Let $A, B \in \powerset S$. Then by the definition of power set, $A \subseteq S$ and $B \subseteq S$. From Intersection is Subset we have that $A \cap B \subseteq A$. It follows from Subset Relation is Transitive that $A \cap B \subseteq S$. Thus $A \cap B \in \powerset S$ and closure is proved. {{qed}} -/ theorem power_set_intersection_closed {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S := begin assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S), have h1 : (A ⊆ S) ∧ (B ⊆ S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset], have h2 : (A ∩ B) ⊆ A, from by auto [set.inter_subset_left], have h3 : (A ∩ B) ⊆ S, from by auto [set.subset.trans], show (A ∩ B) ∈ 𝒫 S, from by auto [set.mem_powerset], end /--`theorem` Square of Sum :$\forall x, y \in \R: \paren {x + y}^2 = x^2 + 2 x y + y^2$ `proof` Follows from the distribution of multiplication over addition: {{begin-eqn}} {{eqn | l = \left({x + y}\right)^2 | r = \left({x + y}\right) \cdot \left({x + y}\right) }} {{eqn | r = x \cdot \left({x + y}\right) + y \cdot \left({x + y}\right) | c = Real Multiplication Distributes over Addition }} {{eqn | r = x \cdot x + x \cdot y + y \cdot x + y \cdot y | c = Real Multiplication Distributes over Addition }} {{eqn | r = x^2 + 2xy + y^2 | c = }} {{end-eqn}} {{qed}} -/ theorem square_of_sum (x y : ℝ) : (x + y)^2 = (x^2 + 2*x*y + y^2) := begin calc (x + y)^2 = (x+y)*(x+y) : by auto [sq] ... = x*(x+y) + y*(x+y) : by auto [add_mul] ... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring] ... = x^2 + 2*x*y + y^2 : by auto [sq, mul_comm] using [ring] end /--`theorem` Identity of Group is Unique Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$. `proof` From Group has Latin Square Property, there exists a unique $x \in G$ such that: :$a x = b$ and there exists a unique $y \in G$ such that: :$y a = b$ Setting $b = a$, this becomes: There exists a unique $x \in G$ such that: :$a x = a$ and there exists a unique $y \in G$ such that: :$y a = a$ These $x$ and $y$ are both $e$, by definition of identity element. {{qed}} -/ theorem group_identity_unique {G : Type*} [group G] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a := begin have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by auto using [use (a⁻¹ * b)], have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by auto using [use b * a⁻¹], have h3 : ∀ a : G, ∃! x : G, a * x = a, from by auto [h1], have h4 : ∀ a : G, ∃! y : G, y * a = a, from by auto [h2], have h5 : ∀ a : G, classical.some (h3 a).exists = (1 : G), from by auto [exists_unique.unique, h3, classical.some_spec, exists_unique.exists, mul_one], have h6 : ∀ a : G, classical.some (h4 a).exists = (1 : G), from by auto [exists_unique.unique, h4, classical.some_spec, exists_unique.exists, one_mul], show ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by auto [h3, h4, exists_unique.unique, classical.some_spec, exists_unique.exists] using [use (1 : G)], end /--`theorem` Bipartite Graph is two colorable Let $G$ be a graph. Then $G$ is 2-colorable if and only if $G$ is bipartite. `proof` Let $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color. Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue. Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$. This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite. Conversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$. Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable. QED -/ theorem bipartite_iff_two_colorable {V : Type*} (G : simple_graph V) [fintype V] : (G.colorable 2) ↔ (∃ (A B : Type*) (h : (A ⊕ B) = V), G ≤ cast (congr_arg _ h) (complete_bipartite_graph A B)) := FEW SHOT PROMPTS TO CODEX(END)-/
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} #if __GLASGOW_HASKELL__ >= 800 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-} #endif -- | -- Module : Graphics.Image.Interface.Repa.Generic -- Copyright : (c) Alexey Kuleshevich 2017 -- License : BSD3 -- Maintainer : Alexey Kuleshevich <[email protected]> -- Stability : experimental -- Portability : non-portable -- module Graphics.Image.Interface.Repa.Generic ( RImage , Strategy(..) , computeR , makeImageR , dimsR , scalarR , index00R , makeImageWindowedR , mapR , imapR , eqR , zipWithR , izipWithR , unsafeTraverseR , traverseR , unsafeTraverse2R , traverse2R , transposeR , backpermuteR , fromListsR , foldR , foldIxR , toVectorUnboxedR , fromVectorUnboxedR , toVectorStorableR , fromVectorStorableR , fromRepaArrayR , multR , ix2sh , sh2ix )where import Data.Array.Repa as R import Data.Array.Repa.Eval as R (Elt (..), Target, fromList, suspendedComputeP) import Data.Array.Repa.Operators.Traversal as R import Data.Array.Repa.Repr.ForeignPtr import Data.Array.Repa.Repr.Partitioned (P, Range (..)) import Data.Array.Repa.Repr.Unboxed (Unbox) import Data.Array.Repa.Repr.Undefined (X) import Data.Complex as C import Data.Maybe (listToMaybe) import qualified Data.Vector.Storable as VS import qualified Data.Vector.Unboxed as VU import Graphics.Image.ColorSpace.Binary (Bit (..)) import Graphics.Image.Interface (ColorSpace (..), Pixel, checkDims, toIx) import Prelude as P data Strategy = Parallel | Sequential data RImage r p = RTImage !(R.Array r R.DIM2 p) | RDImage !(R.Array R.D R.DIM2 p) sh2ix :: DIM2 -> (Int, Int) sh2ix (Z :. i :. j) = (i, j) {-# INLINE sh2ix #-} ix2sh :: (Int, Int) -> DIM2 ix2sh !(i, j) = Z :. i :. j {-# INLINE ix2sh #-} errorR :: String -> String -> a errorR fName errMsg = error $ "Graphics.Image.Interface.Repa.Generic." P.++ fName P.++ ": " P.++ errMsg checkDimsR :: String -> (Int, Int) -> DIM2 checkDimsR fName = ix2sh . checkDims ("Graphics.Image.Interface.Repa.Generic." P.++ fName) {-# INLINE checkDimsR #-} dimsR :: Source r p => RImage r p -> (Int, Int) dimsR (RTImage arr) = sh2ix $ R.extent arr dimsR (RDImage arr) = sh2ix $ R.extent arr {-# INLINE dimsR #-} makeImageR :: (Int, Int) -> ((Int, Int) -> px) -> RImage t px makeImageR sz f = RDImage $ R.fromFunction (checkDimsR "makeImageR" sz) (f . sh2ix) {-# INLINE makeImageR #-} makeImageWindowedR :: (Int, Int) -> (Int, Int) -> (Int, Int) -> ((Int, Int) -> p) -> ((Int, Int) -> p) -> RImage r p makeImageWindowedR !sz !wIx !wSz getWindowPx getBorderPx = RDImage $ R.delay $ makeWindowed sh wIx wSz wArr bArr where wArr = R.fromFunction sh (getWindowPx . sh2ix) bArr = R.fromFunction sh (getBorderPx . sh2ix) !sh = checkDimsR "makeImageWindowedR" sz {-# INLINE makeImageWindowedR #-} makeWindowed :: (Source r1 p, Source r2 p) => DIM2 -- ^ Extent of array. -> (Int, Int) -- ^ Window starting index -> (Int, Int) -- ^ Window size. -> Array r1 DIM2 p -- ^ Array for internal elements. -> Array r2 DIM2 p -- ^ Array for border elements. -> Array (P r1 (P r2 (P r2 (P r2 (P r2 X))))) DIM2 p makeWindowed sh@(Z :. m :. n) !(it, jt) !(wm, wn) arrWindow arrBorder = let inInternal (Z :. i :. j) = i >= it && i < ib && j >= jt && j < jb {-# INLINE inInternal #-} inBorder = not . inInternal {-# INLINE inBorder #-} !(ib, jb) = (wm + it, wn + jt) in APart sh (Range (Z :. it :. jt) (Z :. wm :. wn ) inInternal) arrWindow $ APart sh (Range (Z :. 0 :. 0 ) (Z :. it :. n ) inBorder ) arrBorder $ APart sh (Range (Z :. it :. 0 ) (Z :. wm :. jt ) inBorder ) arrBorder $ APart sh (Range (Z :. it :. jb) (Z :. wm :. (n - jb)) inBorder ) arrBorder $ APart sh (Range (Z :. ib :. 0 ) (Z :. (m - ib) :. n ) inBorder ) arrBorder $ AUndefined sh {-# INLINE makeWindowed #-} fromRepaArrayR :: (Source r1 p) => R.Array r1 DIM2 p -> RImage r p fromRepaArrayR = RDImage . R.delay {-# INLINE fromRepaArrayR #-} scalarR :: p -> RImage t p scalarR = RDImage . fromFunction (Z :. 1 :. 1) . const {-# INLINE scalarR #-} index00R :: Source r e => RImage r e -> e index00R (RTImage arr) = R.index arr (Z :. 0 :. 0) index00R (RDImage arr) = R.index arr (Z :. 0 :. 0) {-# INLINE index00R #-} mapR :: Source r1 a => (a -> p) -> RImage r1 a -> RImage r p mapR f (RTImage arr) = RDImage (R.map f arr) mapR f (RDImage arr) = RDImage (R.map f arr) {-# INLINE mapR #-} imapR :: Source r2 b => ((Int, Int) -> b -> p) -> RImage r2 b -> RImage r p imapR f (RTImage arr) = RDImage (imapArr (f . sh2ix) arr) imapR f (RDImage arr) = RDImage (imapArr (f . sh2ix) arr) {-# INLINE imapR #-} imapArr :: R.Source r2 b => (DIM2 -> b -> c) -> R.Array r2 DIM2 b -> R.Array R.D DIM2 c imapArr f !arr = R.traverse arr id (\ getPx !sh -> f sh (getPx sh)) {-# INLINE imapArr #-} getDelayed :: Source r e => RImage r e -> Array D DIM2 e getDelayed (RTImage arr) = delay arr getDelayed (RDImage arr) = arr {-# INLINE getDelayed #-} zipWithR :: (Source r2 t, Source r1 e) => (t -> e -> c) -> RImage r2 t -> RImage r1 e -> RImage r c zipWithR f !img1 !img2 = zipWithArr f (getDelayed img1) (getDelayed img2) {-# INLINE zipWithR #-} zipWithArr :: (Source r1 a, Source r2 b) => (a -> b -> c) -> Array r1 DIM2 a -> Array r2 DIM2 b -> RImage r c zipWithArr f arr1 arr2 = RDImage $ case (extent arr1, extent arr2) of (Z :. 1 :. 1, _) -> R.map (f (unsafeIndex arr1 (Z :. 0 :. 0))) arr2 (_, Z :. 1 :. 1) -> R.map (`f` (unsafeIndex arr2 (Z :. 0 :. 0))) arr1 _ -> R.zipWith f arr1 arr2 {-# INLINE zipWithArr #-} izipWithR :: (Source r2 a, Source r1 b) => ((Int, Int) -> a -> b -> c) -> RImage r2 a -> RImage r1 b -> RImage r c izipWithR f !img1 !img2 = izipWithArr f (getDelayed img1) (getDelayed img2) {-# INLINE izipWithR #-} izipWithArr :: (Source r1 a, Source r2 b) => ((Int, Int) -> a -> b -> c) -> Array r1 DIM2 a -> Array r2 DIM2 b -> RImage r c izipWithArr f arr1 arr2 = RDImage $ case (extent arr1, extent arr2) of (Z :. 1 :. 1, _) -> imapArr (\ !sh -> f (sh2ix sh) (unsafeIndex arr1 (Z :. 0 :. 0))) arr2 (_, Z :. 1 :. 1) -> imapArr (\ !sh !px1 -> f (sh2ix sh) px1 (unsafeIndex arr2 (Z :. 0 :. 0))) arr1 (Z :. m1 :. n1, Z :. m2 :. n2) -> traverse2 arr1 arr2 getNewDims getNewPx where getNewDims _ _ = Z :. min m1 m2 :. min n1 n2 {-# INLINE getNewDims #-} getNewPx getPx1 getPx2 !sh = f (sh2ix sh) (getPx1 sh) (getPx2 sh) {-# INLINE getNewPx #-} {-# INLINE izipWithArr #-} traverseR :: Source r1 c => RImage r1 c -> ((Int, Int) -> (Int, Int)) -> (((Int, Int) -> c) -> (Int, Int) -> p) -> RImage r p traverseR img getNewDims getNewPx = RDImage $ R.traverse (getDelayed img) (checkDimsR "traverseR" . getNewDims . sh2ix) (\ getPx -> getNewPx (getPx . ix2sh) . sh2ix) {-# INLINE traverseR #-} unsafeTraverseR :: Source r1 c => RImage r1 c -> ((Int, Int) -> (Int, Int)) -> (((Int, Int) -> c) -> (Int, Int) -> p) -> RImage r p unsafeTraverseR img getNewDims getNewPx = RDImage $ R.unsafeTraverse (getDelayed img) (checkDimsR "traverseR" . getNewDims . sh2ix) (\ getPx -> getNewPx (getPx . ix2sh) . sh2ix) {-# INLINE unsafeTraverseR #-} traverse2R :: (Source r1 a, Source r2 b) => RImage r1 a -> RImage r2 b -> ((Int, Int) -> (Int, Int) -> (Int, Int)) -> (((Int, Int) -> a) -> ((Int, Int) -> b) -> (Int, Int) -> c) -> RImage r c traverse2R img1 img2 getNewDims getNewPx = RDImage $ R.traverse2 (getDelayed img1) (getDelayed img2) (\ !sh1 !sh2 -> checkDimsR "traverse2R" (getNewDims (sh2ix sh1) (sh2ix sh2))) (\getPx1 getPx2 -> getNewPx (getPx1 . ix2sh) (getPx2 . ix2sh) . sh2ix) {-# INLINE traverse2R #-} unsafeTraverse2R :: (Source r1 a, Source r2 b) => RImage r1 a -> RImage r2 b -> ((Int, Int) -> (Int, Int) -> (Int, Int)) -> (((Int, Int) -> a) -> ((Int, Int) -> b) -> (Int, Int) -> c) -> RImage r c unsafeTraverse2R img1 img2 getNewDims getNewPx = RDImage $ R.unsafeTraverse2 (getDelayed img1) (getDelayed img2) (\ !sh1 !sh2 -> checkDimsR "traverse2R" (getNewDims (sh2ix sh1) (sh2ix sh2))) (\getPx1 getPx2 -> getNewPx (getPx1 . ix2sh) (getPx2 . ix2sh) . sh2ix) {-# INLINE unsafeTraverse2R #-} transposeR :: Source r1 p => RImage r1 p -> RImage r p transposeR (RDImage arr) = RDImage (R.transpose arr) transposeR (RTImage arr) = RDImage (R.transpose arr) {-# INLINE transposeR #-} backpermuteR :: R.Source r e => (Int, Int) -> ((Int, Int) -> (Int, Int)) -> RImage r e -> RImage r e backpermuteR !newDims g !img = RDImage $ R.backpermute (ix2sh (checkDims "backpermuteR" newDims)) (ix2sh . g . sh2ix) (getDelayed img) {-# INLINE backpermuteR #-} fromListsR :: Target r p => [[p]] -> RImage r p fromListsR ls = if all (== n) (P.map length ls) then RTImage $ R.fromList (Z :. m :. n) . concat $ ls else error "fromListsRepa: Inner lists do not all have an equal length." where !(m, n) = checkDims "fromListsRepa" (length ls, maybe 0 length $ listToMaybe ls) {-# INLINE fromListsR #-} multR :: (Num p, Elt p, Unbox p, Source r2 p, Source r1 p, Source r p, Target r p, Target r2 p, Target r1 p) => Strategy -> RImage r2 p -> RImage r1 p -> RImage r p multR strategy (RTImage arr1) (RTImage arr2) = if n1 /= m2 then errorR "multR" $ "Inner dimensions of multiplied images must be the same, but received: " P.++ show (m1, n1) P.++ " X " P.++ show (m2, n2) else computeR strategy $ RDImage $ fromFunction (Z :. m1 :. n2) getPx where (Z :. m1 :. n1) = R.extent arr1 (Z :. m2 :. n2) = R.extent arr2 getPx (Z :. i :. j) = R.sumAllS (R.slice arr1 (R.Any :. (i :: Int) :. R.All) R.*^ R.slice arr2 (R.Any :. (j :: Int))) {-# INLINE getPx #-} multR strategy img1 img2 = multR strategy (computeR strategy img1) (computeR strategy img2) {-# INLINE multR #-} computeR :: (Target r p, Source r p) => Strategy -> RImage r p -> RImage r p computeR Parallel (RDImage arr) = arrManifest `deepSeqArray` RTImage arrManifest where arrManifest = suspendedComputeP arr computeR Sequential (RDImage arr) = RTImage $ computeS arr computeR _ img = img {-# INLINE computeR #-} foldR :: (Source r p, Target r p, Elt p, Unbox p) => Strategy -> (p -> p -> p) -> p -> RImage r p -> p foldR Parallel f !px0 !img = let RTImage arr = computeR Parallel img in case foldAllP f px0 arr of Just e -> e Nothing -> errorR "foldPR" "impossible happened." foldR Sequential f !px0 img = let RTImage arr = computeR Sequential img in foldAllS f px0 arr {-# INLINE foldR #-} addIxArr :: Source r2 b => Array r2 DIM2 b -> Array R.D DIM2 (Int, b) addIxArr !arr = R.zipWith (,) arrIx arr where !sh = extent arr !arrIx = R.fromFunction (R.extent arr) (toIndex sh) {-# INLINE addIxArr #-} foldIxR :: (Source r b, Elt b, Unbox b) => Strategy -> (b -> (Int, Int) -> b -> b) -> b -> RImage r b -> b foldIxR strategy f !acc' !img = case strategy of Parallel -> case foldAllP accumWithIx (-1, acc') arr of Just (_, acc) -> acc Nothing -> error $ "foldIxPR: impossible happened." Sequential -> snd $ R.foldAllS accumWithIx (-1, acc') arr where (Z :. _ :. n) = extent arr !arr = addIxArr (getDelayed img) accumWithIx !(-1, acc) !(k, px) = (-1, f acc (toIx n k) px) accumWithIx !(k, px) (-1, acc) = (-1, f acc (toIx n k) px) accumWithIx (acc1Ix, _) (acc2Ix, _) = errorR "accumWithx" $ "Impossible happened. Received: " P.++ show acc1Ix P.++ " " P.++ show acc2Ix {-# INLINE accumWithIx #-} {-# INLINE foldIxR #-} eqR :: (Eq a, Source r1 a, Source r a) => Strategy -> RImage r1 a -> RImage r a -> Bool eqR strategy !img1 !img2 = case strategy of Parallel -> let eqArr = R.zipWith (==) (getDelayed img1) (getDelayed img2) in dimsR img1 == dimsR img2 && mCompute "eqR" (foldAllP (&&) True eqArr) Sequential -> R.equalsS (getDelayed img1) (getDelayed img2) {-# INLINE eqR #-} mCompute :: String -> Maybe t -> t mCompute _ (Just res) = res mCompute fName Nothing = errorR fName "impossible happened" {-# INLINE mCompute #-} fromVectorUnboxedR :: Unbox e => (Int, Int) -> VU.Vector e -> RImage U e fromVectorUnboxedR !sz = RTImage . fromUnboxed (ix2sh sz) {-# INLINE fromVectorUnboxedR #-} toVectorR :: (Target r2 e, Source r2 e) => (R.Array r2 DIM2 e -> t) -> Strategy -> RImage r2 e -> t toVectorR toVector Parallel (RDImage arr) = toVector $ mCompute "toVectorR" (computeP arr) toVectorR toVector Sequential (RDImage arr) = toVector $ computeS arr toVectorR toVector _ (RTImage arr) = toVector arr {-# INLINE toVectorR #-} toVectorUnboxedR :: Unbox e => Strategy -> RImage U e -> VU.Vector e toVectorUnboxedR = toVectorR toUnboxed {-# INLINE toVectorUnboxedR #-} toVectorStorableR :: VS.Storable e => Strategy -> RImage F e -> VS.Vector e toVectorStorableR = toVectorR toStorableR {-# INLINE toVectorStorableR #-} toStorableR :: VS.Storable a => Array F DIM2 a -> VS.Vector a toStorableR arr = VS.unsafeFromForeignPtr0 (toForeignPtr arr) (m * n) where (Z :. m :. n) = R.extent arr {-# INLINE toStorableR #-} fromVectorStorableR :: VS.Storable px => (Int, Int) -> VS.Vector px -> RImage F px fromVectorStorableR !(m, n) !v | sz == sz' = RTImage $ fromForeignPtr (ix2sh (m, n)) fp | otherwise = errorR "fromVectorStorableR" $ "(impossible) Vector size mismatch: " P.++ show sz P.++ " vs " P.++ show sz' where !(fp, sz) = VS.unsafeToForeignPtr0 v !sz' = m * n {-# INLINE fromVectorStorableR #-} instance (Num e, R.Elt e) => Elt (C.Complex e) where touch (r :+ i) = R.touch r >> R.touch i {-# INLINE touch #-} zero = 0 :+ 0 {-# INLINE zero #-} one = 1 :+ 0 {-# INLINE one #-} instance Elt Bit where touch (Bit w) = R.touch w {-# INLINE touch #-} zero = 0 {-# INLINE zero #-} one = 1 {-# INLINE one #-} instance (ColorSpace cs e, Elt e, Num (Pixel cs e)) => Elt (Pixel cs e) where touch = foldlPx (\ a !e -> a >> touch e) (return ()) {-# INLINE touch #-} zero = 0 {-# INLINE zero #-} one = 1 {-# INLINE one #-}
import geometry.tarski_7 linear_algebra.basic open classical set namespace Euclidean_plane variables {point : Type} [Euclidean_plane point] local attribute [instance, priority 0] prop_decidable -- Pappus, Pascal and Desargues theorem thirteen1 {a b c p q r : point} {A : set point} : ¬col a b c → M c p b → M c q a → M a r b → xperp r A (l a b) → perp A (l p q) := begin intros h h1 h2 h3 g1, have h4 : c ∉ l p q, intro h_1, suffices : line (l p q), apply h (six23.2 ⟨l p q, this, _, _, h_1⟩), rw seven6 h2, exact (seven24 this (six17b p q)).1 h_1, rw seven6 h1, exact (seven24 this (six17a p q)).1 h_1, apply six14, intro h_2, subst q, exact (six26 h).1 (seven4 h2 h1), cases exists_of_exists_unique (eight17 (six14 (six26 h4).1) h4) with c' hc, cases exists_of_exists_unique (eight22 (S q c') (S p c')) with x hx, cases exists_of_exists_unique (unique_perp x hc.1) with A' hA, suffices : A = A', exact this.symm ▸ hA.2.symm, apply unique_of_exists_unique (unique_xperp g1.2.1 g1.2.2.2.1) g1.symm, haveI h5 := (eight14e hA.2).2, suffices : Sl A' a = b, have h6 : a ∉ A', intro h_1, have h_2 := ten3b h5 h_1, exact (six26 h).1 (h_2.symm.trans this), have h7 := ten3a h5 h6, rw this at *, rw M_to_mid h3 at h7, exact eight15 h7.2.symm (or.inr (or.inl h3.1.symm)) h7.1, have h6 : l (S q c') (S p c') = l p q, exact (six18 hc.1 (seven18a c' (six13 hc.1).symm) ((seven24 hc.1 (six17b p q)).1 hc.2.2.1) ((seven24 hc.1 (six17a p q)).1 hc.2.2.1)).symm, have h7 : Sl A' (S q c') = S p c', apply (unique_of_Sl h5 _ _ _).symm, apply six21b, refine ⟨hc.1, h5, eight14a hA.2, _, hA.1⟩, rw ←h6, exact (or.inr (or.inl hx.1.symm)), intro h_1, subst x, exact (six13 hc.1).symm (seven18 (id_eqd hx.2.symm)), rw ←h6, simp, rw M_to_mid hx, exact hA.1, rw h6, exact hA.2.symm, have h8 : xperp (S q c') (l a (S q c')) (l (S q c') (S p c')), rw [seven6 h2, h6], apply (ten18 hc (six17b p q)).symm, have h9 : xperp (S p c') (l b (S p c')) (l (S q c') (S p c')), rw [seven6 h1, h6], apply (ten18 hc (six17a p q)).symm, apply six11a, suffices : side (l (S q c') (S p c')) a b, apply eleven15b (nine11 this).2.2 (nine11 this).2.2 _ _ _ (side.refla (nine11 this).2.2), rw seven6 h1, apply eleven16 (seven18a c' (six13 hc.1).symm) (seven9a p (six13 hc.2.1)) (seven18a c' (six13 hc.1).symm) _ _ _, rw ←h7, intro h_1, exact (six13 h8.1) (ten7 h_1), rw ←seven6 h1, exact (h9.2.2.2.2 (six17a b (S p c')) (six17a _ _)).symm, suffices : R (Sl A' (S p c')) (Sl A' (S q c')) (Sl A' a), rwa [←h7, ten5, h7] at this, apply (ten11d h5).1 (h8.2.2.2.2 (six17a a (S q c')) (six17b _ _)).symm, apply side.trans _ this, apply side.symm (twelve7.1 (dpar_of_par_neq _ _)).1, rw h6, apply twelve9 hA.2 (ten3a h5 _).2.symm, intro h_1, suffices : S q c' = x, subst x, exact (six13 hc.1).symm (seven18 (id_eqd hx.2.symm)), suffices : l a (S q c') = A', apply eight14d h8 _, rw this, refine eight15 _ hA.1 (or.inr (or.inl hx.1.symm)), simpa [h6] using hA.2.symm, rw ←h6 at *, exact unique_of_exists_unique (unique_perp a hc.1) ⟨six17a a (S q c'), S q c', h8.symm⟩ ⟨h_1, hA.2⟩, intro h_1, exact (nine11 this).2.1 (h_1.symm ▸ six17a a (Sl A' a)), exact eqa.refl (six26 (nine11 this).2.2).1 (six26 (nine11 this).2.2).2.1.symm, rw [h6, seven6 h2, seven6 h1], exact ⟨c, (nine16 (six14 (six26 h4).1) h4 (six17b p q)).symm, (nine16 (six14 (six26 h4).1) h4 (six17a p q)).symm⟩, apply (ten10 h5 (S p c') (Sl A' a)).trans, rw [←h7, ten5, ten5, seven6 h2, h7, seven6 h1], exact (seven13 q c' c).symm.trans (seven13 p c' c) end theorem thirteen1a (a : point) {p q : point} : p ≠ q → par (l p q) (l (S p a) (S q a)) := begin intro h, by_cases h_1 : col p q a, exact or.inr ⟨(six14 h), six18 (six14 h) (seven18a a h) ((seven24 (six14 h) (six17a p q)).1 h_1) ((seven24 (six14 h) (six17b p q)).1 h_1)⟩, cases exists_of_exists_unique (unique_xperp (six14 (seven18a a h)) (or.inr (or.inl (ten1 (S p a) (S q a)).1.symm))) with A ha, have h1 := thirteen1 _ (seven5 q a) (seven5 p a) (ten1 (S p a) (S q a)) ha.symm, rw six17 at h1, exact twelve9 h1.symm ⟨mid (S p a) (S q a), ha⟩, intro h_2, exact h_1 (six23.2 ⟨l (S p a) (S q a), six14 (seven18a a h), six27 (six14 (seven18a a h)) h_2 (six17a _ _) (seven5 p a).1, six27 (six14 (seven18a a h)) h_2 (six17b _ _) (seven5 q a).1, h_2⟩) end theorem thirteen2a {a b c d: point} {A : set point} : Bl c A d → xperp a A (l c a) → xperp b A (l d b) → ∃ p, B a p b ∧ B c p d := begin intros h h1 h2, cases h.2.2.2 with p hp, by_cases h_1 : a = b, subst b, suffices : p = a, subst p, exact ⟨a, three1 a a, hp.2⟩, refine six21a h.1 (six14 (nine2 h)) _ hp.1 (or.inr (or.inl hp.2.symm)) h1.2.2.1 _, intro h_1, subst h_1, exact h.2.1 (six17a c d), suffices : l c a = l d a, apply (four11 _).1, show d ∈ l c a, rw this, simp, exact unique_of_exists_unique (unique_perp a h.1) ⟨h1.2.2.2.1, a, h1⟩ ⟨h2.2.2.2.1, a, h2⟩, have h3 := six18 h.1 h_1 h1.2.2.1 h2.2.2.1, subst h3, refine ⟨p, _, hp.2⟩, cases (four11 hp.1).1, exact h_2, exfalso, rw three2 at h_2, revert c d, wlog h3 := h_2 using a b, intros, cases exists_of_exists_unique (unique_perp p h.1) with P hP, suffices : side P c d, exact nine9 ⟨(nine11 this).1, (nine11 this).2.1, (nine11 this).2.2, p, hP.1, hp.2⟩ this, suffices : side P a b, apply side.trans _ (this.trans _), apply twelve6 (dpar_of_par_neq (twelve9 hP.2.symm ⟨a, h1.symm⟩) _) (six17a c a) (six17b c a), intro h_2, subst h_2, exact (nine11 this).2.1 (six17b c a), apply twelve6 (dpar_of_par_neq (twelve9 hP.2.symm ⟨b, h2.symm⟩) _) (six17b d b) (six17a d b), intro h_2, subst h_2, exact (nine11 this).2.2 (six17b d b), suffices : b ≠ p, apply (nine12 (eight14e hP.2).2 hP.1 (six7 h3.symm this) _).symm, intro h_2, exact (eight14a hP.2) (six21 this h.1 (eight14e hP.2).2 (six17b a b) h_2 (or.inl h3) hP.1), intro h_2, subst p, have h4 := six18 h2.2.1 (six26 h.2.1).2.1.symm (or.inl hp.2.symm) (six17b d b), rw h4 at *, exact h_1 (unique_of_exists_unique (eight18 h.2.1) ⟨six17a a b, a, h1⟩ ⟨six17b a b, b, h2⟩), rw six17 b a at this, exact this (ne.symm h_1) h.symm h2 h1 ⟨hp.1, hp.2.symm⟩ end theorem thirteen2b {a b c d : point} : Bl c (l a b) d → R b c a → R b d a → Bl a (l c d) b := begin intros h h1 h2, cases exists_of_exists_unique (eight17 h.1 h.2.1) with x hx, cases exists_of_exists_unique (eight17 h.1 h.2.2.1) with y hy, have h3 := eleven47 h1.symm hx.symm, have h4 := eleven47 h2.symm hy.symm, cases thirteen2a h hx hy with p hp, have h5 := five7 h3.1 h4.1 hp.1, have h6 : is p (l a b) (l c d), refine ⟨h.1, six14 (nine2 h), _, or.inr (or.inl (h5).symm), or.inr (or.inl hp.2.symm)⟩, intro h_1, rw h_1 at h, exact h.2.1 (six17a c d), refine ⟨h6.2.1, _, _, p, h6.2.2.2.2, h5⟩, intro h_1, apply (six21b h6 _ (six17a a b)) h_1, intro h_2, subst p, cases five3 h3.1 h4.1, exact h3.2.1 (three4 hp.1 h_2), exact h4.2.1 (three4 hp.1.symm h_2), intro h_1, apply (six21b h6 _ (six17b a b)) h_1, intro h_2, subst p, cases five3 h3.1.symm h4.1.symm, exact h3.2.2 (three4 hp.1 h_2), exact h4.2.2 (three4 hp.1.symm h_2) end theorem thirteen2c {a b c d : point} : Bl c (l a b) d → Bl a (l c d) b → ∃ p, B a p b ∧ B c p d ∧ p ≠ a ∧ p ≠ b ∧ p ≠ c ∧ p ≠ d := begin intros h h1, cases h.2.2.2 with p hp, cases h1.2.2.2 with q hq, have : p = q, apply six21a h.1 h1.1 _ hp.1 (or.inr (or.inl hp.2.symm)) (or.inr (or.inl hq.2.symm)) hq.1, intro h_1, rw h_1 at h, exact h.2.1 (six17a c d), subst q, refine ⟨p, hq.2, hp.2, _⟩, repeat {split}; intro h_1; subst p, exact h1.2.1 hq.1, exact h1.2.2.1 hq.1, exact h.2.1 hp.1, exact h.2.2.1 hp.1 end theorem thirteen2 {a b c d e : point} : Bl c (l a b) d → R b c a → R b d a → xperp e (l a e) (l c d) → eqa b a c d a e ∧ eqa b a d c a e ∧ B c e d := begin intros h h1 h2 h3, have h4 : side (l a c) b d, cases thirteen2c h (thirteen2b h h1 h2) with t ht, apply nine15 _ ht.1 ht.2.1, intro h_1, exact h.2.1 (six23.2 ⟨l a t, six14 ht.2.2.1.symm, six17a a t, or.inl ht.1, (four11 h_1).1⟩), have h5 : ang_lt c a b c a d, cases thirteen2c h (thirteen2b h h1 h2) with t ht, suffices : ang_lt c a t c a d, exact eleven37 this (eleven9 (six5 (six26 h.2.1).2.2.symm) (six7 ht.1 ht.2.2.1).symm) (eqa.refl (six26 h.2.1).2.2.symm (six26 h.2.2.1).2.2.symm), exact eleven32d (four10 (nine11 h4).2.2).2.1 ht.2.2.2.2.2 ht.2.1, replace h5 := eleven42b h5, cases eleven32c (λ h_1, (four10 (nine11 h4).2.2).2.2.1 (or.inr (or.inl h_1))) h5 with e' he, have h6 : side (l a d) e' c, suffices : ¬col a d e', exact nine12 (six14 (six26 h.2.2.1).2.2) (six17b a d) (six7 he.2.1 (six26 this).2.1.symm) this, intro h_1, exact (four10 h.2.1).2.2.2.1 (eleven21d (four11 h_1).2.1 he.2.2.symm), have h7 : eqa b a d e' a c, exact eleven22b h4 h6 he.2.2.flip (eleven6 (six26 h.2.1).2.2.symm (six26 h.2.2.1).2.2.symm), suffices : e = e', subst e', exact ⟨eleven7 he.2.2, eleven8 h7, he.2.1.symm⟩, apply unique_of_exists_unique (eight17 h3.2.1 (four10 (nine11 h6).2.2).2.2.2.2) h3.symm _, refine eight15 _ (or.inr (or.inl he.2.1)) (six17b a e'), have h8 := (eqd.symm h1.symm).trans h2.symm, apply (thirteen1 _ (seven5 c b) (seven5 d b) (ten1 (S c b) (S d b)).symm _).symm, intro h_1, exact (thirteen2b h h1 h2).2.2.1 (six23.2 ⟨l (S d b) (S c b), six14 (seven18a b (nine2 h.symm)), six27 (six14 (seven18a b (nine2 h.symm))) (six17b _ _) h_1 (seven5 c b).1.symm, six27 (six14 (seven18a b (nine2 h.symm))) (six17a _ _) h_1 (seven5 d b).1.symm, h_1⟩), haveI ha := six14 he.2.2.2.2.2.1.symm, rw six17 (S d b) (S c b), suffices : Sl (l a e') (S c b) = S d b, rw ←this, refine eight15 (ten3a ha _).2 (ten3a ha _).1 (or.inr (or.inl (ten1 (S c b) (Sl (l a e') (S c b))).1.symm)); intro h_1; exact (seven18a b (nine2 h)) (this ▸ (ten3b ha h_1).symm), suffices : eqa (S c b) a e' (S d b) a e', cases eleven15d this.flip (six14 this.2.1), exact ((seven18a b (nine2 h)) (six11a h_1 h8)).elim, simp only [six17] at h_1, apply ten4.1, apply six11a h_1.symm, simpa [ten3b ha (six17a a e')] using (ten10 ha a (S d b)).symm.trans h8.symm, suffices : eqa (S c b) a c e' a d, apply eleven8 (eleven22a _ _ this _), apply ((nine8 (nine10a (nine11 h4).1 (six17b a c) (nine11 h4).2.1)).2 _).symm, exact nine19a h4 (six17b a c) (six7 he.2.1.symm he.1).symm, apply (nine8 (nine10a (nine11 h6).1 (six17b a d) (four10 h.2.2.1).1)).2 _, apply (h6.trans _).symm, cases thirteen2c h (thirteen2b h h1 h2) with t ht, apply (nine15 _ ht.1 ht.2.1.symm).symm, intro h_1, exact h.2.2.1 (six23.2 ⟨l a t, six14 ht.2.2.1.symm, six17a a t, or.inl ht.1, (four11 h_1).1⟩), apply h7.symm.flip.trans, replaceI h6 := (nine11 h6).1, suffices : S d b = Sl (l a d) b, rw this, simpa [ten3b h6 (six17a a d), ten3b h6 (six17b a d)] using eleven12a h6 h7.2.1 h7.1, apply unique_of_Sl h6 (four10 h.2.2.1).1 _ (perp_of_R h7.2.1.symm (six26 h.2.2.1).2.1 h2.symm), simp [mid_of_S d b, six17b a d], apply (he.2.2.symm.trans _).symm.flip, replaceI h4 := (nine11 h4).1, suffices : S c b = Sl (l a c) b, rw this, simpa [ten3b h4 (six17a a c), ten3b h4 (six17b a c)] using eleven12a h4 he.2.2.1 h7.1, apply unique_of_Sl h4 (four10 h.2.1).1 _ (perp_of_R he.2.2.1.symm (six26 h.2.1).2.1 h1.symm), simp [mid_of_S c b, six17b a c] end theorem thirteen7a {α : angle point} {C : dist point} (hα : acute α) (hc : ¬C = 0) (hα1 : ¬α = 0) : ∃ a b c (hab : a ≠ b) (hcb : c ≠ b), ⟦(a, b)⟧ = C ∧ R a c b ∧ α = ⟦⟨(a, b, c), hab, hcb⟩⟧ := begin rcases quotient.exists_rep α with ⟨⟨⟨p, b, q⟩, hpb, hqb⟩, h2⟩, subst α, change ang_acute p b q at hα, have hpbq : ¬col p b q, intro h_1, exact hα1 (zero_iff_sided.2 (sided_of_acute_col hα h_1)), rcases thirteen3 hpbq hc with ⟨⟨a, c⟩, h3, h, h4⟩, have h2 := h4.symm.2.2.2.2 (six17a a c) (six17a b q), have h5 : sided b q c, apply eleven48 (hα.trans (eleven9 h3.symm (six5 hqb))) h4.2.2.1 _ h2, dsimp, intro h_1, subst b, apply (eleven45a hα).1 ⟨hpb, hqb, h4.symm.2.2.2.2 (four11 (six4.1 h3).1).2.2.2.2 (six17b c q)⟩, exact ⟨a, b, c, h3.2.1, h5.2.1, eq.trans (quotient.sound (show (a, b) ≈ (b, a), from eqd_refl a b)) h, h2, quotient.sound (eleven9 h3.symm h5.symm)⟩ end theorem thirteen7b {β : angle point} {a b c : point} (hab : a ≠ b) : ¬col a b c → acute β → β ≠ 0 → ∃ d (hdb : d ≠ b), β = ⟦⟨(a, b, d), hab, hdb⟩⟧ ∧ Bl c (l b a) d ∧ R a d b := begin intros h h1 h2, rcases quotient.exists_rep β with ⟨⟨⟨p, q, r⟩, h3⟩, h4⟩, subst β, change ang_acute p q r at h1, replace h2 : ¬col p q r, intro h_1, apply h2 (zero_iff_sided.2 _), exact sided_of_acute_col h1 h_1, cases nine10 (six14 hab) h with t ht, cases eleven15a h2 ht.2.2.1 with s hs, cases exists_of_exists_unique (eight17 (six14 hs.1.2.2.2.1.symm) (four10 (nine11 hs.2).2.1).2.2.1) with d hd, have h3 : sided b s d, apply eleven48 (h1.trans hs.1) hd.2.2.1 _ (hd.symm.2.2.2.2 (six17a a d) (six17a b s)), intro h_1, subst d, exact (eleven45a (h1.trans hs.1)).1 ⟨hs.1.2.2.1, hs.1.2.2.2.1, hd.symm.2.2.2.2 (six17a a b) (six17b b s)⟩, refine ⟨d, h3.2.1, _, _, hd.symm.2.2.2.2 (six17a a d) (six17a b s)⟩, exact quotient.sound (hs.1.trans (eleven9 (six5 hab) h3.symm)), exact six17 a b ▸ ((nine8 ht.symm).2 (nine19a hs.2.symm (six17b a b) h3)).symm end theorem thirteen7c {α β : angle point} {C : dist point} : acute α → acute β → cos α (cos β C) = cos β (cos α C) := begin intros hα hβ, by_cases hc : C = 0, subst C, simp [cos_times_zero], by_cases hα1 : α = 0, subst α, rw [cos_zero, cos_zero], by_cases hβ1 : β = 0, subst β, rw [cos_zero, cos_zero], rcases thirteen7a hα hc hα1 with ⟨a, b, c, hab, hcb, h, h1, h2⟩, clear hc, subst_vars, change ang_acute a b c at hα, replace hα1 : ¬col a b c, intro h_1, apply hα1 (zero_iff_sided.2 _), exact sided_of_acute_col hα h_1, rcases thirteen7b hab hα1 hβ hβ1 with ⟨d, hdb, h2, hd⟩, subst β, rw [←thirteen5b hab hcb h1, ←thirteen5b hab hdb hd.2], have h2 := thirteen2b hd.1 h1 hd.2, cases exists_of_exists_unique (eight17 h2.1 h2.2.1) with e he, have h3 := thirteen2 hd.1 h1 hd.2 he.symm, suffices : cos ⟦⟨(d, b, e), hdb, h3.1.2.2.2.1⟩⟧ ⟦(d, b)⟧ = cos ⟦⟨(c, b, e), hcb, h3.1.2.2.2.1⟩⟧ ⟦(c, b)⟧, have h4 : (⟦⟨(a, b, c), hab, hcb⟩⟧ : angle point) = ⟦⟨(d, b, e), hdb, h3.1.2.2.2.1⟩⟧, exact quotient.sound h3.1, have h5 : (⟦⟨(a, b, d), hab, hdb⟩⟧ : angle point) = ⟦⟨(c, b, e), hcb, h3.1.2.2.2.1⟩⟧, exact quotient.sound h3.2.1, rwa [h4, h5], rw [←thirteen5b hdb h3.1.2.2.2.1 _, ←thirteen5b hcb h3.1.2.2.2.1 _], exact he.2.2.2.2 (six17a c d) (six17a b e), exact he.2.2.2.2 (six17b c d) (six17a b e) end theorem thirteen7 (α β : angle point) (C : dist point) : cos α (cos β C) = cos β (cos α C) := begin by_cases ha : right α, simp [cos_right ha, cos_right ha], by_cases hb : right β, simp [cos_right hb, cos_right hb], replace ha : acute α ∨ obtuse α, simpa [ha] using angle_trichotomy α, replace hb : acute β ∨ obtuse β, simpa [hb] using angle_trichotomy β, cases ha.symm, have h1 := supp_of_obtuse.1 h, rw cos_supp α, all_goals { cases hb.symm, have h2 := supp_of_obtuse.1 h_1, rw cos_supp β, all_goals { apply thirteen7c; assumption}} end lemma thirteen11a {o a b a' b' : point} : ¬col o a a' → col o a b → col o a' b' → b ≠ o → b' ≠ o → ¬col o a b' ∧ ¬col o b a' := begin sorry end lemma thirteen11b {o a b a' b' : point} : ¬col o a b' → ¬col o b a' → par (l a b') (l b a') → ∃ x x', xperp x (l o x) (l a b') ∧ xperp x' (l o x) (l b a') := begin sorry end lemma thirteen11c {o a b a' b' x x' : point} : ¬col o a a' → col o a b → col o a' b' → b ≠ o → b' ≠ o → par (l a b') (l b a') → xperp x (l o x) (l a b') → xperp x' (l o x) (l b a') → eqa a o x b o x' ∧ eqa a' o x' b' o x := begin sorry end lemma thirteen11d {o a b a' b' x x' : point} (h : eqa a o x b o x') (h1 : eqa a' o x' b' o x) : ¬col o a a' → col o a b → col o a' b' → b ≠ o → b' ≠ o → par (l a b') (l b a') → xperp x (l o x) (l a b') → xperp x' (l o x) (l b a') := begin sorry end theorem thirteen11 {o a b c a' b' c' : point} : ¬col o a a' → col o a b → col o a c → b ≠ o → c ≠ o → col o a' b' → col o a' c' → b' ≠ o → c' ≠ o → par (l b c') (l c b') → par (l c a') (l a c') → par (l a b') (l b a') := begin intros h h1 h2 h3 h4 h5 h6 h7 h8 h9 h10, sorry end end Euclidean_plane
Formal statement is: lemma norm_of_nat [simp]: "norm (of_nat n::'a::real_normed_algebra_1) = of_nat n" Informal statement is: The norm of a natural number is the natural number itself.
sizeof(bitRecord1): 1 sizeof(bitRecord2): 2 sizeof(bitRecord3): 3 sizeof(bitRecord4): 4 sizeof(bitRecord5): 5 sizeof(bitRecord6): 6 sizeof(bitRecord7): 7 sizeof(bitRecord8): 8 sizeof(bitRecord12): 12
import numpy def screen_stats(blinker_file_name, sensor_file_name): sensor_data = numpy.loadtxt(sensor_file_name) blinker_data = numpy.loadtxt(blinker_file_name) # Convert all times to milliseconds t_sensor = sensor_data[:, 0] * 1e3 t_vsync = blinker_data / 1e3 # Throw away any sensor timestamps earlier than the first blink # this may happen if the operator attached the sensor after # running the command. But this should be avoided. skip_sensor = sum(t_sensor < t_vsync[0]) if(skip_sensor): t_sensor = t_sensor[skip_sensor:] print('Skipped first %d readings from the sensor' % skip_sensor) # Get only the common size and skip the first blink, it's often weird. length = min(len(t_sensor), len(t_vsync)) t_sensor = t_sensor[1:length] t_vsync = t_vsync[1:length] # Shift time so that first time point is 0 t0 = min(t_vsync) t_sensor = t_sensor - t0 t_vsync = t_vsync - t0 dt = t_sensor - t_vsync # Look at even and odd transitions separately - black <-> white. dt_even = dt[0::2] dt_odd = dt[1::2] print('') print('dt = array([' + ', '.join('%0.2f' % x for x in dt) + '])') print('') print('Screen response times [ms]') print('Even: median %0.1f ms, stdev %0.2f ms' % (numpy.median(dt_even), numpy.std(dt_even))) print('Odd: median %0.1f ms, stdev %0.2f ms' % (numpy.median(dt_odd), numpy.std(dt_odd))) # Debug & test if __name__ == '__main__': fname = '/tmp/WALT_2016_06_22__1739_21_' blinker_file_name = fname + 'evtest.log' sensor_file_name = fname + 'laser.log' screen_stats(blinker_file_name, sensor_file_name)
[STATEMENT] theorem STL5_21: assumes h1: "stutinv F" and h2: "stutinv G" shows "\<turnstile> \<box>(F \<and> G) = (\<box>F \<and> \<box>G)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<turnstile> \<box>(F \<and> G) = (\<box>F \<and> \<box>G) [PROOF STEP] using h1[THEN pre_id_unch] h2[THEN pre_id_unch] [PROOF STATE] proof (prove) using this: |~ F \<and> Unchanged id \<longrightarrow> \<circle>F |~ G \<and> Unchanged id \<longrightarrow> \<circle>G goal (1 subgoal): 1. \<turnstile> \<box>(F \<and> G) = (\<box>F \<and> \<box>G) [PROOF STEP] by (rule STL5_2)
From Perennial.program_proof.mvcc Require Import proph_proof. From Perennial.program_proof.dmvcc Require Export txn_proof. Section program. Context `{!heapGS Σ, !mvcc_ghostG Σ}. Definition abort_false_cases tid γ : iProp Σ := (nca_tids_frag γ tid) ∨ (∃ mods, fci_tmods_frag γ (tid, mods)) ∨ (∃ mods, fcc_tmods_frag γ (tid, mods)) ∨ (∃ mods, cmt_tmods_frag γ (tid, mods)). Theorem wp_txn__abort_false txn tid view γ τ : {{{ own_txn_clerk txn tid view γ τ ∗ abort_false_cases tid γ }}} txn.Clerk__abort #txn {{{ RET #(); False }}}. Proof. iIntros (Φ) "[Htxn Hfrag] HΦ". wp_call. (***********************************************************) (* proph.ResolveAbort(txn.txnMgr.p, txn.tid) *) (***********************************************************) iNamed "Htxn". iNamed "Himpl". do 2 wp_loadField. wp_apply (wp_ResolveAbort); first auto. iInv "Hinv" as "> HinvO" "HinvC". iApply ncfupd_mask_intro; first set_solver. iIntros "Hclose". iNamed "HinvO". iExists future. iFrame "Hproph". iIntros "(%future' & %Hhead & Hproph)". (* Obtain contradiction for each case. *) unfold abort_false_cases. iDestruct "Hfrag" as "[HncaFrag | Hfrag]". { (* Case NCA. *) iNamed "Hnca". iDestruct (nca_tids_lookup with "HncaAuth HncaFrag") as "%Helem". apply Hnca in Helem. destruct (no_commit_abort_false Helem). right. set_solver. } iDestruct "Hfrag" as "[HfciFrag | Hfrag]". { (* Case FCI. *) iNamed "Hfci". iDestruct "HfciFrag" as (m') "HfciFrag". iDestruct (fci_tmods_lookup with "HfciAuth HfciFrag") as "%Helem". apply Hfci in Helem. simpl in Helem. destruct Helem as (lp & ls & Hfc & _). destruct (first_commit_false Hfc). set_solver. } iDestruct "Hfrag" as "[HfccFrag | HcmtFrag]". { (* Case FCC. *) iNamed "Hfcc". iDestruct "HfccFrag" as (m') "HfccFrag". iDestruct (fcc_tmods_lookup with "HfccAuth HfccFrag") as "%Helem". apply Hfcc in Helem. simpl in Helem. destruct Helem as (lp & ls & Hfc & _). destruct (first_commit_false Hfc). set_solver. } { (* Case CMT. *) iNamed "Hcmt". iDestruct "HcmtFrag" as (m') "HcmtFrag". iDestruct (cmt_tmods_lookup with "HcmtAuth HcmtFrag") as "%Helem". apply Hcmt in Helem. simpl in Helem. destruct Helem as (lp & ls & Hfc & _). destruct (first_commit_false Hfc). set_solver. } Qed. Theorem wp_txn__abort txn tid view γ τ : {{{ own_txn_clerk txn tid view γ τ ∗ fa_tids_frag γ tid }}} txn.Clerk__abort #txn {{{ RET #(); own_txn_clerk_uninit txn γ }}}. Proof. iIntros (Φ) "[Htxn Hfrag] HΦ". wp_call. (***********************************************************) (* proph.ResolveAbort(txn.txnMgr.p, txn.tid) *) (***********************************************************) iNamed "Htxn". iNamed "Himpl". do 2 wp_loadField. wp_apply (wp_ResolveAbort); first auto. iInv "Hinv" as "> HinvO" "HinvC". iApply ncfupd_mask_intro; first set_solver. iIntros "Hclose". iNamed "HinvO". iExists future. iFrame "Hproph". iIntros "(%future' & %Hhead & Hproph)". iMod "Hclose" as "_". (* Update the sets of ok/doomed txns to re-establish inv w.r.t. [future']. *) iDestruct (nca_inv_any_action with "Hnca") as "Hnca"; first apply Hhead. iMod (fa_inv_same_action with "Hfrag Hfa") as "Hfa"; first apply Hhead. iDestruct (fci_inv_diff_action with "Hfci") as "Hfci"; [apply Hhead | done |]. iDestruct (fcc_inv_diff_action with "Hfcc") as "Hfcc"; [apply Hhead | done |]. iDestruct (cmt_inv_diff_action with "Hcmt") as "Hcmt"; [apply Hhead | done |]. iDestruct (per_key_inv_past_abort tid with "Hkeys") as "Hkeys". iMod ("HinvC" with "[- HΦ Hwrites HwritesM Htid Hltuples Htxnmap]") as "_". { (* Close the invariant. *) eauto 15 with iFrame. } iIntros "!> _". wp_pures. (***********************************************************) (* txn.txnMgr.deactivate(txn.sid, txn.tid) *) (***********************************************************) iApply "HΦ". iModIntro. unfold own_txn_clerk_uninit. eauto 20 with iFrame. Qed. End program. #[global] Hint Extern 1 (environments.envs_entails _ (abort_false_cases _ _)) => unfold abort_false_cases : core.
from sklearn import datasets,svm , preprocessing import numpy as np from sklearn.model_selection import train_test_split # loading data set iris iris=datasets.load_iris() X=iris.data[:,:] y=iris.target X_train,X_test , y_train ,y_test = train_test_split(X ,y ,test_size=0.25, random_state=20) maxi=list() C=[0.01 , 0.05 , 0.1 , 0.5 , 1 , 2 , 5 , 10 , 100] X_trainscale=preprocessing.scale(X_train) X_testscale=preprocessing.scale(X_test) for i in C : # classifier and kernel rbf model=svm.SVC(kernel='rbf',C=i,gamma='auto') # fitting training data model.fit(X_trainscale,y_train) # predicting accuracy of dat accuracy = model.score(X_testscale,y_test) maxi.append(accuracy) print("Output for test data is") print("for the given c %f we have accuracy as %f" % (i,accuracy)) # print predictedted output print model.predict(X_testscale) print("maximum accuracy in svm method is %f" % (max(maxi)))
(* *********************************************************************) (* *) (* The CertiKOS Certified Kit Operating System *) (* *) (* The FLINT Group, Yale University *) (* *) (* Copyright The FLINT Group, Yale University. All rights reserved. *) (* This file is distributed under the terms of the Yale University *) (* Non-Commercial License Agreement. *) (* *) (* *********************************************************************) Require Import Coqlib. Require Import Maps. Require Import AST. Require Import Integers. Require Import Floats. Require Import Values. Require Import MemoryX. Require Import MemWithData. Require Import EventsX. Require Import Globalenvs. Require Import LAsm. Require Import Smallstep. Require Import ClightBigstep. Require Import Cop. Require Import ZArith.Zwf. Require Import VCGen. Require Import RealParams. Require Import liblayers.compcertx.Stencil. Require Import liblayers.compcertx.MakeProgram. Require Import liblayers.compat.CompatLayers. Require Import liblayers.compat.CompatGenSem. Require Import CompatClightSem. Require Import PrimSemantics. Require Import Clight. Require Import CDataTypes. Require Import Ctypes. Require Import I64Layer. Require Import LinkTactic. Require Import CompCertiKOSproof. Require Import MBoot. Require Import PreInit. Require Import PreInitCode. Require Import PreInitCSource. Require Import BootGen. Require Import BootGenLinkSource. Require Import LinkTemplate. (** Remove*) (*Require Import MBootCSource.*) Section WITHCOMPCERTIKOS. Context `{compcertikos_prf: CompCertiKOS}. Context `{real_params_prf : RealParams}. Notation HDATA := AbstractDataType.RData. Notation LDATA := AbstractDataType.RData. (** Fix Me *) Lemma fstore_correct: forall COMPILABLE: LayerCompilable ((FlatMem_LOC ↦ flatmem_loc_type ⊕ preinit) ⊕ L64), forall MOK: ModuleOK (fstore ↦ f_fstore), forall M2: LAsm.module, CompCertiKOS.transf_module (fstore ↦ f_fstore) = OK M2 -> cl_sim HDATAOps LDATAOps (crel HDATA LDATA) (fstore ↦ gensem fstore'_spec) (〚 M2 〛((FlatMem_LOC ↦ flatmem_loc_type ⊕ preinit) ⊕ L64)). Proof. intros. eapply link_compiler; eauto. - eapply fstore_spec_ref. - link_nextblock. - link_kernel_mode. - apply PREINITCODE.fstore_correct. - apply left_upper_bound. Qed. Lemma fload_correct: forall COMPILABLE: LayerCompilable ((FlatMem_LOC ↦ flatmem_loc_type ⊕ preinit) ⊕ L64), forall MOK: ModuleOK (fload ↦ f_fload), forall M2: LAsm.module, CompCertiKOS.transf_module (fload ↦ f_fload) = OK M2 -> cl_sim HDATAOps LDATAOps (crel HDATA LDATA) (fload ↦ gensem fload'_spec) (〚 M2 〛((FlatMem_LOC ↦ flatmem_loc_type ⊕ preinit) ⊕ L64)). Proof. intros. eapply link_compiler; eauto. - eapply fload_spec_ref. - link_nextblock. - link_kernel_mode. - apply PREINITCODE.fload_code_correct. - apply left_upper_bound. Qed. Lemma link_correct_aux: forall M, MBoot_impl = OK M -> preinit ⊕ L64 ⊢ (path_inj (crel HDATA LDATA), M) : mboot ⊕ L64. Proof. intros M HM. inv_link_impl HM; subst. unfold mboot. eapply conseq_le_assoc_comm. hcomp_tac. { transfer_variables. unfold mboot_fresh. layer_link_split_tac. - apply fload_correct; code_correct_tac. - apply fstore_correct; code_correct_tac. } { eapply layer_link_new_glbl_both. apply oplus_sim_monotonic. apply passthrough_correct. apply L64_auto_sim. } Qed. Require Import FlatMemory. Require Import Decision. Require Import LAsmModuleSem. Require Import Soundness. Require Import CompatExternalCalls. Require Import CommonTactic. Require Import LayerCalculusLemma. Lemma empty_flatmem_inject f m b n bs : Mem.loadbytes m b 0 n = Some bs -> list_forall2 (memval_inject f) (FlatMem.loadbytes FlatMem.empty_flatmem 0 n) bs. Proof. intros HLD. apply Mem.loadbytes_length in HLD. destruct n; try (destruct bs; try discriminate HLD; constructor). generalize 0. generalize dependent bs. generalize dependent p. refine (Pos.peano_ind _ _ _). - destruct bs; try discriminate. destruct bs; try discriminate. unfold FlatMem.loadbytes, FlatMem.empty_flatmem; simpl; intros _ ?. rewrite ZMap.gi. repeat constructor. - intros p IHp. unfold FlatMem.loadbytes, FlatMem.empty_flatmem. rewrite Pos2Z.inj_succ, Z2Nat.inj_succ; [| discriminate ]. destruct bs; try discriminate; simpl. injection 1 as bs_length. intros; constructor. + rewrite ZMap.gi. repeat constructor. + apply IHp; assumption. Qed. Lemma init_correct: forall M, MBoot_impl = OK M -> ModuleOK M -> cl_init_sim HDATAOps LDATAOps (crel HDATA LDATA) (mboot ⊕ L64) M (preinit ⊕ L64). Proof. Opaque oplus. intros. pose proof (fun i => module_ok_variable M i (H0 i)) as MOK. clear H0. apply cl_init_sim_intro. - intros. inv_link_impl H; subst. inv_monad' H0. generalize (make_program_make_globalenv _ _ _ _ H1). intros HP. pose proof HP as HP'. eapply make_globalenv_stencil_matches in HP'. inv_make_globalenv HP. subst. rewrite (stencil_matches_symbols _ _ HP') in *. inv HP'. constructor. + constructor; simpl; trivial. + econstructor; eauto. econstructor; eauto. specialize (Genv.init_mem_characterization _ _ Hbvi H2); eauto. unfold Genv.perm_globvar; simpl; intros [Hperm _]. change (Z.max 4294967296 0) with 4294967296 in Hperm. assert (Hperm': Mem.range_perm m2 b 0 (0 + 4294967296) Cur Readable). { simpl. eapply Mem.range_perm_implies; eauto. constructor. } exploit Mem.range_perm_loadbytes; try eassumption. intros [bs HLD]. refine_split'; eauto. eapply empty_flatmem_inject; eassumption. - intros. destruct H0 as [HF|HF]; inv HF; reflexivity. - intros. destruct H0 as [HF|HF]; inv HF; reflexivity. - intros. inv_link_impl H; subst. transf_none i. specialize (MOK i). destruct H0 as [HF|HF]; inv HF; econstructor. + get_module_variable_relfexivity. - intros. inv_link_impl H; subst. transf_none i. specialize (MOK i). destruct (peq i FlatMem_LOC); subst. + eapply (get_module_varible_OK_Some_left flatmem_loc_type) in H0; subst. reflexivity. destruct (get_module_variable_isOK _ _ _ MOK) as [HT1 _]. get_module_variable_relfexivity. + assert (get_module_variable i ((((M1 ⊕ M0 ⊕ ∅) ⊕ ∅) ⊕ FlatMem_LOC ↦ flatmem_loc_type) ⊕ ∅) = OK None). { get_module_variable_relfexivity. } setoid_rewrite H0 in H. congruence. - decision. Qed. Theorem cl_backward_simulation: forall (s: stencil) (CTXT M: module) pl ph (builtin_idents_norepet_prf: CompCertBuiltins.BuiltinIdentsNorepet), MBoot_impl = OK M -> make_program s CTXT (mboot ⊕ L64) = OK ph -> make_program s (CTXT ⊕ M) (preinit ⊕ L64) = OK pl -> backward_simulation (LAsm.semantics (lcfg_ops := LC (mboot ⊕ L64)) ph) (LAsm.semantics (lcfg_ops := LC (preinit ⊕ L64)) pl). Proof. intros. pose proof H as HM. inv_link_impl HM; subst. eapply (soundness (crel HDATA LDATA)); try eassumption; try decision. eapply link_correct_aux; eauto. eapply init_correct; eauto. eapply make_program_oplus_right; eassumption. Qed. Require Import LAsmModuleSemMakeProgram. Theorem make_program_exists: forall (s: stencil) (CTXT M: module) pl, MBoot_impl = OK M -> make_program s (CTXT ⊕ M) (preinit ⊕ L64) = OK pl -> exists ph, make_program s CTXT (mboot ⊕ L64) = OK ph. Proof. intros. exploit link_correct_aux; eauto. eapply make_program_vertical' in H0; try eassumption. destruct H0 as [p' Hmake]. intros Hle. eapply make_program_sim_monotonic_exists. 2: eapply Hle. reflexivity. eassumption. inv_link_impl H. assumption. Qed. End WITHCOMPCERTIKOS.
(* Title: ZF/IMP/Equiv.thy Author: Heiko Loetzbeyer and Robert Sandner, TU München *) section {* Equivalence *} theory Equiv imports Denotation Com begin lemma aexp_iff [rule_format]: "[| a \<in> aexp; sigma: loc -> nat |] ==> \<forall>n. <a,sigma> -a-> n \<longleftrightarrow> A(a,sigma) = n" apply (erule aexp.induct) apply (force intro!: evala.intros)+ done declare aexp_iff [THEN iffD1, simp] aexp_iff [THEN iffD2, intro!] inductive_cases [elim!]: "<true,sigma> -b-> x" "<false,sigma> -b-> x" "<ROp(f,a0,a1),sigma> -b-> x" "<noti(b),sigma> -b-> x" "<b0 andi b1,sigma> -b-> x" "<b0 ori b1,sigma> -b-> x" lemma bexp_iff [rule_format]: "[| b \<in> bexp; sigma: loc -> nat |] ==> \<forall>w. <b,sigma> -b-> w \<longleftrightarrow> B(b,sigma) = w" apply (erule bexp.induct) apply (auto intro!: evalb.intros) done declare bexp_iff [THEN iffD1, simp] bexp_iff [THEN iffD2, intro!] lemma com1: "<c,sigma> -c-> sigma' ==> <sigma,sigma'> \<in> C(c)" apply (erule evalc.induct) apply (simp_all (no_asm_simp)) txt {* @{text assign} *} apply (simp add: update_type) txt {* @{text comp} *} apply fast txt {* @{text while} *} apply (erule Gamma_bnd_mono [THEN lfp_unfold, THEN ssubst, OF C_subset]) apply (simp add: Gamma_def) txt {* recursive case of @{text while} *} apply (erule Gamma_bnd_mono [THEN lfp_unfold, THEN ssubst, OF C_subset]) apply (auto simp add: Gamma_def) done declare B_type [intro!] A_type [intro!] declare evalc.intros [intro] lemma com2 [rule_format]: "c \<in> com ==> \<forall>x \<in> C(c). <c,fst(x)> -c-> snd(x)" apply (erule com.induct) txt {* @{text skip} *} apply force txt {* @{text assign} *} apply force txt {* @{text comp} *} apply force txt {* @{text while} *} apply safe apply simp_all apply (frule Gamma_bnd_mono [OF C_subset], erule Fixedpt.induct, assumption) apply (unfold Gamma_def) apply force txt {* @{text "if"} *} apply auto done subsection {* Main theorem *} theorem com_equivalence: "c \<in> com ==> C(c) = {io \<in> (loc->nat) \<times> (loc->nat). <c,fst(io)> -c-> snd(io)}" by (force intro: C_subset [THEN subsetD] elim: com2 dest: com1) end
[GOAL] L R : Type w fst snd : R → L ⊢ ∀ {X Y : WalkingMulticospan fst snd} (f : X ⟶ Y), 𝟙 X ≫ f = f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case left.left.id L R : Type w fst snd : R → L a✝ : L ⊢ 𝟙 (left a✝) ≫ Hom.id (left a✝) = Hom.id (left a✝) [PROOFSTEP] rfl [GOAL] case left.right.fst L R : Type w fst snd : R → L a✝ : R ⊢ 𝟙 (left (fst a✝)) ≫ Hom.fst a✝ = Hom.fst a✝ [PROOFSTEP] rfl [GOAL] case left.right.snd L R : Type w fst snd : R → L a✝ : R ⊢ 𝟙 (left (snd a✝)) ≫ Hom.snd a✝ = Hom.snd a✝ [PROOFSTEP] rfl [GOAL] case right.right.id L R : Type w fst snd : R → L a✝ : R ⊢ 𝟙 (right a✝) ≫ Hom.id (right a✝) = Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] L R : Type w fst snd : R → L ⊢ ∀ {X Y : WalkingMulticospan fst snd} (f : X ⟶ Y), f ≫ 𝟙 Y = f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case left.left.id L R : Type w fst snd : R → L a✝ : L ⊢ Hom.id (left a✝) ≫ 𝟙 (left a✝) = Hom.id (left a✝) [PROOFSTEP] rfl [GOAL] case left.right.fst L R : Type w fst snd : R → L a✝ : R ⊢ Hom.fst a✝ ≫ 𝟙 (right a✝) = Hom.fst a✝ [PROOFSTEP] rfl [GOAL] case left.right.snd L R : Type w fst snd : R → L a✝ : R ⊢ Hom.snd a✝ ≫ 𝟙 (right a✝) = Hom.snd a✝ [PROOFSTEP] rfl [GOAL] case right.right.id L R : Type w fst snd : R → L a✝ : R ⊢ Hom.id (right a✝) ≫ 𝟙 (right a✝) = Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] L R : Type w fst snd : R → L ⊢ ∀ {W X Y Z : WalkingMulticospan fst snd} (f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z), (f ≫ g) ≫ h = f ≫ g ≫ h [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) [GOAL] case left.left.left.left.id.id.id L R : Type w fst snd : R → L a✝ : L ⊢ (Hom.id (left a✝) ≫ Hom.id (left a✝)) ≫ Hom.id (left a✝) = Hom.id (left a✝) ≫ Hom.id (left a✝) ≫ Hom.id (left a✝) [PROOFSTEP] rfl [GOAL] case left.left.left.right.id.id.fst L R : Type w fst snd : R → L a✝ : R ⊢ (Hom.id (left (fst a✝)) ≫ Hom.id (left (fst a✝))) ≫ Hom.fst a✝ = Hom.id (left (fst a✝)) ≫ Hom.id (left (fst a✝)) ≫ Hom.fst a✝ [PROOFSTEP] rfl [GOAL] case left.left.left.right.id.id.snd L R : Type w fst snd : R → L a✝ : R ⊢ (Hom.id (left (snd a✝)) ≫ Hom.id (left (snd a✝))) ≫ Hom.snd a✝ = Hom.id (left (snd a✝)) ≫ Hom.id (left (snd a✝)) ≫ Hom.snd a✝ [PROOFSTEP] rfl [GOAL] case left.left.right.right.id.fst.id L R : Type w fst snd : R → L a✝ : R ⊢ (Hom.id (left (fst a✝)) ≫ Hom.fst a✝) ≫ Hom.id (right a✝) = Hom.id (left (fst a✝)) ≫ Hom.fst a✝ ≫ Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] case left.left.right.right.id.snd.id L R : Type w fst snd : R → L a✝ : R ⊢ (Hom.id (left (snd a✝)) ≫ Hom.snd a✝) ≫ Hom.id (right a✝) = Hom.id (left (snd a✝)) ≫ Hom.snd a✝ ≫ Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] case left.right.right.right.fst.id.id L R : Type w fst snd : R → L a✝ : R ⊢ (Hom.fst a✝ ≫ Hom.id (right a✝)) ≫ Hom.id (right a✝) = Hom.fst a✝ ≫ Hom.id (right a✝) ≫ Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] case left.right.right.right.snd.id.id L R : Type w fst snd : R → L a✝ : R ⊢ (Hom.snd a✝ ≫ Hom.id (right a✝)) ≫ Hom.id (right a✝) = Hom.snd a✝ ≫ Hom.id (right a✝) ≫ Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] case right.right.right.right.id.id.id L R : Type w fst snd : R → L a✝ : R ⊢ (Hom.id (right a✝) ≫ Hom.id (right a✝)) ≫ Hom.id (right a✝) = Hom.id (right a✝) ≫ Hom.id (right a✝) ≫ Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] L R : Type v fst snd : L → R ⊢ ∀ {X Y : WalkingMultispan fst snd} (f : X ⟶ Y), 𝟙 X ≫ f = f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case left.left.id L R : Type v fst snd : L → R a✝ : L ⊢ 𝟙 (left a✝) ≫ Hom.id (left a✝) = Hom.id (left a✝) [PROOFSTEP] rfl [GOAL] case left.right.fst L R : Type v fst snd : L → R a✝ : L ⊢ 𝟙 (left a✝) ≫ Hom.fst a✝ = Hom.fst a✝ [PROOFSTEP] rfl [GOAL] case left.right.snd L R : Type v fst snd : L → R a✝ : L ⊢ 𝟙 (left a✝) ≫ Hom.snd a✝ = Hom.snd a✝ [PROOFSTEP] rfl [GOAL] case right.right.id L R : Type v fst snd : L → R a✝ : R ⊢ 𝟙 (right a✝) ≫ Hom.id (right a✝) = Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] L R : Type v fst snd : L → R ⊢ ∀ {X Y : WalkingMultispan fst snd} (f : X ⟶ Y), f ≫ 𝟙 Y = f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case left.left.id L R : Type v fst snd : L → R a✝ : L ⊢ Hom.id (left a✝) ≫ 𝟙 (left a✝) = Hom.id (left a✝) [PROOFSTEP] rfl [GOAL] case left.right.fst L R : Type v fst snd : L → R a✝ : L ⊢ Hom.fst a✝ ≫ 𝟙 (right (fst a✝)) = Hom.fst a✝ [PROOFSTEP] rfl [GOAL] case left.right.snd L R : Type v fst snd : L → R a✝ : L ⊢ Hom.snd a✝ ≫ 𝟙 (right (snd a✝)) = Hom.snd a✝ [PROOFSTEP] rfl [GOAL] case right.right.id L R : Type v fst snd : L → R a✝ : R ⊢ Hom.id (right a✝) ≫ 𝟙 (right a✝) = Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] L R : Type v fst snd : L → R ⊢ ∀ {W X Y Z : WalkingMultispan fst snd} (f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z), (f ≫ g) ≫ h = f ≫ g ≫ h [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) [GOAL] case left.left.left.left.id.id.id L R : Type v fst snd : L → R a✝ : L ⊢ (Hom.id (left a✝) ≫ Hom.id (left a✝)) ≫ Hom.id (left a✝) = Hom.id (left a✝) ≫ Hom.id (left a✝) ≫ Hom.id (left a✝) [PROOFSTEP] rfl [GOAL] case left.left.left.right.id.id.fst L R : Type v fst snd : L → R a✝ : L ⊢ (Hom.id (left a✝) ≫ Hom.id (left a✝)) ≫ Hom.fst a✝ = Hom.id (left a✝) ≫ Hom.id (left a✝) ≫ Hom.fst a✝ [PROOFSTEP] rfl [GOAL] case left.left.left.right.id.id.snd L R : Type v fst snd : L → R a✝ : L ⊢ (Hom.id (left a✝) ≫ Hom.id (left a✝)) ≫ Hom.snd a✝ = Hom.id (left a✝) ≫ Hom.id (left a✝) ≫ Hom.snd a✝ [PROOFSTEP] rfl [GOAL] case left.left.right.right.id.fst.id L R : Type v fst snd : L → R a✝ : L ⊢ (Hom.id (left a✝) ≫ Hom.fst a✝) ≫ Hom.id (right (fst a✝)) = Hom.id (left a✝) ≫ Hom.fst a✝ ≫ Hom.id (right (fst a✝)) [PROOFSTEP] rfl [GOAL] case left.left.right.right.id.snd.id L R : Type v fst snd : L → R a✝ : L ⊢ (Hom.id (left a✝) ≫ Hom.snd a✝) ≫ Hom.id (right (snd a✝)) = Hom.id (left a✝) ≫ Hom.snd a✝ ≫ Hom.id (right (snd a✝)) [PROOFSTEP] rfl [GOAL] case left.right.right.right.fst.id.id L R : Type v fst snd : L → R a✝ : L ⊢ (Hom.fst a✝ ≫ Hom.id (right (fst a✝))) ≫ Hom.id (right (fst a✝)) = Hom.fst a✝ ≫ Hom.id (right (fst a✝)) ≫ Hom.id (right (fst a✝)) [PROOFSTEP] rfl [GOAL] case left.right.right.right.snd.id.id L R : Type v fst snd : L → R a✝ : L ⊢ (Hom.snd a✝ ≫ Hom.id (right (snd a✝))) ≫ Hom.id (right (snd a✝)) = Hom.snd a✝ ≫ Hom.id (right (snd a✝)) ≫ Hom.id (right (snd a✝)) [PROOFSTEP] rfl [GOAL] case right.right.right.right.id.id.id L R : Type v fst snd : L → R a✝ : R ⊢ (Hom.id (right a✝) ≫ Hom.id (right a✝)) ≫ Hom.id (right a✝) = Hom.id (right a✝) ≫ Hom.id (right a✝) ≫ Hom.id (right a✝) [PROOFSTEP] rfl [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C ⊢ ∀ (X : WalkingMulticospan I.fstTo I.sndTo), { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (𝟙 X) = 𝟙 ({ obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.obj X) [PROOFSTEP] rintro (_ | _) [GOAL] case left C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C a✝ : I.L ⊢ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (𝟙 (WalkingMulticospan.left a✝)) = 𝟙 ({ obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.obj (WalkingMulticospan.left a✝)) [PROOFSTEP] rfl [GOAL] case right C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C a✝ : I.R ⊢ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (𝟙 (WalkingMulticospan.right a✝)) = 𝟙 ({ obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.obj (WalkingMulticospan.right a✝)) [PROOFSTEP] rfl [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C ⊢ ∀ {X Y Z : WalkingMulticospan I.fstTo I.sndTo} (f : X ⟶ Y) (g : Y ⟶ Z), { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (f ≫ g) = { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map f ≫ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map g [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) [GOAL] case left.left.left.id.id C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C a✝ : I.L ⊢ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.left a✝) ≫ WalkingMulticospan.Hom.id (WalkingMulticospan.left a✝)) = { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.left a✝)) ≫ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.left a✝)) [PROOFSTEP] aesop_cat [GOAL] case left.left.right.id.fst C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C a✝ : I.R ⊢ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.left (fstTo I a✝)) ≫ WalkingMulticospan.Hom.fst a✝) = { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.left (fstTo I a✝))) ≫ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.fst a✝) [PROOFSTEP] aesop_cat [GOAL] case left.left.right.id.snd C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C a✝ : I.R ⊢ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.left (sndTo I a✝)) ≫ WalkingMulticospan.Hom.snd a✝) = { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.left (sndTo I a✝))) ≫ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.snd a✝) [PROOFSTEP] aesop_cat [GOAL] case left.right.right.fst.id C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C a✝ : I.R ⊢ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.fst a✝ ≫ WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) = { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.fst a✝) ≫ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) [PROOFSTEP] aesop_cat [GOAL] case left.right.right.snd.id C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C a✝ : I.R ⊢ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.snd a✝ ≫ WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) = { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.snd a✝) ≫ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) [PROOFSTEP] aesop_cat [GOAL] case right.right.right.id.id C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C a✝ : I.R ⊢ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝) ≫ WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) = { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) ≫ { obj := fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMulticospan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMulticospan.left a => left I a | WalkingMulticospan.right b => right I b) x) | .(WalkingMulticospan.left (fstTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.fst b => fst I b | .(WalkingMulticospan.left (sndTo I b)), .(WalkingMulticospan.right b), WalkingMulticospan.Hom.snd b => snd I b }.map (WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) [PROOFSTEP] aesop_cat [GOAL] C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right b : I.R ⊢ fstPiMap I ≫ Pi.π I.right b = Pi.π I.left (fstTo I b) ≫ fst I b [PROOFSTEP] simp [fstPiMap] [GOAL] C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right b : I.R ⊢ sndPiMap I ≫ Pi.π I.right b = Pi.π I.left (sndTo I b) ≫ snd I b [PROOFSTEP] simp [sndPiMap] [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C ⊢ ∀ (X : WalkingMultispan I.fstFrom I.sndFrom), { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (𝟙 X) = 𝟙 ({ obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.obj X) [PROOFSTEP] rintro (_ | _) [GOAL] case left C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C a✝ : I.L ⊢ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (𝟙 (WalkingMultispan.left a✝)) = 𝟙 ({ obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.obj (WalkingMultispan.left a✝)) [PROOFSTEP] rfl [GOAL] case right C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C a✝ : I.R ⊢ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (𝟙 (WalkingMultispan.right a✝)) = 𝟙 ({ obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.obj (WalkingMultispan.right a✝)) [PROOFSTEP] rfl [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C ⊢ ∀ {X Y Z : WalkingMultispan I.fstFrom I.sndFrom} (f : X ⟶ Y) (g : Y ⟶ Z), { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (f ≫ g) = { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map f ≫ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map g [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) [GOAL] case left.left.left.id.id C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C a✝ : I.L ⊢ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝) ≫ WalkingMultispan.Hom.id (WalkingMultispan.left a✝)) = { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝)) ≫ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝)) [PROOFSTEP] aesop_cat [GOAL] case left.left.right.id.fst C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C a✝ : I.L ⊢ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝) ≫ WalkingMultispan.Hom.fst a✝) = { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝)) ≫ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.fst a✝) [PROOFSTEP] aesop_cat [GOAL] case left.left.right.id.snd C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C a✝ : I.L ⊢ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝) ≫ WalkingMultispan.Hom.snd a✝) = { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝)) ≫ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.snd a✝) [PROOFSTEP] aesop_cat [GOAL] case left.right.right.fst.id C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C a✝ : I.L ⊢ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.fst a✝ ≫ WalkingMultispan.Hom.id (WalkingMultispan.right (fstFrom I a✝))) = { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.fst a✝) ≫ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.right (fstFrom I a✝))) [PROOFSTEP] aesop_cat [GOAL] case left.right.right.snd.id C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C a✝ : I.L ⊢ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.snd a✝ ≫ WalkingMultispan.Hom.id (WalkingMultispan.right (sndFrom I a✝))) = { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.snd a✝) ≫ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.right (sndFrom I a✝))) [PROOFSTEP] aesop_cat [GOAL] case right.right.right.id.id C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C a✝ : I.R ⊢ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.right a✝) ≫ WalkingMultispan.Hom.id (WalkingMultispan.right a✝)) = { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.right a✝)) ≫ { obj := fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b, map := fun {x y} f => match x, y, f with | x, .(x), WalkingMultispan.Hom.id .(x) => 𝟙 ((fun x => match x with | WalkingMultispan.left a => left I a | WalkingMultispan.right b => right I b) x) | .(WalkingMultispan.left b), .(WalkingMultispan.right (fstFrom I b)), WalkingMultispan.Hom.fst b => fst I b | .(WalkingMultispan.left b), .(WalkingMultispan.right (sndFrom I b)), WalkingMultispan.Hom.snd b => snd I b }.map (WalkingMultispan.Hom.id (WalkingMultispan.right a✝)) [PROOFSTEP] aesop_cat [GOAL] C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right b : I.L ⊢ Sigma.ι I.left b ≫ fstSigmaMap I = fst I b ≫ Sigma.ι I.right (fstFrom I b) [PROOFSTEP] simp [fstSigmaMap] [GOAL] C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right b : I.L ⊢ Sigma.ι I.left b ≫ sndSigmaMap I = snd I b ≫ Sigma.ι I.right (sndFrom I b) [PROOFSTEP] simp [sndSigmaMap] [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I b : I.R ⊢ NatTrans.app K.π (WalkingMulticospan.right b) = ι K (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b [PROOFSTEP] rw [← K.w (WalkingMulticospan.Hom.fst b)] [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I b : I.R ⊢ NatTrans.app K.π (WalkingMulticospan.left (MulticospanIndex.fstTo I b)) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.fst b) = ι K (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b [PROOFSTEP] rfl [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I b : I.R ⊢ NatTrans.app K.π (WalkingMulticospan.right b) = ι K (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b [PROOFSTEP] rw [← K.w (WalkingMulticospan.Hom.snd b)] [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I b : I.R ⊢ NatTrans.app K.π (WalkingMulticospan.left (MulticospanIndex.sndTo I b)) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.snd b) = ι K (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b [PROOFSTEP] rfl [GOAL] C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b ⊢ ∀ ⦃X Y : WalkingMulticospan I.fstTo I.sndTo⦄ (f : X ⟶ Y), ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj P).map f ≫ (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) Y = (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) X ≫ (MulticospanIndex.multicospan I).map f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case left.left.id C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b a✝ : I.L ⊢ ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj P).map (WalkingMulticospan.Hom.id (WalkingMulticospan.left a✝)) ≫ (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) (WalkingMulticospan.left a✝) = (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) (WalkingMulticospan.left a✝) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.id (WalkingMulticospan.left a✝)) [PROOFSTEP] dsimp [GOAL] case left.right.fst C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b a✝ : I.R ⊢ ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj P).map (WalkingMulticospan.Hom.fst a✝) ≫ (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) (WalkingMulticospan.right a✝) = (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) (WalkingMulticospan.left (MulticospanIndex.fstTo I a✝)) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.fst a✝) [PROOFSTEP] dsimp [GOAL] case left.right.snd C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b a✝ : I.R ⊢ ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj P).map (WalkingMulticospan.Hom.snd a✝) ≫ (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) (WalkingMulticospan.right a✝) = (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) (WalkingMulticospan.left (MulticospanIndex.sndTo I a✝)) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.snd a✝) [PROOFSTEP] dsimp [GOAL] case right.right.id C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b a✝ : I.R ⊢ ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj P).map (WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) ≫ (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) (WalkingMulticospan.right a✝) = (fun x => match x with | WalkingMulticospan.left a => ι a | WalkingMulticospan.right b => ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b) (WalkingMulticospan.right a✝) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) [PROOFSTEP] dsimp [GOAL] case left.left.id C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b a✝ : I.L ⊢ 𝟙 P ≫ ι a✝ = ι a✝ ≫ (MulticospanIndex.multicospan I).map (𝟙 (WalkingMulticospan.left a✝)) [PROOFSTEP] simp only [Category.id_comp, Category.comp_id, Functor.map_id, MulticospanIndex.multicospan_obj_left, MulticospanIndex.multicospan_obj_right] [GOAL] case left.right.fst C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b a✝ : I.R ⊢ 𝟙 P ≫ ι (MulticospanIndex.fstTo I a✝) ≫ MulticospanIndex.fst I a✝ = ι (MulticospanIndex.fstTo I a✝) ≫ MulticospanIndex.fst I a✝ [PROOFSTEP] simp only [Category.id_comp, Category.comp_id, Functor.map_id, MulticospanIndex.multicospan_obj_left, MulticospanIndex.multicospan_obj_right] [GOAL] case left.right.snd C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b a✝ : I.R ⊢ 𝟙 P ≫ ι (MulticospanIndex.fstTo I a✝) ≫ MulticospanIndex.fst I a✝ = ι (MulticospanIndex.sndTo I a✝) ≫ MulticospanIndex.snd I a✝ [PROOFSTEP] simp only [Category.id_comp, Category.comp_id, Functor.map_id, MulticospanIndex.multicospan_obj_left, MulticospanIndex.multicospan_obj_right] [GOAL] case right.right.id C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b a✝ : I.R ⊢ 𝟙 P ≫ ι (MulticospanIndex.fstTo I a✝) ≫ MulticospanIndex.fst I a✝ = (ι (MulticospanIndex.fstTo I a✝) ≫ MulticospanIndex.fst I a✝) ≫ (MulticospanIndex.multicospan I).map (𝟙 (WalkingMulticospan.right a✝)) [PROOFSTEP] simp only [Category.id_comp, Category.comp_id, Functor.map_id, MulticospanIndex.multicospan_obj_left, MulticospanIndex.multicospan_obj_right] [GOAL] case left.right.snd C : Type u inst✝ : Category.{v, u} C I✝ : MulticospanIndex C K : Multifork I✝ I : MulticospanIndex C P : C ι : (a : I.L) → P ⟶ MulticospanIndex.left I a w : ∀ (b : I.R), ι (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b a✝ : I.R ⊢ ι (MulticospanIndex.fstTo I a✝) ≫ MulticospanIndex.fst I a✝ = ι (MulticospanIndex.sndTo I a✝) ≫ MulticospanIndex.snd I a✝ [PROOFSTEP] apply w [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I b : I.R ⊢ ι K (MulticospanIndex.fstTo I b) ≫ MulticospanIndex.fst I b = ι K (MulticospanIndex.sndTo I b) ≫ MulticospanIndex.snd I b [PROOFSTEP] rw [← app_right_eq_ι_comp_fst, ← app_right_eq_ι_comp_snd] [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I lift : (E : Multifork I) → E.pt ⟶ K.pt fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ ι K i = ι E i uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ (i : I.L), m ≫ ι K i = ι E i) → m = lift E ⊢ ∀ (s : Cone (MulticospanIndex.multicospan I)) (j : WalkingMulticospan I.fstTo I.sndTo), lift s ≫ NatTrans.app K.π j = NatTrans.app s.π j [PROOFSTEP] rintro E (a | b) [GOAL] case left C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I lift : (E : Multifork I) → E.pt ⟶ K.pt fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ ι K i = ι E i uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ (i : I.L), m ≫ ι K i = ι E i) → m = lift E E : Cone (MulticospanIndex.multicospan I) a : I.L ⊢ lift E ≫ NatTrans.app K.π (WalkingMulticospan.left a) = NatTrans.app E.π (WalkingMulticospan.left a) [PROOFSTEP] apply fac [GOAL] case right C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I lift : (E : Multifork I) → E.pt ⟶ K.pt fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ ι K i = ι E i uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ (i : I.L), m ≫ ι K i = ι E i) → m = lift E E : Cone (MulticospanIndex.multicospan I) b : I.R ⊢ lift E ≫ NatTrans.app K.π (WalkingMulticospan.right b) = NatTrans.app E.π (WalkingMulticospan.right b) [PROOFSTEP] rw [← E.w (WalkingMulticospan.Hom.fst b), ← K.w (WalkingMulticospan.Hom.fst b), ← Category.assoc] [GOAL] case right C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I lift : (E : Multifork I) → E.pt ⟶ K.pt fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ ι K i = ι E i uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ (i : I.L), m ≫ ι K i = ι E i) → m = lift E E : Cone (MulticospanIndex.multicospan I) b : I.R ⊢ (lift E ≫ NatTrans.app K.π (WalkingMulticospan.left (MulticospanIndex.fstTo I b))) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.fst b) = NatTrans.app E.π (WalkingMulticospan.left (MulticospanIndex.fstTo I b)) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.fst b) [PROOFSTEP] congr 1 [GOAL] case right.e_a C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I lift : (E : Multifork I) → E.pt ⟶ K.pt fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ ι K i = ι E i uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ (i : I.L), m ≫ ι K i = ι E i) → m = lift E E : Cone (MulticospanIndex.multicospan I) b : I.R ⊢ lift E ≫ NatTrans.app K.π (WalkingMulticospan.left (MulticospanIndex.fstTo I b)) = NatTrans.app E.π (WalkingMulticospan.left (MulticospanIndex.fstTo I b)) [PROOFSTEP] apply fac [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I lift : (E : Multifork I) → E.pt ⟶ K.pt fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ ι K i = ι E i uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ (i : I.L), m ≫ ι K i = ι E i) → m = lift E ⊢ ∀ (s : Cone (MulticospanIndex.multicospan I)) (m : s.pt ⟶ K.pt), (∀ (j : WalkingMulticospan I.fstTo I.sndTo), m ≫ NatTrans.app K.π j = NatTrans.app s.π j) → m = lift s [PROOFSTEP] rintro E m hm [GOAL] C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I lift : (E : Multifork I) → E.pt ⟶ K.pt fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ ι K i = ι E i uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ (i : I.L), m ≫ ι K i = ι E i) → m = lift E E : Cone (MulticospanIndex.multicospan I) m : E.pt ⟶ K.pt hm : ∀ (j : WalkingMulticospan I.fstTo I.sndTo), m ≫ NatTrans.app K.π j = NatTrans.app E.π j ⊢ m = lift E [PROOFSTEP] apply uniq [GOAL] case a C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I lift : (E : Multifork I) → E.pt ⟶ K.pt fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ ι K i = ι E i uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ (i : I.L), m ≫ ι K i = ι E i) → m = lift E E : Cone (MulticospanIndex.multicospan I) m : E.pt ⟶ K.pt hm : ∀ (j : WalkingMulticospan I.fstTo I.sndTo), m ≫ NatTrans.app K.π j = NatTrans.app E.π j ⊢ ∀ (i : I.L), m ≫ ι K i = ι E i [PROOFSTEP] intro i [GOAL] case a C : Type u inst✝ : Category.{v, u} C I : MulticospanIndex C K : Multifork I lift : (E : Multifork I) → E.pt ⟶ K.pt fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ ι K i = ι E i uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ (i : I.L), m ≫ ι K i = ι E i) → m = lift E E : Cone (MulticospanIndex.multicospan I) m : E.pt ⟶ K.pt hm : ∀ (j : WalkingMulticospan I.fstTo I.sndTo), m ≫ NatTrans.app K.π j = NatTrans.app E.π j i : I.L ⊢ m ≫ ι K i = ι E i [PROOFSTEP] apply hm [GOAL] C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right ⊢ Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I = Pi.lift (ι K) ≫ MulticospanIndex.sndPiMap I [PROOFSTEP] ext [GOAL] case h C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right b✝ : I.R ⊢ (Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) ≫ Pi.π I.right b✝ = (Pi.lift (ι K) ≫ MulticospanIndex.sndPiMap I) ≫ Pi.π I.right b✝ [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K✝ : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ ∀ ⦃X Y : WalkingParallelPair⦄ (f : X ⟶ Y), ((Functor.const WalkingParallelPair).obj K.pt).map f ≫ (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) Y = (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) X ≫ (parallelPair (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I)).map f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case zero.zero.id C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K✝ : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ ((Functor.const WalkingParallelPair).obj K.pt).map (WalkingParallelPairHom.id WalkingParallelPair.zero) ≫ (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) WalkingParallelPair.zero = (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) WalkingParallelPair.zero ≫ (parallelPair (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I)).map (WalkingParallelPairHom.id WalkingParallelPair.zero) [PROOFSTEP] dsimp [GOAL] case zero.one.left C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K✝ : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ ((Functor.const WalkingParallelPair).obj K.pt).map WalkingParallelPairHom.left ≫ (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) WalkingParallelPair.one = (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) WalkingParallelPair.zero ≫ (parallelPair (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I)).map WalkingParallelPairHom.left [PROOFSTEP] dsimp [GOAL] case zero.one.right C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K✝ : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ ((Functor.const WalkingParallelPair).obj K.pt).map WalkingParallelPairHom.right ≫ (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) WalkingParallelPair.one = (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) WalkingParallelPair.zero ≫ (parallelPair (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I)).map WalkingParallelPairHom.right [PROOFSTEP] dsimp [GOAL] case one.one.id C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K✝ : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ ((Functor.const WalkingParallelPair).obj K.pt).map (WalkingParallelPairHom.id WalkingParallelPair.one) ≫ (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) WalkingParallelPair.one = (fun x => match x with | WalkingParallelPair.zero => Pi.lift (ι K) | WalkingParallelPair.one => Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) WalkingParallelPair.one ≫ (parallelPair (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I)).map (WalkingParallelPairHom.id WalkingParallelPair.one) [PROOFSTEP] dsimp [GOAL] case zero.zero.id C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K✝ : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ 𝟙 K.pt ≫ Pi.lift (ι K) = Pi.lift (ι K) ≫ (parallelPair (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I)).map (𝟙 WalkingParallelPair.zero) [PROOFSTEP] simp only [Category.id_comp, Functor.map_id, parallelPair_obj_zero, Category.comp_id, pi_condition, parallelPair_obj_one] [GOAL] case zero.one.left C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K✝ : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ 𝟙 K.pt ≫ Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I = Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I [PROOFSTEP] simp only [Category.id_comp, Functor.map_id, parallelPair_obj_zero, Category.comp_id, pi_condition, parallelPair_obj_one] [GOAL] case zero.one.right C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K✝ : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ 𝟙 K.pt ≫ Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I = Pi.lift (ι K) ≫ MulticospanIndex.sndPiMap I [PROOFSTEP] simp only [Category.id_comp, Functor.map_id, parallelPair_obj_zero, Category.comp_id, pi_condition, parallelPair_obj_one] [GOAL] case one.one.id C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K✝ : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ 𝟙 K.pt ≫ Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I = (Pi.lift (ι K) ≫ MulticospanIndex.fstPiMap I) ≫ (parallelPair (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I)).map (𝟙 WalkingParallelPair.one) [PROOFSTEP] simp only [Category.id_comp, Functor.map_id, parallelPair_obj_zero, Category.comp_id, pi_condition, parallelPair_obj_one] [GOAL] C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right c : Fork (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I) ⊢ ∀ ⦃X Y : WalkingMulticospan I.fstTo I.sndTo⦄ (f : X ⟶ Y), ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj c.pt).map f ≫ (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) Y = (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) X ≫ (MulticospanIndex.multicospan I).map f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case left.left.id C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right c : Fork (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I) a✝ : I.L ⊢ ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj c.pt).map (WalkingMulticospan.Hom.id (WalkingMulticospan.left a✝)) ≫ (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) (WalkingMulticospan.left a✝) = (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) (WalkingMulticospan.left a✝) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.id (WalkingMulticospan.left a✝)) [PROOFSTEP] simp [GOAL] case left.right.fst C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right c : Fork (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I) a✝ : I.R ⊢ ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj c.pt).map (WalkingMulticospan.Hom.fst a✝) ≫ (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) (WalkingMulticospan.right a✝) = (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) (WalkingMulticospan.left (MulticospanIndex.fstTo I a✝)) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.fst a✝) [PROOFSTEP] simp [GOAL] case left.right.snd C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right c : Fork (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I) a✝ : I.R ⊢ ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj c.pt).map (WalkingMulticospan.Hom.snd a✝) ≫ (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) (WalkingMulticospan.right a✝) = (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) (WalkingMulticospan.left (MulticospanIndex.sndTo I a✝)) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.snd a✝) [PROOFSTEP] dsimp [GOAL] case left.right.snd C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right c : Fork (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I) a✝ : I.R ⊢ 𝟙 c.pt ≫ Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right a✝ = (Fork.ι c ≫ Pi.π I.left (MulticospanIndex.sndTo I a✝)) ≫ MulticospanIndex.snd I a✝ [PROOFSTEP] rw [c.condition_assoc] [GOAL] case left.right.snd C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right c : Fork (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I) a✝ : I.R ⊢ 𝟙 c.pt ≫ Fork.ι c ≫ MulticospanIndex.sndPiMap I ≫ Pi.π I.right a✝ = (Fork.ι c ≫ Pi.π I.left (MulticospanIndex.sndTo I a✝)) ≫ MulticospanIndex.snd I a✝ [PROOFSTEP] simp [GOAL] case right.right.id C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C K : Multifork I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right c : Fork (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I) a✝ : I.R ⊢ ((Functor.const (WalkingMulticospan I.fstTo I.sndTo)).obj c.pt).map (WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) ≫ (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) (WalkingMulticospan.right a✝) = (fun x => match x with | WalkingMulticospan.left a => Fork.ι c ≫ Pi.π I.left a | WalkingMulticospan.right b => Fork.ι c ≫ MulticospanIndex.fstPiMap I ≫ Pi.π I.right b) (WalkingMulticospan.right a✝) ≫ (MulticospanIndex.multicospan I).map (WalkingMulticospan.Hom.id (WalkingMulticospan.right a✝)) [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Multifork I f : K₁ ⟶ K₂ ⊢ ∀ (j : WalkingParallelPair), f.Hom ≫ NatTrans.app (Multifork.toPiFork K₂).π j = NatTrans.app (Multifork.toPiFork K₁).π j [PROOFSTEP] rintro (_ | _) [GOAL] case zero C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Multifork I f : K₁ ⟶ K₂ ⊢ f.Hom ≫ NatTrans.app (Multifork.toPiFork K₂).π WalkingParallelPair.zero = NatTrans.app (Multifork.toPiFork K₁).π WalkingParallelPair.zero [PROOFSTEP] apply limit.hom_ext [GOAL] case zero.w C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Multifork I f : K₁ ⟶ K₂ ⊢ ∀ (j : Discrete I.L), (f.Hom ≫ NatTrans.app (Multifork.toPiFork K₂).π WalkingParallelPair.zero) ≫ limit.π (Discrete.functor I.left) j = NatTrans.app (Multifork.toPiFork K₁).π WalkingParallelPair.zero ≫ limit.π (Discrete.functor I.left) j [PROOFSTEP] simp [GOAL] case one C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Multifork I f : K₁ ⟶ K₂ ⊢ f.Hom ≫ NatTrans.app (Multifork.toPiFork K₂).π WalkingParallelPair.one = NatTrans.app (Multifork.toPiFork K₁).π WalkingParallelPair.one [PROOFSTEP] apply limit.hom_ext [GOAL] case one.w C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Multifork I f : K₁ ⟶ K₂ ⊢ ∀ (j : Discrete I.R), (f.Hom ≫ NatTrans.app (Multifork.toPiFork K₂).π WalkingParallelPair.one) ≫ limit.π (Discrete.functor I.right) j = NatTrans.app (Multifork.toPiFork K₁).π WalkingParallelPair.one ≫ limit.π (Discrete.functor I.right) j [PROOFSTEP] intros j [GOAL] case one.w C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Multifork I f : K₁ ⟶ K₂ j : Discrete I.R ⊢ (f.Hom ≫ NatTrans.app (Multifork.toPiFork K₂).π WalkingParallelPair.one) ≫ limit.π (Discrete.functor I.right) j = NatTrans.app (Multifork.toPiFork K₁).π WalkingParallelPair.one ≫ limit.π (Discrete.functor I.right) j [PROOFSTEP] simp only [Multifork.toPiFork_π_app_one, Multifork.pi_condition, Category.assoc] [GOAL] case one.w C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Multifork I f : K₁ ⟶ K₂ j : Discrete I.R ⊢ f.Hom ≫ Pi.lift (Multifork.ι K₂) ≫ sndPiMap I ≫ limit.π (Discrete.functor I.right) j = Pi.lift (Multifork.ι K₁) ≫ sndPiMap I ≫ limit.π (Discrete.functor I.right) j [PROOFSTEP] dsimp [sndPiMap] [GOAL] case one.w C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Multifork I f : K₁ ⟶ K₂ j : Discrete I.R ⊢ f.Hom ≫ Pi.lift (Multifork.ι K₂) ≫ (Pi.lift fun b => Pi.π I.left (sndTo I b) ≫ snd I b) ≫ limit.π (Discrete.functor I.right) j = Pi.lift (Multifork.ι K₁) ≫ (Pi.lift fun b => Pi.π I.left (sndTo I b) ≫ snd I b) ≫ limit.π (Discrete.functor I.right) j [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Fork (fstPiMap I) (sndPiMap I) f : K₁ ⟶ K₂ ⊢ ∀ (j : WalkingMulticospan I.fstTo I.sndTo), f.Hom ≫ NatTrans.app (Multifork.ofPiFork I K₂).π j = NatTrans.app (Multifork.ofPiFork I K₁).π j [PROOFSTEP] rintro (_ | _) [GOAL] case left C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Fork (fstPiMap I) (sndPiMap I) f : K₁ ⟶ K₂ a✝ : I.L ⊢ f.Hom ≫ NatTrans.app (Multifork.ofPiFork I K₂).π (WalkingMulticospan.left a✝) = NatTrans.app (Multifork.ofPiFork I K₁).π (WalkingMulticospan.left a✝) [PROOFSTEP] simp [GOAL] case right C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K₁ K₂ : Fork (fstPiMap I) (sndPiMap I) f : K₁ ⟶ K₂ a✝ : I.R ⊢ f.Hom ≫ NatTrans.app (Multifork.ofPiFork I K₂).π (WalkingMulticospan.right a✝) = NatTrans.app (Multifork.ofPiFork I K₁).π (WalkingMulticospan.right a✝) [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I ⊢ ∀ (j : WalkingMulticospan I.fstTo I.sndTo), NatTrans.app ((𝟭 (Multifork I)).obj K).π j = (Iso.refl ((𝟭 (Multifork I)).obj K).pt).hom ≫ NatTrans.app ((toPiForkFunctor I ⋙ ofPiForkFunctor I).obj K).π j [PROOFSTEP] rintro (_ | _) [GOAL] case left C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I a✝ : I.L ⊢ NatTrans.app ((𝟭 (Multifork I)).obj K).π (WalkingMulticospan.left a✝) = (Iso.refl ((𝟭 (Multifork I)).obj K).pt).hom ≫ NatTrans.app ((toPiForkFunctor I ⋙ ofPiForkFunctor I).obj K).π (WalkingMulticospan.left a✝) [PROOFSTEP] dsimp [GOAL] case right C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I a✝ : I.R ⊢ NatTrans.app ((𝟭 (Multifork I)).obj K).π (WalkingMulticospan.right a✝) = (Iso.refl ((𝟭 (Multifork I)).obj K).pt).hom ≫ NatTrans.app ((toPiForkFunctor I ⋙ ofPiForkFunctor I).obj K).π (WalkingMulticospan.right a✝) [PROOFSTEP] dsimp [GOAL] case left C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I a✝ : I.L ⊢ Multifork.ι K a✝ = 𝟙 K.pt ≫ Pi.lift (Multifork.ι K) ≫ Pi.π I.left a✝ [PROOFSTEP] simp [← Fork.app_one_eq_ι_comp_left, -Fork.app_one_eq_ι_comp_left] [GOAL] case right C : Type u inst✝² : Category.{v, u} C I : MulticospanIndex C inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right K : Multifork I a✝ : I.R ⊢ NatTrans.app K.π (WalkingMulticospan.right a✝) = 𝟙 K.pt ≫ Pi.lift (Multifork.ι K) ≫ fstPiMap I ≫ Pi.π I.right a✝ [PROOFSTEP] simp [← Fork.app_one_eq_ι_comp_left, -Fork.app_one_eq_ι_comp_left] [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I a : I.L ⊢ NatTrans.app K.ι (WalkingMultispan.left a) = MultispanIndex.fst I a ≫ π K (MultispanIndex.fstFrom I a) [PROOFSTEP] rw [← K.w (WalkingMultispan.Hom.fst a)] [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I a : I.L ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.fst a) ≫ NatTrans.app K.ι (WalkingMultispan.right (MultispanIndex.fstFrom I a)) = MultispanIndex.fst I a ≫ π K (MultispanIndex.fstFrom I a) [PROOFSTEP] rfl [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I a : I.L ⊢ NatTrans.app K.ι (WalkingMultispan.left a) = MultispanIndex.snd I a ≫ π K (MultispanIndex.sndFrom I a) [PROOFSTEP] rw [← K.w (WalkingMultispan.Hom.snd a)] [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I a : I.L ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.snd a) ≫ NatTrans.app K.ι (WalkingMultispan.right (MultispanIndex.sndFrom I a)) = MultispanIndex.snd I a ≫ π K (MultispanIndex.sndFrom I a) [PROOFSTEP] rfl [GOAL] C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) ⊢ ∀ ⦃X Y : WalkingMultispan I.fstFrom I.sndFrom⦄ (f : X ⟶ Y), (MultispanIndex.multispan I).map f ≫ (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) Y = (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) X ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj P).map f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case left.left.id C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.L ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝)) ≫ (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) (WalkingMultispan.left a✝) = (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) (WalkingMultispan.left a✝) ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj P).map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝)) [PROOFSTEP] dsimp [GOAL] case left.right.fst C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.L ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.fst a✝) ≫ (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) (WalkingMultispan.right (MultispanIndex.fstFrom I a✝)) = (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) (WalkingMultispan.left a✝) ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj P).map (WalkingMultispan.Hom.fst a✝) [PROOFSTEP] dsimp [GOAL] case left.right.snd C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.L ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.snd a✝) ≫ (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) (WalkingMultispan.right (MultispanIndex.sndFrom I a✝)) = (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) (WalkingMultispan.left a✝) ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj P).map (WalkingMultispan.Hom.snd a✝) [PROOFSTEP] dsimp [GOAL] case right.right.id C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.R ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.id (WalkingMultispan.right a✝)) ≫ (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) (WalkingMultispan.right a✝) = (fun x => match x with | WalkingMultispan.left a => MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) | WalkingMultispan.right b => π b) (WalkingMultispan.right a✝) ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj P).map (WalkingMultispan.Hom.id (WalkingMultispan.right a✝)) [PROOFSTEP] dsimp [GOAL] case left.left.id C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.L ⊢ (MultispanIndex.multispan I).map (𝟙 (WalkingMultispan.left a✝)) ≫ MultispanIndex.fst I a✝ ≫ π (MultispanIndex.fstFrom I a✝) = (MultispanIndex.fst I a✝ ≫ π (MultispanIndex.fstFrom I a✝)) ≫ 𝟙 P [PROOFSTEP] simp only [Functor.map_id, MultispanIndex.multispan_obj_left, Category.id_comp, Category.comp_id, MultispanIndex.multispan_obj_right] [GOAL] case left.right.fst C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.L ⊢ MultispanIndex.fst I a✝ ≫ π (MultispanIndex.fstFrom I a✝) = (MultispanIndex.fst I a✝ ≫ π (MultispanIndex.fstFrom I a✝)) ≫ 𝟙 P [PROOFSTEP] simp only [Functor.map_id, MultispanIndex.multispan_obj_left, Category.id_comp, Category.comp_id, MultispanIndex.multispan_obj_right] [GOAL] case left.right.snd C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.L ⊢ MultispanIndex.snd I a✝ ≫ π (MultispanIndex.sndFrom I a✝) = (MultispanIndex.fst I a✝ ≫ π (MultispanIndex.fstFrom I a✝)) ≫ 𝟙 P [PROOFSTEP] simp only [Functor.map_id, MultispanIndex.multispan_obj_left, Category.id_comp, Category.comp_id, MultispanIndex.multispan_obj_right] [GOAL] case right.right.id C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.R ⊢ (MultispanIndex.multispan I).map (𝟙 (WalkingMultispan.right a✝)) ≫ π a✝ = π a✝ ≫ 𝟙 P [PROOFSTEP] simp only [Functor.map_id, MultispanIndex.multispan_obj_left, Category.id_comp, Category.comp_id, MultispanIndex.multispan_obj_right] [GOAL] case left.right.snd C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.L ⊢ MultispanIndex.snd I a✝ ≫ π (MultispanIndex.sndFrom I a✝) = MultispanIndex.fst I a✝ ≫ π (MultispanIndex.fstFrom I a✝) [PROOFSTEP] symm [GOAL] case left.right.snd C : Type u inst✝ : Category.{v, u} C I✝ : MultispanIndex C K : Multicofork I✝ I : MultispanIndex C P : C π : (b : I.R) → MultispanIndex.right I b ⟶ P w : ∀ (a : I.L), MultispanIndex.fst I a ≫ π (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π (MultispanIndex.sndFrom I a) a✝ : I.L ⊢ MultispanIndex.fst I a✝ ≫ π (MultispanIndex.fstFrom I a✝) = MultispanIndex.snd I a✝ ≫ π (MultispanIndex.sndFrom I a✝) [PROOFSTEP] apply w [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I a : I.L ⊢ MultispanIndex.fst I a ≫ π K (MultispanIndex.fstFrom I a) = MultispanIndex.snd I a ≫ π K (MultispanIndex.sndFrom I a) [PROOFSTEP] rw [← K.snd_app_right, ← K.fst_app_right] [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I desc : (E : Multicofork I) → K.pt ⟶ E.pt fac : ∀ (E : Multicofork I) (i : I.R), π K i ≫ desc E = π E i uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ (i : I.R), π K i ≫ m = π E i) → m = desc E ⊢ ∀ (s : Cocone (MultispanIndex.multispan I)) (j : WalkingMultispan I.fstFrom I.sndFrom), NatTrans.app K.ι j ≫ desc s = NatTrans.app s.ι j [PROOFSTEP] rintro S (a | b) [GOAL] case left C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I desc : (E : Multicofork I) → K.pt ⟶ E.pt fac : ∀ (E : Multicofork I) (i : I.R), π K i ≫ desc E = π E i uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ (i : I.R), π K i ≫ m = π E i) → m = desc E S : Cocone (MultispanIndex.multispan I) a : I.L ⊢ NatTrans.app K.ι (WalkingMultispan.left a) ≫ desc S = NatTrans.app S.ι (WalkingMultispan.left a) [PROOFSTEP] rw [← K.w (WalkingMultispan.Hom.fst a), ← S.w (WalkingMultispan.Hom.fst a), Category.assoc] [GOAL] case left C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I desc : (E : Multicofork I) → K.pt ⟶ E.pt fac : ∀ (E : Multicofork I) (i : I.R), π K i ≫ desc E = π E i uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ (i : I.R), π K i ≫ m = π E i) → m = desc E S : Cocone (MultispanIndex.multispan I) a : I.L ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.fst a) ≫ NatTrans.app K.ι (WalkingMultispan.right (MultispanIndex.fstFrom I a)) ≫ desc S = (MultispanIndex.multispan I).map (WalkingMultispan.Hom.fst a) ≫ NatTrans.app S.ι (WalkingMultispan.right (MultispanIndex.fstFrom I a)) [PROOFSTEP] congr 1 [GOAL] case left.e_a C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I desc : (E : Multicofork I) → K.pt ⟶ E.pt fac : ∀ (E : Multicofork I) (i : I.R), π K i ≫ desc E = π E i uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ (i : I.R), π K i ≫ m = π E i) → m = desc E S : Cocone (MultispanIndex.multispan I) a : I.L ⊢ NatTrans.app K.ι (WalkingMultispan.right (MultispanIndex.fstFrom I a)) ≫ desc S = NatTrans.app S.ι (WalkingMultispan.right (MultispanIndex.fstFrom I a)) [PROOFSTEP] apply fac [GOAL] case right C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I desc : (E : Multicofork I) → K.pt ⟶ E.pt fac : ∀ (E : Multicofork I) (i : I.R), π K i ≫ desc E = π E i uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ (i : I.R), π K i ≫ m = π E i) → m = desc E S : Cocone (MultispanIndex.multispan I) b : I.R ⊢ NatTrans.app K.ι (WalkingMultispan.right b) ≫ desc S = NatTrans.app S.ι (WalkingMultispan.right b) [PROOFSTEP] apply fac [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I desc : (E : Multicofork I) → K.pt ⟶ E.pt fac : ∀ (E : Multicofork I) (i : I.R), π K i ≫ desc E = π E i uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ (i : I.R), π K i ≫ m = π E i) → m = desc E ⊢ ∀ (s : Cocone (MultispanIndex.multispan I)) (m : K.pt ⟶ s.pt), (∀ (j : WalkingMultispan I.fstFrom I.sndFrom), NatTrans.app K.ι j ≫ m = NatTrans.app s.ι j) → m = desc s [PROOFSTEP] intro S m hm [GOAL] C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I desc : (E : Multicofork I) → K.pt ⟶ E.pt fac : ∀ (E : Multicofork I) (i : I.R), π K i ≫ desc E = π E i uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ (i : I.R), π K i ≫ m = π E i) → m = desc E S : Cocone (MultispanIndex.multispan I) m : K.pt ⟶ S.pt hm : ∀ (j : WalkingMultispan I.fstFrom I.sndFrom), NatTrans.app K.ι j ≫ m = NatTrans.app S.ι j ⊢ m = desc S [PROOFSTEP] apply uniq [GOAL] case a C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I desc : (E : Multicofork I) → K.pt ⟶ E.pt fac : ∀ (E : Multicofork I) (i : I.R), π K i ≫ desc E = π E i uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ (i : I.R), π K i ≫ m = π E i) → m = desc E S : Cocone (MultispanIndex.multispan I) m : K.pt ⟶ S.pt hm : ∀ (j : WalkingMultispan I.fstFrom I.sndFrom), NatTrans.app K.ι j ≫ m = NatTrans.app S.ι j ⊢ ∀ (i : I.R), π K i ≫ m = π S i [PROOFSTEP] intro i [GOAL] case a C : Type u inst✝ : Category.{v, u} C I : MultispanIndex C K : Multicofork I desc : (E : Multicofork I) → K.pt ⟶ E.pt fac : ∀ (E : Multicofork I) (i : I.R), π K i ≫ desc E = π E i uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ (i : I.R), π K i ≫ m = π E i) → m = desc E S : Cocone (MultispanIndex.multispan I) m : K.pt ⟶ S.pt hm : ∀ (j : WalkingMultispan I.fstFrom I.sndFrom), NatTrans.app K.ι j ≫ m = NatTrans.app S.ι j i : I.R ⊢ π K i ≫ m = π S i [PROOFSTEP] apply hm [GOAL] C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right ⊢ MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) = MultispanIndex.sndSigmaMap I ≫ Sigma.desc (π K) [PROOFSTEP] ext [GOAL] case h C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right b✝ : I.L ⊢ Sigma.ι I.left b✝ ≫ MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) = Sigma.ι I.left b✝ ≫ MultispanIndex.sndSigmaMap I ≫ Sigma.desc (π K) [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K✝ : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ ∀ ⦃X Y : WalkingParallelPair⦄ (f : X ⟶ Y), (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I)).map f ≫ (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) Y = (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) X ≫ ((Functor.const WalkingParallelPair).obj K.pt).map f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case zero.zero.id C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K✝ : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I)).map (WalkingParallelPairHom.id WalkingParallelPair.zero) ≫ (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) WalkingParallelPair.zero = (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) WalkingParallelPair.zero ≫ ((Functor.const WalkingParallelPair).obj K.pt).map (WalkingParallelPairHom.id WalkingParallelPair.zero) [PROOFSTEP] dsimp [GOAL] case zero.one.left C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K✝ : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I)).map WalkingParallelPairHom.left ≫ (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) WalkingParallelPair.one = (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) WalkingParallelPair.zero ≫ ((Functor.const WalkingParallelPair).obj K.pt).map WalkingParallelPairHom.left [PROOFSTEP] dsimp [GOAL] case zero.one.right C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K✝ : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I)).map WalkingParallelPairHom.right ≫ (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) WalkingParallelPair.one = (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) WalkingParallelPair.zero ≫ ((Functor.const WalkingParallelPair).obj K.pt).map WalkingParallelPairHom.right [PROOFSTEP] dsimp [GOAL] case one.one.id C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K✝ : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I)).map (WalkingParallelPairHom.id WalkingParallelPair.one) ≫ (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) WalkingParallelPair.one = (fun x => match x with | WalkingParallelPair.zero => MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) | WalkingParallelPair.one => Sigma.desc (π K)) WalkingParallelPair.one ≫ ((Functor.const WalkingParallelPair).obj K.pt).map (WalkingParallelPairHom.id WalkingParallelPair.one) [PROOFSTEP] dsimp [GOAL] case zero.zero.id C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K✝ : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I)).map (𝟙 WalkingParallelPair.zero) ≫ MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) = (MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K)) ≫ 𝟙 K.pt [PROOFSTEP] simp only [Functor.map_id, parallelPair_obj_zero, parallelPair_obj_one, sigma_condition, Category.id_comp, Category.comp_id] [GOAL] case zero.one.left C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K✝ : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K) = (MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K)) ≫ 𝟙 K.pt [PROOFSTEP] simp only [Functor.map_id, parallelPair_obj_zero, parallelPair_obj_one, sigma_condition, Category.id_comp, Category.comp_id] [GOAL] case zero.one.right C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K✝ : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ MultispanIndex.sndSigmaMap I ≫ Sigma.desc (π K) = (MultispanIndex.fstSigmaMap I ≫ Sigma.desc (π K)) ≫ 𝟙 K.pt [PROOFSTEP] simp only [Functor.map_id, parallelPair_obj_zero, parallelPair_obj_one, sigma_condition, Category.id_comp, Category.comp_id] [GOAL] case one.one.id C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K✝ : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I)).map (𝟙 WalkingParallelPair.one) ≫ Sigma.desc (π K) = Sigma.desc (π K) ≫ 𝟙 K.pt [PROOFSTEP] simp only [Functor.map_id, parallelPair_obj_zero, parallelPair_obj_one, sigma_condition, Category.id_comp, Category.comp_id] [GOAL] C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right c : Cofork (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I) ⊢ ∀ ⦃X Y : WalkingMultispan I.fstFrom I.sndFrom⦄ (f : X ⟶ Y), (MultispanIndex.multispan I).map f ≫ (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) Y = (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) X ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj c.pt).map f [PROOFSTEP] rintro (_ | _) (_ | _) (_ | _ | _) [GOAL] case left.left.id C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right c : Cofork (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I) a✝ : I.L ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝)) ≫ (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) (WalkingMultispan.left a✝) = (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) (WalkingMultispan.left a✝) ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj c.pt).map (WalkingMultispan.Hom.id (WalkingMultispan.left a✝)) [PROOFSTEP] simp [GOAL] case left.right.fst C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right c : Cofork (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I) a✝ : I.L ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.fst a✝) ≫ (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) (WalkingMultispan.right (MultispanIndex.fstFrom I a✝)) = (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) (WalkingMultispan.left a✝) ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj c.pt).map (WalkingMultispan.Hom.fst a✝) [PROOFSTEP] simp [GOAL] case left.right.snd C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right c : Cofork (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I) a✝ : I.L ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.snd a✝) ≫ (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) (WalkingMultispan.right (MultispanIndex.sndFrom I a✝)) = (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) (WalkingMultispan.left a✝) ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj c.pt).map (WalkingMultispan.Hom.snd a✝) [PROOFSTEP] simp [c.condition] [GOAL] case right.right.id C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C K : Multicofork I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right c : Cofork (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I) a✝ : I.R ⊢ (MultispanIndex.multispan I).map (WalkingMultispan.Hom.id (WalkingMultispan.right a✝)) ≫ (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) (WalkingMultispan.right a✝) = (fun x => match x with | WalkingMultispan.left a => Sigma.ι I.left a ≫ MultispanIndex.fstSigmaMap I ≫ Cofork.π c | WalkingMultispan.right b => Sigma.ι I.right b ≫ Cofork.π c) (WalkingMultispan.right a✝) ≫ ((Functor.const (WalkingMultispan I.fstFrom I.sndFrom)).obj c.pt).map (WalkingMultispan.Hom.id (WalkingMultispan.right a✝)) [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ ⊢ ∀ (j : WalkingParallelPair), NatTrans.app (Multicofork.toSigmaCofork K₁).ι j ≫ f.Hom = NatTrans.app (Multicofork.toSigmaCofork K₂).ι j [PROOFSTEP] rintro (_ | _) [GOAL] case zero C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ ⊢ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.zero ≫ f.Hom = NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.zero case one C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ ⊢ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.one ≫ f.Hom = NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.one [PROOFSTEP] all_goals { apply colimit.hom_ext rintro ⟨j⟩ simp } [GOAL] case zero C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ ⊢ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.zero ≫ f.Hom = NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.zero [PROOFSTEP] { apply colimit.hom_ext rintro ⟨j⟩ simp } [GOAL] case zero C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ ⊢ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.zero ≫ f.Hom = NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.zero [PROOFSTEP] apply colimit.hom_ext [GOAL] case zero.w C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ ⊢ ∀ (j : Discrete I.L), colimit.ι (Discrete.functor I.left) j ≫ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.zero ≫ f.Hom = colimit.ι (Discrete.functor I.left) j ≫ NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.zero [PROOFSTEP] rintro ⟨j⟩ [GOAL] case zero.w.mk C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ j : I.L ⊢ colimit.ι (Discrete.functor I.left) { as := j } ≫ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.zero ≫ f.Hom = colimit.ι (Discrete.functor I.left) { as := j } ≫ NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.zero [PROOFSTEP] simp [GOAL] case one C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ ⊢ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.one ≫ f.Hom = NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.one [PROOFSTEP] { apply colimit.hom_ext rintro ⟨j⟩ simp } [GOAL] case one C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ ⊢ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.one ≫ f.Hom = NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.one [PROOFSTEP] apply colimit.hom_ext [GOAL] case one.w C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ ⊢ ∀ (j : Discrete I.R), colimit.ι (Discrete.functor I.right) j ≫ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.one ≫ f.Hom = colimit.ι (Discrete.functor I.right) j ≫ NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.one [PROOFSTEP] rintro ⟨j⟩ [GOAL] case one.w.mk C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Multicofork I f : K₁ ⟶ K₂ j : I.R ⊢ colimit.ι (Discrete.functor I.right) { as := j } ≫ NatTrans.app (Multicofork.toSigmaCofork K₁).ι WalkingParallelPair.one ≫ f.Hom = colimit.ι (Discrete.functor I.right) { as := j } ≫ NatTrans.app (Multicofork.toSigmaCofork K₂).ι WalkingParallelPair.one [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Cofork (fstSigmaMap I) (sndSigmaMap I) f : K₁ ⟶ K₂ ⊢ ∀ (j : WalkingMultispan I.fstFrom I.sndFrom), NatTrans.app (Multicofork.ofSigmaCofork I K₁).ι j ≫ f.Hom = NatTrans.app (Multicofork.ofSigmaCofork I K₂).ι j [PROOFSTEP] rintro (_ | _) -- porting note; in mathlib3, `simp` worked. What seems to be happening is that -- the `simp` set is not confluent, and mathlib3 found -- `Multicofork.ofSigmaCofork_ι_app_left` before `Multicofork.fst_app_right`, -- but mathlib4 finds `Multicofork.fst_app_right` first. [GOAL] case left C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Cofork (fstSigmaMap I) (sndSigmaMap I) f : K₁ ⟶ K₂ a✝ : I.L ⊢ NatTrans.app (Multicofork.ofSigmaCofork I K₁).ι (WalkingMultispan.left a✝) ≫ f.Hom = NatTrans.app (Multicofork.ofSigmaCofork I K₂).ι (WalkingMultispan.left a✝) case right C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Cofork (fstSigmaMap I) (sndSigmaMap I) f : K₁ ⟶ K₂ a✝ : I.R ⊢ NatTrans.app (Multicofork.ofSigmaCofork I K₁).ι (WalkingMultispan.right a✝) ≫ f.Hom = NatTrans.app (Multicofork.ofSigmaCofork I K₂).ι (WalkingMultispan.right a✝) [PROOFSTEP] {simp [-Multicofork.fst_app_right] } -- porting note: similarly here, the `simp` set seems to be non-confluent [GOAL] case left C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Cofork (fstSigmaMap I) (sndSigmaMap I) f : K₁ ⟶ K₂ a✝ : I.L ⊢ NatTrans.app (Multicofork.ofSigmaCofork I K₁).ι (WalkingMultispan.left a✝) ≫ f.Hom = NatTrans.app (Multicofork.ofSigmaCofork I K₂).ι (WalkingMultispan.left a✝) [PROOFSTEP] simp [-Multicofork.fst_app_right] [GOAL] case right C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Cofork (fstSigmaMap I) (sndSigmaMap I) f : K₁ ⟶ K₂ a✝ : I.R ⊢ NatTrans.app (Multicofork.ofSigmaCofork I K₁).ι (WalkingMultispan.right a✝) ≫ f.Hom = NatTrans.app (Multicofork.ofSigmaCofork I K₂).ι (WalkingMultispan.right a✝) [PROOFSTEP] {simp [-Multicofork.ofSigmaCofork_pt] } [GOAL] case right C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K₁ K₂ : Cofork (fstSigmaMap I) (sndSigmaMap I) f : K₁ ⟶ K₂ a✝ : I.R ⊢ NatTrans.app (Multicofork.ofSigmaCofork I K₁).ι (WalkingMultispan.right a✝) ≫ f.Hom = NatTrans.app (Multicofork.ofSigmaCofork I K₂).ι (WalkingMultispan.right a✝) [PROOFSTEP] simp [-Multicofork.ofSigmaCofork_pt] [GOAL] C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I ⊢ ∀ (j : WalkingMultispan I.fstFrom I.sndFrom), NatTrans.app ((𝟭 (Multicofork I)).obj K).ι j ≫ (Iso.refl ((𝟭 (Multicofork I)).obj K).pt).hom = NatTrans.app ((toSigmaCoforkFunctor I ⋙ ofSigmaCoforkFunctor I).obj K).ι j [PROOFSTEP] rintro (_ | _) [GOAL] case left C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I a✝ : I.L ⊢ NatTrans.app ((𝟭 (Multicofork I)).obj K).ι (WalkingMultispan.left a✝) ≫ (Iso.refl ((𝟭 (Multicofork I)).obj K).pt).hom = NatTrans.app ((toSigmaCoforkFunctor I ⋙ ofSigmaCoforkFunctor I).obj K).ι (WalkingMultispan.left a✝) [PROOFSTEP] simp [GOAL] case right C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Multicofork I a✝ : I.R ⊢ NatTrans.app ((𝟭 (Multicofork I)).obj K).ι (WalkingMultispan.right a✝) ≫ (Iso.refl ((𝟭 (Multicofork I)).obj K).pt).hom = NatTrans.app ((toSigmaCoforkFunctor I ⋙ ofSigmaCoforkFunctor I).obj K).ι (WalkingMultispan.right a✝) [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Cofork (fstSigmaMap I) (sndSigmaMap I) ⊢ Cofork.π ((ofSigmaCoforkFunctor I ⋙ toSigmaCoforkFunctor I).obj K) ≫ (Iso.refl ((ofSigmaCoforkFunctor I ⋙ toSigmaCoforkFunctor I).obj K).pt).hom = Cofork.π ((𝟭 (Cofork (fstSigmaMap I) (sndSigmaMap I))).obj K) [PROOFSTEP] apply Limits.colimit.hom_ext [GOAL] case w C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Cofork (fstSigmaMap I) (sndSigmaMap I) ⊢ ∀ (j : Discrete I.R), colimit.ι (Discrete.functor I.right) j ≫ Cofork.π ((ofSigmaCoforkFunctor I ⋙ toSigmaCoforkFunctor I).obj K) ≫ (Iso.refl ((ofSigmaCoforkFunctor I ⋙ toSigmaCoforkFunctor I).obj K).pt).hom = colimit.ι (Discrete.functor I.right) j ≫ Cofork.π ((𝟭 (Cofork (fstSigmaMap I) (sndSigmaMap I))).obj K) [PROOFSTEP] rintro ⟨j⟩ [GOAL] case w.mk C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Cofork (fstSigmaMap I) (sndSigmaMap I) j : I.R ⊢ colimit.ι (Discrete.functor I.right) { as := j } ≫ Cofork.π ((ofSigmaCoforkFunctor I ⋙ toSigmaCoforkFunctor I).obj K) ≫ (Iso.refl ((ofSigmaCoforkFunctor I ⋙ toSigmaCoforkFunctor I).obj K).pt).hom = colimit.ι (Discrete.functor I.right) { as := j } ≫ Cofork.π ((𝟭 (Cofork (fstSigmaMap I) (sndSigmaMap I))).obj K) [PROOFSTEP] dsimp [GOAL] case w.mk C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Cofork (fstSigmaMap I) (sndSigmaMap I) j : I.R ⊢ colimit.ι (Discrete.functor I.right) { as := j } ≫ Sigma.desc (Multicofork.π (Multicofork.ofSigmaCofork I K)) ≫ 𝟙 K.pt = colimit.ι (Discrete.functor I.right) { as := j } ≫ Cofork.π K [PROOFSTEP] simp only [Category.comp_id, colimit.ι_desc, Cofan.mk_ι_app] [GOAL] case w.mk C : Type u inst✝² : Category.{v, u} C I : MultispanIndex C inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right K : Cofork (fstSigmaMap I) (sndSigmaMap I) j : I.R ⊢ Multicofork.π (Multicofork.ofSigmaCofork I K) j = colimit.ι (Discrete.functor I.right) { as := j } ≫ Cofork.π K [PROOFSTEP] rfl [GOAL] C : Type u inst✝¹ : Category.{v, u} C I : MulticospanIndex C inst✝ : HasMultiequalizer I W : C i j : W ⟶ multiequalizer I h : ∀ (a : I.L), i ≫ ι I a = j ≫ ι I a ⊢ ∀ (j_1 : WalkingMulticospan I.fstTo I.sndTo), i ≫ limit.π (MulticospanIndex.multicospan I) j_1 = j ≫ limit.π (MulticospanIndex.multicospan I) j_1 [PROOFSTEP] rintro (a | b) [GOAL] case left C : Type u inst✝¹ : Category.{v, u} C I : MulticospanIndex C inst✝ : HasMultiequalizer I W : C i j : W ⟶ multiequalizer I h : ∀ (a : I.L), i ≫ ι I a = j ≫ ι I a a : I.L ⊢ i ≫ limit.π (MulticospanIndex.multicospan I) (WalkingMulticospan.left a) = j ≫ limit.π (MulticospanIndex.multicospan I) (WalkingMulticospan.left a) [PROOFSTEP] apply h [GOAL] case right C : Type u inst✝¹ : Category.{v, u} C I : MulticospanIndex C inst✝ : HasMultiequalizer I W : C i j : W ⟶ multiequalizer I h : ∀ (a : I.L), i ≫ ι I a = j ≫ ι I a b : I.R ⊢ i ≫ limit.π (MulticospanIndex.multicospan I) (WalkingMulticospan.right b) = j ≫ limit.π (MulticospanIndex.multicospan I) (WalkingMulticospan.right b) [PROOFSTEP] simp_rw [← limit.w I.multicospan (WalkingMulticospan.Hom.fst b), ← Category.assoc, h] [GOAL] C : Type u inst✝³ : Category.{v, u} C I : MulticospanIndex C inst✝² : HasMultiequalizer I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right a : I.L ⊢ ιPi I ≫ Pi.π I.left a = ι I a [PROOFSTEP] rw [ιPi, Category.assoc, ← Iso.eq_inv_comp, isoEqualizer] [GOAL] C : Type u inst✝³ : Category.{v, u} C I : MulticospanIndex C inst✝² : HasMultiequalizer I inst✝¹ : HasProduct I.left inst✝ : HasProduct I.right a : I.L ⊢ equalizer.ι (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I) ≫ Pi.π I.left a = (limit.isoLimitCone { cone := (MulticospanIndex.multiforkEquivPiFork I).inverse.obj (limit.cone (parallelPair (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I))), isLimit := IsLimit.ofPreservesConeTerminal (MulticospanIndex.multiforkEquivPiFork I).inverse (limit.isLimit (parallelPair (MulticospanIndex.fstPiMap I) (MulticospanIndex.sndPiMap I))) }).inv ≫ ι I a [PROOFSTEP] simp [GOAL] C : Type u inst✝¹ : Category.{v, u} C I : MultispanIndex C inst✝ : HasMulticoequalizer I W : C i j : multicoequalizer I ⟶ W h : ∀ (b : I.R), π I b ≫ i = π I b ≫ j ⊢ ∀ (j_1 : WalkingMultispan I.fstFrom I.sndFrom), colimit.ι (MultispanIndex.multispan I) j_1 ≫ i = colimit.ι (MultispanIndex.multispan I) j_1 ≫ j [PROOFSTEP] rintro (a | b) [GOAL] case left C : Type u inst✝¹ : Category.{v, u} C I : MultispanIndex C inst✝ : HasMulticoequalizer I W : C i j : multicoequalizer I ⟶ W h : ∀ (b : I.R), π I b ≫ i = π I b ≫ j a : I.L ⊢ colimit.ι (MultispanIndex.multispan I) (WalkingMultispan.left a) ≫ i = colimit.ι (MultispanIndex.multispan I) (WalkingMultispan.left a) ≫ j [PROOFSTEP] simp_rw [← colimit.w I.multispan (WalkingMultispan.Hom.fst a), Category.assoc, h] [GOAL] case right C : Type u inst✝¹ : Category.{v, u} C I : MultispanIndex C inst✝ : HasMulticoequalizer I W : C i j : multicoequalizer I ⟶ W h : ∀ (b : I.R), π I b ≫ i = π I b ≫ j b : I.R ⊢ colimit.ι (MultispanIndex.multispan I) (WalkingMultispan.right b) ≫ i = colimit.ι (MultispanIndex.multispan I) (WalkingMultispan.right b) ≫ j [PROOFSTEP] apply h [GOAL] C : Type u inst✝³ : Category.{v, u} C I : MultispanIndex C inst✝² : HasMulticoequalizer I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right b : I.R ⊢ Sigma.ι I.right b ≫ sigmaπ I = π I b [PROOFSTEP] rw [sigmaπ, ← Category.assoc, Iso.comp_inv_eq, isoCoequalizer] [GOAL] C : Type u inst✝³ : Category.{v, u} C I : MultispanIndex C inst✝² : HasMulticoequalizer I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right b : I.R ⊢ Sigma.ι I.right b ≫ coequalizer.π (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I) = π I b ≫ (colimit.isoColimitCocone { cocone := (MultispanIndex.multicoforkEquivSigmaCofork I).inverse.obj (colimit.cocone (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I))), isColimit := IsColimit.ofPreservesCoconeInitial (MultispanIndex.multicoforkEquivSigmaCofork I).inverse (colimit.isColimit (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I))) }).hom [PROOFSTEP] simp only [MultispanIndex.multicoforkEquivSigmaCofork_inverse, MultispanIndex.ofSigmaCoforkFunctor_obj, colimit.isoColimitCocone_ι_hom, Multicofork.ofSigmaCofork_pt, colimit.cocone_x, Multicofork.π_eq_app_right] [GOAL] C : Type u inst✝³ : Category.{v, u} C I : MultispanIndex C inst✝² : HasMulticoequalizer I inst✝¹ : HasCoproduct I.left inst✝ : HasCoproduct I.right b : I.R ⊢ Sigma.ι I.right b ≫ coequalizer.π (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I) = Multicofork.π (Multicofork.ofSigmaCofork I (colimit.cocone (parallelPair (MultispanIndex.fstSigmaMap I) (MultispanIndex.sndSigmaMap I)))) b [PROOFSTEP] rfl
function [ y, next ] = p39_equil ( neqn, next ) %*****************************************************************************80 % %% P39_EQUIL returns equilibrium solutions of problem p39. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 19 February 2013 % % Author: % % John Burkardt % % Parameters: % % Input, integer NEQN, the number of equations. % % Input, integer NEXT, the index of the previous % equilibrium, which should be 0 on first call. % % Output, real Y(NEQN), the "next" equilibrium solution, if any. % % Output, integer NEXT, the index of the current equilibrium, % or 0 if there are no more. % next = 0; y = []; return end
From machine_program_logic.program_logic Require Import machine weakestpre adequacy. From iris.algebra Require Import big_op. From HypVeri Require Import machine_extra lifting. From HypVeri.algebra Require Import base mailbox pagetable mem. From HypVeri.lang Require Import reg_extra. From HypVeri.examples Require Import instr utils. From HypVeri.logrel Require Import logrel logrel_extra logrel_prim_extra. From HypVeri.examples.mem_trans_msg_send Require Import proof. Require Import Setoid. Section mtms_adequacy. Context `{hypparams: !HypervisorParameters}. Context (p_prog0 p_prog1 p_prog2 : PID). Context (p_tx0 p_rx0 p_tx1 p_rx1 p_tx2 p_rx2 : PID). Context (p_share : PID). Context (Hps_nd: NoDup [p_prog0;p_prog1;p_prog2;p_share;p_tx0;p_tx1;p_tx2;p_rx0;p_rx1;p_rx2]). Context (addr : Imm) (Heq_pshare : of_pid p_share = addr). Context (i_ptx0 : Imm) (Heq_ptx0 : of_pid p_tx0 = i_ptx0). Context (i_prx1 : Imm) (Heq_prx1 : of_pid p_rx1 = i_prx1). Context (σ : state). Definition pgt := access_layout σ {[V0 := to_dfrac_agree (DfracOwn 1) {[p_share; p_prog0; p_tx0]}; V1 := to_dfrac_agree (DfracOwn 1) {[p_prog1; p_tx1; p_rx1]}; V2 := to_dfrac_agree (DfracOwn 1) {[p_tx2; p_rx2; p_prog2]}]} ∧ excl_layout σ {[p_rx0 := true; p_rx1 := true; p_rx2 := true; p_tx2 := true; p_prog2 := true; p_share:= true]} ∧ own_layout σ {[p_rx0 := None; p_rx1 := None; p_rx2 := None; p_tx2 := None; p_prog2 := Some V2; p_share:= Some V0]}. Program Definition mem:= let mem := ((get_mem σ): gmap Addr Word) in (∀ (m : gmap Addr Addr), dom m = set_of_addr {[p_prog0]} -> m ⊆ mem -> m = mem_page_program p_prog0 (mtms_program0 addr i_ptx0) _) ∧ (∀ (m : gmap Addr Addr), dom m = set_of_addr {[p_prog1]} -> m ⊆ mem -> m = mem_page_program p_prog1 (mtms_program1 addr i_prx1) _) ∧ ((set_of_addr {[p_prog0;p_prog1; p_share; p_prog2;p_tx0; p_tx1; p_tx2;p_rx0;p_rx1;p_rx2]}) ⊆ dom mem). Next Obligation. lia. Qed. Next Obligation. lia. Qed. Definition regs := reg_layout σ ({[PC:=of_pid p_prog0]}) V0 ∧ reg_layout σ ({[PC:=of_pid p_prog1]}) V1 ∧ ∀ i rn, is_Some (((get_reg_files σ) !!! i) !! rn). Definition mailbox:= mailbox_layout σ {[(V0, TX) := p_tx0; (V1, TX) := p_tx1; (V2, TX) := p_tx2; (V0, RX) := p_rx0; (V1, RX) := p_rx1; (V2, RX) := p_rx2]} ∧ rx_layout σ {[V0 := None; V1 := None; V2 := None]}. Definition transactions := σ.2 = {[W0 := None]}. Definition initial_config (ms: list exec_mode) (φs : list (exec_mode -> Prop)):= (get_current_vm σ) = V0 ∧ φs = [(λ m , m = HaltI); (λ _, False); (λ _, True)] ∧ ms = [ExecI;ExecI;ExecI] ∧ pgt ∧ mem ∧ regs ∧ mailbox ∧ transactions. Context {vm_preG: gen_VMPreG Addr VMID Word reg_name PID transaction_type irisΣ}. Lemma memory_list_gmap (pid : PID) (mem_list : list Word) (Hle: length mem_list < (Z.to_nat page_size)) (mem_gmap : gmap Addr Word) (H : NoDup (zip (finz.seq pid (length mem_list)) mem_list).*1) (G : mem_gmap = mem_page_program pid mem_list Hle) γ : (([∗ list] xk ∈ map_to_list mem_gmap, xk.1 ↪[γ] xk.2) -∗ [∗ list] xy ∈ zip (finz.seq pid (length mem_list)) mem_list, xy.1 ↪[γ] xy.2). Proof. rewrite G /mem_page_program //. rewrite map_to_list_to_map; first done. rewrite fst_zip. - apply finz_seq_NoDup'. simpl. pose proof (last_addr_in_bound pid). solve_finz. - rewrite finz_seq_length. lia. Qed. Lemma get_reg_gmap_split γ: ([∗ map] p↦w ∈ (get_reg_gmap σ) , p ↪[γ] w)%I ⊢ [∗ list] i ∈ ((list_of_vmids): list VMID), [∗ map] p↦w ∈ get_reg_gmap_vm σ i, p ↪[γ] w. Proof. iIntros "Hmap". rewrite /get_reg_gmap. pose proof (NoDup_list_of_vmids) as Hnodup. iInduction (list_of_vmids) as [ | i l] "IH". done. rewrite list_to_map_app. rewrite big_sepM_union. iDestruct "Hmap" as "[Hsub Hmap]". iSplitL "Hsub". { rewrite /get_reg_gmap_vm. iFrame "Hsub". } iApply "IH". { iPureIntro. apply NoDup_cons in Hnodup. destruct Hnodup;auto. } iFrame "Hmap". apply map_disjoint_list_to_map_l. apply Forall_forall. intros. assert (∀ (v: VMID) x, x ∈ map (λ p : reg_name * Addr, (p.1, v, p.2)) (map_to_list (σ.1.1.1.1.1 !!! v)) -> x.1.2 = v). { intros. apply elem_of_list_In in H0. apply in_map_iff in H0. destruct H0 as [? [Heq Hin]]. destruct x0. destruct p. simpl. simplify_eq /=. done. } apply H0 in H. destruct (x.1). simpl in H. subst v. apply not_elem_of_list_to_map_1. intro. apply elem_of_list_In in H. apply in_map_iff in H. destruct H as [p]. destruct H as [Heqn H1]. apply in_flat_map in H1. destruct H1 as [i']. destruct H as [HIn H]. apply elem_of_list_In in H. apply H0 in H. rewrite Heqn in H. simpl in H. subst i'. apply NoDup_cons in Hnodup as [Hnotin ?]. rewrite -elem_of_list_In in HIn. contradiction. Qed. (* exec_mode of all VMs *) Lemma adequacy (ms : list exec_mode) φs: (* we need assumptions to be able to allocate resources *) (* with these resources, we apply the specification and get the wptp *) (* along with some other stuff, then it should be enough to apply the adequacy theorem *) (initial_config ms φs) -> adequate ms σ ((λ φ, λ v _, φ v)<$> φs). (* φ : vm 0 is scheduled but halted *) Proof. intros Hinit. destruct Hinit as (Hcur & -> & -> & Hpgt & Hmem & Hreg & Hmb & Htrans). set (saved_props := (let (_, x, _, _) := iris_subG irisΣ (subG_refl irisΣ) in x)). set (prop_name := (let (_, _, x, _) := iris_subG irisΣ (subG_refl irisΣ) in x)). set (name_map := (let (_, _, _, x) := iris_subG irisΣ (subG_refl irisΣ) in x)). eapply (wp_adequacy irisΣ); auto. intro Hinv. iIntros. iMod (gen_mem_alloc σ) as (mem_gname) "[Hσmem Hmem]". iMod (gen_reg_alloc σ) as (reg_gname) "[Hσreg Hreg]". iMod (gen_mb_alloc σ) as (mb_gname) "[Hσmb Hmb]". iMod (gen_rx_state_alloc σ) as (rx_state_gname) "[Hσrxs Hrxs]". iMod (gen_own_alloc σ) as (own_gname) "[Hσown Hown]". iMod (gen_access_alloc σ) as (access_gname) "[Hσaccess Haccess]". iMod (gen_excl_alloc σ) as (excl_gname) "[Hσexcl Hexcl]". iMod (gen_trans_alloc σ) as (trans_gname) "[Hσtrans Htrans]". iMod (gen_hpool_alloc σ) as (hpool_gname) "[Hσhpool Hhpool]". iMod (gen_retri_alloc σ) as (retri_gname) "[Hσretri Hretri]". iModIntro. iIntros (name_map_name). pose ((GenVMG irisΣ vm_preG Hinv _ _ _ name_map_name mem_gname reg_gname mb_gname rx_state_gname own_gname access_gname excl_gname trans_gname hpool_gname retri_gname)) as VMG. iExists (gen_vm_interp (Σ := irisΣ)). destruct Hreg as (Hlookup_reg0 & Hlookup_reg1 & Htotal_reg). (* use assumptions to extract resources *) (** extract regs **) iDestruct (get_reg_gmap_split with "Hreg") as "(Hreg0 & Hreg1 & Hreg2 & _)". (* TODO: move, do the same for other resources *) assert (∀ σ f, ([∗ map] p↦w ∈ get_reg_gmap_vm σ f, p ↪[reg_gname] w)%I = ([∗ map] p↦w ∈ get_reg_gmap_vm σ f, p.1 @@ p.2 ->r w)%I) as sepM_reg_def. { intros σ' f'. apply big_opM_ext. intros k x H. destruct k as [k1 k2]. simpl. rewrite reg_mapsto_eq /reg_mapsto_def //. } iEval (rewrite sepM_reg_def) in "Hreg0 Hreg1 Hreg2". clear sepM_reg_def. (* extract regs of VM0 *) pose proof (Htotal_reg V0 R0) as [r0_ Hlookup_reg0_r0]. pose proof (Htotal_reg V0 R1) as [r1_ Hlookup_reg0_r1]. pose proof (Htotal_reg V0 R2) as [r2_ Hlookup_reg0_r2]. pose proof (Htotal_reg V0 R3) as [r3_ Hlookup_reg0_r3]. pose proof (Htotal_reg V0 R4) as [r4_ Hlookup_reg0_r4]. pose proof (Htotal_reg V0 R5) as [r5_ Hlookup_reg0_r5]. iDestruct (big_sepM_subseteq _ (get_reg_gmap_vm σ V0) {[(PC, V0):= (of_pid p_prog0); (R0, V0) := r0_; (R1,V0):= r1_; (R2,V0):= r2_; (R3,V0):= r3_; (R4,V0):= r4_; (R5,V0):= r5_]} with "Hreg0") as "Hreg0";eauto. { apply (λ x, reg_layout_extend σ _ _ x R5 r5_ Hlookup_reg0_r5) in Hlookup_reg0. apply (λ x, reg_layout_extend σ _ _ x R4 r4_ Hlookup_reg0_r4) in Hlookup_reg0. apply (λ x, reg_layout_extend σ _ _ x R3 r3_ Hlookup_reg0_r3) in Hlookup_reg0. apply (λ x, reg_layout_extend σ _ _ x R2 r2_ Hlookup_reg0_r2) in Hlookup_reg0. apply (λ x, reg_layout_extend σ _ _ x R1 r1_ Hlookup_reg0_r1) in Hlookup_reg0. apply (λ x, reg_layout_extend σ _ _ x R0 r0_ Hlookup_reg0_r0) in Hlookup_reg0. apply reg_layout_get_reg_gmap in Hlookup_reg0; last assumption. clear -Hlookup_reg0. rewrite !kmap_insert in Hlookup_reg0. rewrite kmap_empty in Hlookup_reg0. rewrite insert_empty in Hlookup_reg0. rewrite (insert_commute _ (R5, V0) (PC, V0)) in Hlookup_reg0. rewrite (insert_commute _ (R4, V0) (PC, V0)) in Hlookup_reg0. rewrite (insert_commute _ (R3, V0) (PC, V0)) in Hlookup_reg0. rewrite (insert_commute _ (R2, V0) (PC, V0)) in Hlookup_reg0. rewrite (insert_commute _ (R1, V0) (PC, V0)) in Hlookup_reg0. rewrite (insert_commute _ (R0, V0) (PC, V0)) in Hlookup_reg0. assumption. 1-6: done. } clear Hlookup_reg0_r0 Hlookup_reg0_r1 Hlookup_reg0_r2 Hlookup_reg0_r3 Hlookup_reg0_r4 Hlookup_reg0_r5 Hlookup_reg0. iDestruct (big_sepM_insert with "Hreg0") as "(PCz & Hreg0)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg0") as "(R0z & Hreg0)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg0") as "(R1z & Hreg0)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg0") as "(R2z & Hreg0)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg0") as "(R3z & Hreg0)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg0") as "(R4z & Hreg0)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg0") as "(R5z & _)". { rewrite lookup_empty; eauto. } (* extract regs of VM1 *) pose proof (Htotal_reg V1 R0) as [r0__ Hlookup_reg1_r0]. pose proof (Htotal_reg V1 R1) as [r1__ Hlookup_reg1_r1]. pose proof (Htotal_reg V1 R2) as [r2__ Hlookup_reg1_r2]. pose proof (Htotal_reg V1 R3) as [r3__ Hlookup_reg1_r3]. pose proof (Htotal_reg V1 R4) as [r4__ Hlookup_reg1_r4]. pose proof (Htotal_reg V1 R5) as [r5__ Hlookup_reg1_r5]. iDestruct (big_sepM_subseteq _ (get_reg_gmap_vm σ V1) {[(PC, V1):= (of_pid p_prog1); (R0, V1) := r0__; (R1, V1) := r1__; (R2, V1) := r2__; (R3, V1) := r3__; (R4, V1) := r4__; (R5, V1) := r5__]} with "Hreg1") as "Hreg1";eauto. { apply (λ x, reg_layout_extend σ _ _ x R5 r5__ Hlookup_reg1_r5) in Hlookup_reg1. apply (λ x, reg_layout_extend σ _ _ x R4 r4__ Hlookup_reg1_r4) in Hlookup_reg1. apply (λ x, reg_layout_extend σ _ _ x R3 r3__ Hlookup_reg1_r3) in Hlookup_reg1. apply (λ x, reg_layout_extend σ _ _ x R2 r2__ Hlookup_reg1_r2) in Hlookup_reg1. apply (λ x, reg_layout_extend σ _ _ x R1 r1__ Hlookup_reg1_r1) in Hlookup_reg1. apply (λ x, reg_layout_extend σ _ _ x R0 r0__ Hlookup_reg1_r0) in Hlookup_reg1. apply reg_layout_get_reg_gmap in Hlookup_reg1; last assumption. clear -Hlookup_reg1. rewrite !kmap_insert in Hlookup_reg1. rewrite kmap_empty in Hlookup_reg1. rewrite insert_empty in Hlookup_reg1. rewrite (insert_commute _ (R5, V1) (PC, V1)) in Hlookup_reg1. rewrite (insert_commute _ (R4, V1) (PC, V1)) in Hlookup_reg1. rewrite (insert_commute _ (R3, V1) (PC, V1)) in Hlookup_reg1. rewrite (insert_commute _ (R2, V1) (PC, V1)) in Hlookup_reg1. rewrite (insert_commute _ (R1, V1) (PC, V1)) in Hlookup_reg1. rewrite (insert_commute _ (R0, V1) (PC, V1)) in Hlookup_reg1. assumption. 1-6: done. } clear Hlookup_reg1_r0 Hlookup_reg1_r1 Hlookup_reg1_r2 Hlookup_reg1_r3 Hlookup_reg1_r4 Hlookup_reg1_r5 Hlookup_reg1. iDestruct (big_sepM_insert with "Hreg1") as "(PC1 & Hreg1)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg1") as "(R01 & Hreg1)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg1") as "(R11 & Hreg1)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg1") as "(R21 & Hreg1)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg1") as "(R31 & Hreg1)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg1") as "(R41 & Hreg1)". { rewrite !lookup_insert_None; repeat (split; eauto). } iDestruct (big_sepM_insert with "Hreg1") as "(R51 & _)". { rewrite lookup_empty; eauto. } iDestruct (big_sepM_subseteq _ (get_mb_gmap σ) {[(V0, TX):= p_tx0; (V1, TX) := (p_tx1); (V2, TX) := (p_tx2); (V0, RX) := p_rx0; (V1, RX) := p_rx1; (V2, RX) := p_rx2]} with "Hmb") as "Hmb";eauto. { apply mailbox_layout_get_mb_gmap. apply Hmb. } iDestruct (big_sepM_insert with "Hmb") as "(mb0TX & Hmb)". { rewrite !lookup_insert_None; split; eauto. } iDestruct (big_sepM_insert with "Hmb") as "(mb1TX & Hmb)". { rewrite !lookup_insert_None; split; eauto. } iDestruct (big_sepM_insert with "Hmb") as "(mb2TX & Hmb)". { rewrite !lookup_insert_None; split; eauto. } iDestruct (big_sepM_insert with "Hmb") as "(mb0RX & Hmb)". { rewrite !lookup_insert_None; split; eauto. } iDestruct (big_sepM_insert with "Hmb") as "(mb1RX & Hmb)". { rewrite !lookup_insert_None; split; eauto. } iDestruct (big_sepM_insert with "Hmb") as "(mb2RX & _)". { rewrite lookup_empty; eauto. } iDestruct (big_sepM_subseteq _ (get_rx_gmap σ) {[V0:= None; V1 := None; V2 := None]} with "Hrxs") as "Hrxs";eauto. { apply rx_layout_get_rx_gmap. apply Hmb. } iDestruct (big_sepM_insert with "Hrxs") as "(RX0St & Hrxs)". { rewrite !lookup_insert_None; split; eauto. } iDestruct (big_sepM_insert with "Hrxs") as "(RX1St & Hrxs)". { rewrite !lookup_insert_None; split; eauto. } iDestruct (big_sepM_insert with "Hrxs") as "(RX2St & _)". { rewrite lookup_empty; eauto. } (** extract mem **) destruct Hmem as ( HmemH1 & HmemH2 & Hdom_mem). destruct Hpgt as (pgt_acc & pgt_excl & pgt_own). pose proof (union_split_difference_intersection_subseteq_L _ _ Hdom_mem) as [Hdom_mem_union Hdom_mem_disj]. pose proof (dom_union_inv_L _ _ _ Hdom_mem_disj Hdom_mem_union) as (mem' & mem2 & Hunion_mem' & Hdisj_mem' & _ & Hdom_mem2). iDestruct (big_sepM_subseteq _ (get_mem σ) mem2 with "Hmem") as "Hmem"; eauto. { rewrite Hunion_mem'. apply map_union_subseteq_r. done. } assert (NoDup' [p_prog0;p_prog1;p_prog2;p_share;p_tx0;p_tx1;p_tx2;p_rx0;p_rx1;p_rx2]) as Hps_nd'. { rewrite /NoDup'. intros. intro. apply H1. pose proof Hps_nd as Hps_nd'. rewrite NoDup_alt in Hps_nd'. apply lookup_lt_is_Some_2 in H. apply lookup_lt_is_Some_2 in H0. destruct H, H0. rewrite H2 in H. rewrite H in H0. inversion H0;subst x0;clear H0. eapply Hps_nd';eauto. rewrite H2;done. } pose proof (union_split_difference_intersection_subseteq_L {[p_prog0; p_prog1; p_share; p_prog2; p_tx0; p_tx1; p_tx2; p_rx0; p_rx1; p_rx2]} {[p_prog0]}) as [Heq Hdisj]. set_solver +. rewrite Heq in Hdom_mem2. rewrite set_of_addr_union in Hdom_mem2. 2 : { set_solver +. } clear Heq. apply dom_union_inv_L in Hdom_mem2. 2 : { apply set_of_addr_disj. done. } destruct Hdom_mem2 as (mem1 & mem_p_prog0 & -> & Hmem1_disj & Hdom_mem1 & Hdom_mem_p_prog0). iDestruct ((big_sepM_union _ _) with "Hmem") as "(Hmem1 & mem_p_prog0)";auto. clear Hdisj. pose proof (union_split_difference_intersection_subseteq_L ({[p_prog0; p_prog1; p_share; p_prog2; p_tx0; p_tx1; p_tx2; p_rx0; p_rx1; p_rx2]} ∖ {[p_prog0]}) {[p_prog1]}) as [Heq Hdisj]. apply singleton_subseteq_l. rewrite !difference_union_distr_l_L. rewrite difference_diag_L. rewrite union_empty_l_L. rewrite <-!difference_union_distr_l_L. rewrite difference_disjoint_L. set_solver +. solve_NoDup 0. rewrite Heq in Hdom_mem1. rewrite set_of_addr_union in Hdom_mem1. 2 : { set_solver. } clear Heq. apply dom_union_inv_L in Hdom_mem1. 2 : { apply set_of_addr_disj. done. } destruct Hdom_mem1 as (mem2 & mem_p_prog1 & -> & Hmem2_disj & Hdom_mem2 & Hdom_mem_p_prog1). clear Hdisj. iDestruct ((big_sepM_union _ _) with "Hmem1") as "(Hmem2 & mem_p_prog1)";auto. pose proof (union_split_difference_intersection_subseteq_L (({[p_prog0; p_prog1; p_share; p_prog2; p_tx0; p_tx1; p_tx2; p_rx0; p_rx1; p_rx2]} ∖ {[p_prog0]}) ∖ {[p_prog1]}) {[p_share]}) as [Heq Hdisj]. apply singleton_subseteq_l. rewrite !difference_union_distr_l_L. rewrite !difference_diag_L. do 7 (rewrite elem_of_union; left). rewrite elem_of_union; right. rewrite ->2elem_of_difference. split; [split; first set_solver + |]. solve_NoDup 0. solve_NoDup 1. rewrite Heq in Hdom_mem2. rewrite set_of_addr_union in Hdom_mem2. 2 : { set_solver +. } clear Heq. apply dom_union_inv_L in Hdom_mem2. 2 : { apply set_of_addr_disj. done. } destruct Hdom_mem2 as (mem_p & mem & -> & Hmem_disj & Hdom_mem' & Hdom_mem_p). iDestruct ((big_sepM_union _ _) with "Hmem2") as "(Hmem & mem_p)";auto. clear Hdisj. match goal with | [ H : context G [?a ∖ ?b ∖ ?c ∖ ?d] |- _ ] => set p := a; set q := b; set r := c; set t := d end. change {[p_prog0; p_prog1; p_prog2; p_tx0; p_tx1; p_tx2; p_rx0; p_rx1; p_rx2]} with p in Hdom_mem'. change {[p_prog0]} with q in Hdom_mem'. change {[p_prog1]} with r in Hdom_mem'. change {[p_share]} with t in Hdom_mem'. assert (p ∖ q ∖ r ∖ t = {[p_prog2; p_tx0; p_tx1; p_tx2; p_rx0; p_rx1; p_rx2]}) as Heq. { assert (p ∖ q ∖ r = {[p_share; p_prog2; p_tx0; p_tx1; p_tx2; p_rx0; p_rx1; p_rx2]}) as ->. { assert (p ∖ q = {[p_prog1; p_share; p_prog2; p_tx0; p_tx1; p_tx2; p_rx0; p_rx1; p_rx2]}) as ->. { subst p q. rewrite !difference_union_distr_l_L. rewrite difference_diag_L. rewrite union_empty_l_L. rewrite <-!difference_union_distr_l_L. rewrite difference_disjoint_L. - reflexivity. - solve_NoDup 0. } subst r. rewrite !difference_union_distr_l_L. rewrite difference_diag_L. rewrite union_empty_l_L. rewrite <-!difference_union_distr_l_L. rewrite difference_disjoint_L. - reflexivity. - solve_NoDup 1. } subst t. rewrite !difference_union_distr_l_L. rewrite difference_diag_L. rewrite union_empty_l_L. rewrite <-!difference_union_distr_l_L. rewrite difference_disjoint_L. - reflexivity. - solve_NoDup 3. } rewrite Heq in Hdom_mem'. clear Heq. rewrite set_of_addr_union in Hdom_mem'. 2 : { solve_NoDup 9. } apply dom_union_inv_L in Hdom_mem'. 2 : { apply set_of_addr_disj. solve_NoDup 9. } destruct Hdom_mem' as (mem3 & mem_p_rx2 & -> & Hmem3_disj & Hdom_mem1 & Hdom_mem_p_rx2). iDestruct ((big_sepM_union _ _) with "Hmem") as "(Hmem2 & p_rx2)";auto. rewrite set_of_addr_union in Hdom_mem1. 2 : { solve_NoDup 8. } apply dom_union_inv_L in Hdom_mem1. 2 : { apply set_of_addr_disj. solve_NoDup 8. } destruct Hdom_mem1 as (mem4 & mem_p_rx1 & -> & Hmem4_disj & Hdom_mem2 & Hdom_mem_p_rx1). iDestruct ((big_sepM_union _ _) with "Hmem2") as "(Hmem2 & p_rx1)";auto. rewrite set_of_addr_union in Hdom_mem2. 2 : { solve_NoDup 7. } apply dom_union_inv_L in Hdom_mem2. 2 : { apply set_of_addr_disj. solve_NoDup 7. } destruct Hdom_mem2 as (mem5 & mem_p_rx0 & -> & Hmem5_disj & Hdom_mem1 & Hdom_mem_p_rx0). iDestruct ((big_sepM_union _ _) with "Hmem2") as "(Hmem2 & p_rx0)";auto. rewrite set_of_addr_union in Hdom_mem1. 2 : { solve_NoDup 6. } apply dom_union_inv_L in Hdom_mem1. 2 : { apply set_of_addr_disj. solve_NoDup 6. } destruct Hdom_mem1 as (mem3 & mem_p_tx2 & -> & Hmem6_disj & Hdom_mem2 & Hdom_mem_p_tx2). iDestruct ((big_sepM_union _ _) with "Hmem2") as "(Hmem2 & p_tx2)";auto. rewrite set_of_addr_union in Hdom_mem2. 2 : { solve_NoDup 5. } apply dom_union_inv_L in Hdom_mem2. 2 : { apply set_of_addr_disj. solve_NoDup 5. } destruct Hdom_mem2 as (mem4 & mem_p_tx1 & -> & Hmem7_disj & Hdom_mem2 & Hdom_mem_p_tx1). iDestruct ((big_sepM_union _ _) with "Hmem2") as "(Hmem2 & p_tx1)";auto. rewrite set_of_addr_union in Hdom_mem2. 2 : { solve_NoDup 4. } apply dom_union_inv_L in Hdom_mem2. 2 : { apply set_of_addr_disj. solve_NoDup 4. } destruct Hdom_mem2 as (mem5 & mem_p_tx0 & -> & Hmem8_disj & Hdom_mem3 & Hdom_mem_p_tx0). iDestruct ((big_sepM_union _ _) with "Hmem2") as "(Hmem2 & p_tx0)";auto. subst p q r t. clear Hmem8_disj Hmem7_disj Hmem6_disj Hmem5_disj Hmem4_disj Hmem3_disj. iAssert (trans.fresh_handles 1 valid_handles)%I with "[Hhpool Htrans Hretri]" as "Hp". { unfold trans.fresh_handles. unfold get_hpool_gset. unfold get_fresh_handles. rewrite hpool_mapsto_eq /hpool_mapsto_def. rewrite Htrans. simpl. rewrite map_filter_singleton_True. rewrite dom_singleton_L. rewrite intersection_idemp_L. iFrame "Hhpool". rewrite big_sepS_sep. unfold get_trans_gmap. unfold get_retri_gmap. unfold get_transactions_gmap. rewrite Htrans. rewrite !map_fmap_singleton. rewrite !big_sepM_singleton. rewrite !big_sepS_singleton. iSplitL "Htrans". rewrite trans_mapsto_eq /trans_mapsto_def /=. iFrame. done. rewrite retri_mapsto_eq /retri_mapsto_def /=. iFrame. done. done. } iDestruct (big_sepM_subseteq _ (get_access_gmap σ) {[V0 := (to_dfrac_agree (DfracOwn 1) ({[p_share; p_prog0; p_tx0]})); V1 := (to_dfrac_agree (DfracOwn 1) ({[p_prog1; p_tx1; p_rx1]})); V2 := (to_dfrac_agree (DfracOwn 1) ({[p_tx2;p_rx2;p_prog2]}))]} with "Haccess") as "access"; eauto. { apply access_layout_get_access_gmap. assumption. } iEval (rewrite big_opM_insert_delete) in "access". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete V0 P = P) as ->. { subst P. clear. apply delete_notin. by simplify_map_eq /=. } subst P. iEval (rewrite big_opM_insert_delete) in "access". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete V1 P = P) as ->. { subst P. clear. apply delete_notin. by simplify_map_eq /=. } subst P. iEval (rewrite big_sepM_singleton) in "access". iDestruct "access" as "(access1 & access2 & access3)". iDestruct (big_sepM_subseteq _ (get_excl_gmap σ) {[p_rx0 := true; p_rx1 := true; p_rx2 := true; p_tx2 := true; p_prog2 := true; p_share := true]} with "Hexcl") as "excl"; eauto. { apply excl_layout_get_excl_gmap. assumption. } iEval (rewrite big_opM_insert_delete) in "excl". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_rx0 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. solve_NoDup_pre. solve_NoDup_pre'. solve_NoDup_pre'' 7 8. solve_NoDup 7. } subst P. iEval (rewrite big_opM_insert_delete) in "excl". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_rx1 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. solve_NoDup_pre. solve_NoDup_pre'. solve_NoDup_pre'' 8 9. solve_NoDup 8. } subst P. iEval (rewrite big_opM_insert_delete) in "excl". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_rx2 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. solve_NoDup_pre. solve_NoDup_pre'. solve_NoDup_pre'' 6 9. destruct eq as [-> | ->]. solve_NoDup_pre'' 2 9. solve_NoDup_pre'' 3 9. } subst P. iEval (rewrite big_opM_insert_delete) in "excl". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_tx2 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. solve_NoDup_pre. destruct contra as [-> | ->]. solve_NoDup_pre'' 2 6. solve_NoDup_pre'' 3 6. } subst P. iEval (rewrite big_opM_insert_delete) in "excl". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_prog2 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. rewrite !elem_of_singleton. intros ->. solve_NoDup_pre'' 2 3. } subst P. iEval (rewrite big_sepM_singleton) in "excl". iDestruct "excl" as "(excl1 & excl2 & excl3 & excl4 & excl5 & excl6)". iDestruct (big_sepM_subseteq _ (get_own_gmap σ) {[p_rx0 := None; p_rx1 := None; p_rx2 := None; p_tx2 := None; p_prog2 := Some V2; p_share := Some V0]} with "Hown") as "own"; eauto. { apply own_layout_get_own_gmap. assumption. } iEval (rewrite big_opM_insert_delete) in "own". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_rx0 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. solve_NoDup_pre. solve_NoDup_pre'. solve_NoDup_pre'' 7 8. solve_NoDup 7. } subst P. iEval (rewrite big_opM_insert_delete) in "own". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_rx1 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. solve_NoDup_pre. solve_NoDup_pre'. solve_NoDup_pre'' 8 9. solve_NoDup 8. } subst P. iEval (rewrite big_opM_insert_delete) in "own". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_rx2 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. solve_NoDup_pre. solve_NoDup_pre'. solve_NoDup_pre'' 6 9. solve_NoDup 9. } subst P. iEval (rewrite big_opM_insert_delete) in "own". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_tx2 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. solve_NoDup 6. } subst P. iEval (rewrite big_opM_insert_delete) in "own". match goal with | |- context G [delete _ ?p] => set P := p end. assert (delete p_prog2 P = P) as ->. { subst P. apply delete_notin. rewrite <-not_elem_of_dom. rewrite !dom_insert_L. rewrite dom_empty_L. rewrite union_empty_r. solve_NoDup 3. } subst P. iEval (rewrite big_sepM_singleton) in "own". iDestruct "own" as "(own1 & own2 & own3 & own4 & own5 & own6)". iDestruct (ghost_map_elem_persist with "mb0TX") as ">mb0TX". iDestruct (ghost_map_elem_persist with "mb1TX") as ">mb1TX". iDestruct (ghost_map_elem_persist with "mb2TX") as ">mb2TX". iDestruct (ghost_map_elem_persist with "mb0RX") as ">mb0RX". iDestruct (ghost_map_elem_persist with "mb1RX") as ">mb1RX". iDestruct (ghost_map_elem_persist with "mb2RX") as ">mb2RX". iModIntro. (* allocate VMProps *) set pgt := (get_page_table σ). iExists [True%I; (R0 @@ V0 ->r run_I ∗ R1 @@ V0 ->r encode_vmid V1 ∗ addr ->a two ∗ (∃ (wh : Addr), (∃ (β : lang.mem), wh ->t (V0, V1, {[p_share]}, Sharing) ∗ wh ->re false ∗ RX_state@V1 := Some (of_imm one, V0) ∗ RX@V1:=p_rx1 ∗ memory_page p_rx1 β ∗ ⌜β !! (of_imm i_prx1) = Some wh⌝) ∗ VMProp V0 ((R0 @@ V0 ->r yield_I ∗ R1 @@ V0 ->r encode_vmid V1 ∗ addr ->a four ∗ wh ->t (V0, V1, {[p_share]}, Sharing) ∗ RX@V1:=p_rx1 ∗ RX_state@V1 := None ∗ (∃ mem_rx, memory_page p_rx1 mem_rx)) ∗ VMProp V1 False%I (1/2)%Qp) (1/2)%Qp))%I; (vmprop_unknown V2 mtms_slice_trans mtms_slice_rxs ∅)]. iSimpl. iSplit; first done. (* frame state_interp *) iSplitL "Hσmem Hσreg Hσaccess Hσown Hσexcl Hσrxs Hσmb Hσhpool Hσtrans Hσretri". iFrame. rewrite /inv_trans_wellformed /inv_trans_wellformed'. rewrite /inv_trans_pgt_consistent /inv_trans_pgt_consistent'. rewrite Htrans. repeat iSplit. done. { rewrite /inv_trans_pg_num_ub. iPureIntro. rewrite map_Forall_singleton //. } { rewrite /inv_trans_sndr_rcvr_neq. iPureIntro. rewrite map_Forall_singleton //. } { rewrite /inv_finite_handles. iPureIntro. rewrite dom_singleton_L //. } { iPureIntro. rewrite /inv_trans_ps_disj /inv_trans_ps_disj'. rewrite Htrans. rewrite map_Forall_singleton //. } { iPureIntro. rewrite map_Forall_singleton //. } iIntros "(VMProp0 & VMProp1 & VMProp2 & _)". rewrite /scheduled /machine.scheduler /= /scheduler Hcur /=. iDestruct (VMProp_split with "VMProp1") as "[VMProp1_half VMProp1_half']". iDestruct (VMProp_split with "VMProp2") as "[VMProp2_half VMProp2_half']". pose proof (@access_split mtms_vmconfig irisΣ VMG 1 V2) as Hsplit. rewrite access_mapsto_eq /access_mapsto_def in Hsplit. (* iDestruct "access3" as "(access3 & access3')". *) iAssert ((V2, RX) ↪[ mb_gname ]□ p_rx2 ∗ (V2, RX) ↪[ mb_gname ]□ p_rx2)%I with "[mb2RX]" as "(mb2RX & mb2RX')". { iDestruct "mb2RX" as "#mb2RX". iFrame "mb2RX". } iSplitL "PCz R0z R1z R2z R3z R4z R5z mem_p_prog0 p_tx0 mem_p Hp VMProp0 VMProp1_half' VMProp2_half' mb0RX mb1RX RX0St RX1St RX2St p_rx0 p_rx1 p_rx2 mb0TX mb2RX access1 excl1 excl2 excl6 own1 own2 own6". iIntros "_". iApply (wp_mono _ _ _ (λ m, ⌜m = HaltI⌝ ∗ addr ->a four ∗ V0 -@A> {[p_share; p_prog0; p_tx0]} ∗ TX@V0:=p_tx0 ∗ PC @@ V0 ->r ((of_pid p_prog0) ^+ (length (mtms_program0 addr i_ptx0)))%f)%I). intros. iIntros "[$ _]". iApply (mtms_machine0 p_prog0 p_prog1 p_prog2 p_tx0 p_rx0 p_tx1 p_rx1 p_tx2 p_rx2 p_share Hps_nd with "[-]"). { exact Heq_pshare. } assumption. exact Heq_prx1. program_in_seq. iSplitL "mem_p_prog0". { unfold program. iEval (rewrite big_opM_map_to_list) in "mem_p_prog0". rewrite big_sepL2_alt. iSplitR "mem_p_prog0". { simpl. by iPureIntro. } { rewrite mem_mapsto_eq /mem_mapsto_def. assert (mem_p_prog0 ⊆ σ.1.2) as Hsubseteq. { rewrite Hunion_mem'. apply map_union_subseteq_r'. assumption. apply map_union_subseteq_r'. assumption. done. } iApply (memory_list_gmap p_prog0 (mtms_program0 addr i_ptx0) _ mem_p_prog0 with "mem_p_prog0"). - rewrite fst_zip. + apply finz_seq_NoDup'. simpl. pose proof (last_addr_in_bound p_prog0). solve_finz. + simpl. lia. - apply HmemH1; done. } } iSplitL "mem_p". { rewrite mem_mapsto_eq /mem_mapsto_def. assert (mem ⊆ σ.1.2) as Hsubseteq. { rewrite Hunion_mem'. apply map_union_subseteq_r'. assumption. apply map_union_subseteq_l'. apply map_union_subseteq_l'. apply map_union_subseteq_r'. assumption. done. } assert (of_imm addr ∈ set_of_addr {[p_share]}) as H. { apply elem_of_set_of_addr with (p_share). rewrite -Heq_pshare. apply elem_of_addr_of_page_iff. rewrite to_pid_aligned_eq //. set_solver +. } rewrite <-Hdom_mem_p in H. rewrite elem_of_dom in H. destruct H as [waddr Hwaddr]. iDestruct (big_sepM_delete _ mem addr waddr with "mem_p") as "(mem & memacc)". assumption. iExists waddr. iFrame. } iSplitL "p_tx0". { unfold memory_page. iExists mem_p_tx0. iSplit. rewrite Hdom_mem_p_tx0. iPureIntro. rewrite set_of_addr_singleton //. rewrite mem_mapsto_eq /mem_mapsto_def /=. iFrame. } rewrite rx_state_mapsto_eq /rx_state_mapsto_def /=. iFrame "RX0St RX1St RX2St". unfold rx_page. rewrite mb_mapsto_eq /mb_mapsto_def /=. iFrame "mb0TX". iFrame "PCz". rewrite access_mapsto_eq /access_mapsto_def /=. rewrite big_sepS_singleton. iSplitL "excl6 own6". { rewrite excl_mapsto_eq own_mapsto_eq /excl_mapsto_def /own_mapsto_def /=. iFrame. } iSplitL "access1". { rewrite /to_frac_agree. iFrame. } iSplitL "R0z". iExists r0_; iFrame. iSplitL "R1z". iExists r1_; iFrame. iSplitL "R2z". iExists r2_; iFrame. iSplitL "R3z". iExists r3_; iFrame. iSplitL "R4z". iExists r4_; iFrame. iSplitL "R5z". iExists r5_; iFrame. iFrame "VMProp0". iFrame "VMProp1_half'". iFrame "VMProp2_half'". iFrame "Hp". iFrame. iSplitL "p_rx0 excl1 own1". iSplitR "p_rx0". rewrite excl_mapsto_eq own_mapsto_eq /excl_mapsto_def /own_mapsto_def /=. iFrame. unfold memory_page. iExists mem_p_rx0. iSplit. rewrite Hdom_mem_p_rx0. iPureIntro. apply set_of_addr_singleton. rewrite mem_mapsto_eq /mem_mapsto_def /=. iFrame "p_rx0". iSplitL "p_rx1 excl2 own2". iExists mem_p_rx1. iSplit. rewrite Hdom_mem_p_rx1. iPureIntro. apply set_of_addr_singleton. rewrite mem_mapsto_eq /mem_mapsto_def /=. iFrame "p_rx1". unfold memory_page. iExists mem_p_rx2. iSplit. rewrite Hdom_mem_p_rx2. iPureIntro. apply set_of_addr_singleton. rewrite mem_mapsto_eq /mem_mapsto_def /=. iFrame "p_rx2". iSplitL "VMProp1_half PC1 R01 R11 R21 R31 R41 R51 mem_p_prog1 p_tx1 mb1TX access2". iAssert ((VMProp_holds V1 (1 / 2) -∗ WP ExecI @ V1 {{ _, False }}) -∗ VMProp_holds 1 (1 / 2) -∗ WP ExecI @ 1 {{ _, False }})%I as "WP". { iIntros "H". simpl. iApply "H". } iApply "WP". iApply (mtms_machine1 p_prog0 p_prog1 p_prog2 p_tx0 p_rx0 p_tx1 p_rx1 p_tx2 p_rx2 p_share Hps_nd with "[-]"). { exact Heq_pshare. } { exact Heq_prx1. } { program_in_seq. } iSplitL "mem_p_prog1". unfold program. iEval (rewrite big_opM_map_to_list) in "mem_p_prog1". rewrite big_sepL2_alt. iSplit; first done. rewrite mem_mapsto_eq /mem_mapsto_def. { assert (mem_p_prog1 ⊆ σ.1.2) as Hsubseteq. { rewrite Hunion_mem'. apply map_union_subseteq_r'. assumption. apply map_union_subseteq_l'. apply map_union_subseteq_r'. assumption. done. } iApply (memory_list_gmap _ _ _ mem_p_prog1). - rewrite fst_zip. + apply finz_seq_NoDup'. simpl. pose proof (last_addr_in_bound p_prog1). solve_finz. + simpl. lia. - apply HmemH2; done. - by iFrame. } iSplitL "p_tx1". { unfold memory_page. iExists mem_p_tx1. iSplit. rewrite Hdom_mem_p_tx1. iPureIntro. rewrite set_of_addr_singleton //. rewrite mem_mapsto_eq /mem_mapsto_def /=. iFrame. } iSplitL "access2". { rewrite access_mapsto_eq /access_mapsto_def. simpl. iFrame "access2". } iSplitL "mb1TX". { rewrite mb_mapsto_eq /mb_mapsto_def /=. iFrame. } iFrame "PC1". iSplitL "R01". iExists r0__. iFrame. iSplitL "R11". iExists r1__. iFrame. iSplitL "R21". iExists r2__. iFrame. iSplitL "R31". iExists r3__. iFrame. iSplitL "R41". iExists r4__. iFrame. iSplitL "R51". iExists r5__. iFrame. iFrame "VMProp1_half". iSplitR ""; last done. iAssert ((VMProp_holds V2 (1 / 2) -∗ WP ExecI @ V2 {{ _, True }}) -∗ VMProp_holds 2 (1 / 2) -∗ WP ExecI @ 2 {{ _, True }})%I as "WP". { iIntros "H". simpl. iApply "H". } iApply "WP". iApply (mtms_ftlr2 p_prog2 p_tx2 p_rx2 with "[-] []"). 2: { iPureIntro. cbn. done. } rewrite /mtms_interp_access2 /interp_access. repeat (iSplit;[iPureIntro|]). { rewrite /mtms_slice_trans. intros ? ? ? [|]; done. } { rewrite /mtms_slice_rxs. intros ?. destruct os;done. } { rewrite /mtms_slice_rxs. intros ?. destruct os;done. } { rewrite /mtms_slice_rxs. intros ??. destruct os. destruct p. intros. done. done. } { intros. rewrite /mtms_slice_rxs //. } iSplitL "Hreg2". iExists (get_reg_files σ !!! V2). unfold get_reg_gmap_vm. iSplit. iPureIntro. unfold base_extra.is_total_gmap. apply Htotal_reg. simpl. { set g := (λ p0 : reg_name * Addr, (p0.1, 2%fin, p0.2)). unfold V2. simpl. set l := (σ.1.1.1.1.1 !!! 2%fin). iEval (rewrite big_opM_map_to_list) in "Hreg2". rewrite map_to_list_to_map. rewrite big_opL_fmap. subst g. simpl. rewrite big_opM_map_to_list. iFrame "Hreg2". subst g. apply NoDup_fmap_fst. intros [x1 x2] y1 y2 Hh Hh'. rewrite elem_of_list_In in Hh. rewrite elem_of_list_In in Hh'. rewrite in_map_iff in Hh. rewrite in_map_iff in Hh'. destruct Hh as [(x & x') [Hheq Hh]]. destruct Hh' as [(t & t') [Hh'eq Hh']]. simpl in Hheq. simpl in Hh'eq. inversion Hheq. inversion Hh'eq. simplify_eq. clear Hheq Hh'eq. rewrite <-elem_of_list_In in Hh. rewrite <-elem_of_list_In in Hh'. apply map_to_list_unique with l x1; auto. apply NoDup_fmap_2. intros a b abeq. inversion abeq. destruct a, b; simpl in *. by simplify_eq. apply NoDup_map_to_list. } iFrame "VMProp2_half". rewrite difference_empty_L. unfold transaction_pagetable_entries_owned. unfold retrieved_transaction_owned. rewrite -!big_sepFM_empty. assert (({[p_prog2; p_tx2; p_rx2]} ∖ {[p_rx2; p_tx2]}) = {[p_prog2]}) as ->. { rewrite !difference_union_distr_l_L. rewrite difference_disjoint_L. assert ({[p_tx2]} ∖ {[p_rx2; p_tx2]} = ∅) as ->. { set_solver +. } assert ({[p_rx2]} ∖ {[p_rx2; p_tx2]} = ∅) as ->. { set_solver +. } set_solver +. apply disjoint_singleton_l. intros contra. rewrite elem_of_union in contra. rewrite !elem_of_singleton in contra. solve_NoDup_pre'. solve_NoDup_pre'' 2 9. solve_NoDup_pre'' 2 6. } unfold pagetable_entries_excl_owned. unfold logrel.pgt. rewrite !big_sepS_singleton. unfold tx_page. iSplitL "mb2TX p_tx2 excl4 own4". iSplitR "p_tx2". rewrite mb_mapsto_eq /mb_mapsto_def. rewrite excl_mapsto_eq own_mapsto_eq /excl_mapsto_def /own_mapsto_def. iFrame. iExists mem_p_tx2. unfold memory_page. iSplit. iPureIntro. rewrite Hdom_mem_p_tx2. apply set_of_addr_singleton. rewrite mem_mapsto_eq /mem_mapsto_def. iFrame "p_tx2". rewrite access_mapsto_eq /access_mapsto_def /=. assert ({[p_tx2; p_rx2; p_prog2]} = {[p_prog2; p_tx2; p_rx2]}) as -> by set_solver +. iFrame "access3". unfold rx_page. iSplitL "mb2RX' excl3 own3". { rewrite excl_mapsto_eq /excl_mapsto_def. rewrite own_mapsto_eq /own_mapsto_def. rewrite mb_mapsto_eq /mb_mapsto_def. iFrame. } iSplit. iPureIntro. set_solver +. iSplit. iPureIntro. set_solver +. iSplitL "excl5 own5". { rewrite excl_mapsto_eq /excl_mapsto_def. rewrite own_mapsto_eq /own_mapsto_def. iFrame. } iSplit; first done. iSplit; first done. iExists mem5. unfold memory_pages. iSplit. iPureIntro. rewrite /retrieved_lending_memory_pages. rewrite map_filter_empty pages_in_trans_empty union_empty_r_L //. rewrite mem_mapsto_eq /mem_mapsto_def. iFrame "Hmem2". Qed. End mtms_adequacy.
[GOAL] ⊢ Denumerable ℚ [PROOFSTEP] let T := { x : ℤ × ℕ // 0 < x.2 ∧ x.1.natAbs.coprime x.2 } [GOAL] T : Type := { x // 0 < x.snd ∧ Nat.coprime (Int.natAbs x.fst) x.snd } ⊢ Denumerable ℚ [PROOFSTEP] letI : Infinite T := Infinite.of_injective _ denumerable_aux.injective [GOAL] T : Type := { x // 0 < x.snd ∧ Nat.coprime (Int.natAbs x.fst) x.snd } this : Infinite T := Infinite.of_injective (↑Rat.denumerable_aux) (Equiv.injective Rat.denumerable_aux) ⊢ Denumerable ℚ [PROOFSTEP] letI : Encodable T := Subtype.encodable [GOAL] T : Type := { x // 0 < x.snd ∧ Nat.coprime (Int.natAbs x.fst) x.snd } this✝ : Infinite T := Infinite.of_injective (↑Rat.denumerable_aux) (Equiv.injective Rat.denumerable_aux) this : Encodable T := Subtype.encodable ⊢ Denumerable ℚ [PROOFSTEP] letI : Denumerable T := ofEncodableOfInfinite T [GOAL] T : Type := { x // 0 < x.snd ∧ Nat.coprime (Int.natAbs x.fst) x.snd } this✝¹ : Infinite T := Infinite.of_injective (↑Rat.denumerable_aux) (Equiv.injective Rat.denumerable_aux) this✝ : Encodable T := Subtype.encodable this : Denumerable T := ofEncodableOfInfinite T ⊢ Denumerable ℚ [PROOFSTEP] exact Denumerable.ofEquiv T denumerable_aux [GOAL] ⊢ #ℚ = ℵ₀ [PROOFSTEP] simp only [mk_eq_aleph0]
[STATEMENT] theorem lfinite_less_induct[consumes 1, case_names less]: assumes fin: "lfinite xs" and step: "\<And>xs. lfinite xs \<Longrightarrow> (\<And>zs. llength zs < llength xs \<Longrightarrow> P zs) \<Longrightarrow> P xs" shows "P xs" [PROOF STATE] proof (prove) goal (1 subgoal): 1. P xs [PROOF STEP] using fin [PROOF STATE] proof (prove) using this: lfinite xs goal (1 subgoal): 1. P xs [PROOF STEP] proof (induct "the_enat (llength xs)" arbitrary: xs rule: less_induct) [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>xs. \<lbrakk>\<And>xsa. \<lbrakk>the_enat (llength xsa) < the_enat (llength xs); lfinite xsa\<rbrakk> \<Longrightarrow> P xsa; lfinite xs\<rbrakk> \<Longrightarrow> P xs [PROOF STEP] case (less xs) [PROOF STATE] proof (state) this: \<lbrakk>the_enat (llength ?xs) < the_enat (llength xs); lfinite ?xs\<rbrakk> \<Longrightarrow> P ?xs lfinite xs goal (1 subgoal): 1. \<And>xs. \<lbrakk>\<And>xsa. \<lbrakk>the_enat (llength xsa) < the_enat (llength xs); lfinite xsa\<rbrakk> \<Longrightarrow> P xsa; lfinite xs\<rbrakk> \<Longrightarrow> P xs [PROOF STEP] show ?case [PROOF STATE] proof (prove) goal (1 subgoal): 1. P xs [PROOF STEP] using less(2) [PROOF STATE] proof (prove) using this: lfinite xs goal (1 subgoal): 1. P xs [PROOF STEP] by (intro step[OF less(2)] less(1)) (auto dest!: lfinite_llength_enat simp: eSuc_enat elim!: less_enatE llength_eq_enat_lfiniteD) [PROOF STATE] proof (state) this: P xs goal: No subgoals! [PROOF STEP] qed
lemma connected_component_refl_eq [simp]: "connected_component S x x \<longleftrightarrow> x \<in> S"
Are Experiential Therapy Techniques Helpful? What Is Animal-Assisted Therapy & How Does It Work? Substance abuse recovery involves much more than clearing drugs or alcohol from the body. Overcoming the disease of addiction requires an understanding of the origins of substance abuse, the motivating factors for recovery, and the reasons for resistance to healing. Art therapy serves as a vehicle for the psychological component of recovery by providing an emotional outlet and a means of self-expression. Feelings or experiences that are too painful or shameful to articulate can be expressed through ink, paint, clay, or other media. When combined with other recovery services, such as detox, individual therapy, support groups, and family counseling, art therapy can be a powerful way to promote the healing process. Art therapy is a form of experiential therapy, an approach to recovery that addresses emotional and spiritual needs through creative or physical activity. It is not necessary to have a background in the arts or artistic talent to participate; individuals only need to be open to the experience and to engage actively to benefit from these sessions. Many clients find that art therapy is a relaxing and enjoyable way to address some of the more complex aspects of rehab. Creative activity provides a way to process some of the stressful emotions and anxieties that can emerge during treatment. After rehab, activities like painting or drawing, can be used throughout the individual’s life as a way to express feelings, explore creativity, and reduce stress. One of the primary goals of art therapy is to help the client return to healthy functioning, whether that be on a social, emotional, or cognitive level. It can be particularly useful in the treatment of individuals who have experienced personal trauma, such as childhood abuse, sexual assault, violence, or a natural disaster. Memories and experiences that are too powerful to confront directly can be explored through the vehicle of visual media, allowing the release of tension and fear in a safe environment. Creative activity gives the individual in recovery a sense of control that may be lacking in life. In this sense, art can become a coping strategy for dealing with the challenges of recovery. On a social level, art therapy sessions can serve as a form of group therapy, creating bonds among peers. As clients work together on guided projects, they can learn new methods of coping, share their responses to therapy, and practice their collaborative skills. On a more general level, art therapy can act as an introduction to the pleasures of creative activity. Art therapy is practiced in a wide range of settings, from community mental health centers to inpatient psychiatric units, medical facilities, schools, and residential recovery centers. This versatile treatment modality can be applied in almost any therapeutic context, from individual therapy to group sessions and family or marriage counseling. A study of art therapy programs in substance abuse treatment published in the Journal of Addictions Nursingfound that 36.8 percent of programs in the study sample offered art therapy as part of a comprehensive rehab program. This study also found that art therapy was particularly successful when combined with therapies that focus on motivating the client and encouraging active participation. One such modality is Motivational Enhancement Therapy (MET), an approach that brings the therapist and client together in a collaborative relationship to stop substance abuse. Art Therapy: Journal of the American Art Therapy Association notes that art therapy can be very effective at breaking down resistance to treatment and overcoming ambivalence about recovery in rehab clients. Many individuals who enter recover programs are living with the residual effects of traumatic experiences, from past abuse to recent violence or loss. For the survivors of trauma, substance abuse can be used as a dysfunctional coping mechanism to manage unbearable feelings of grief, rage, or guilt. According to Psychology Today, art therapy has been used successfully as a healing intervention for children who have survived the trauma of war. The act of creating images and objects with paint, clay, chalk, or crayons is itself a therapeutic process for these children, as well as a way to depict the unspeakable acts that they have seen. By the same token, adults who have lived through domestic violence, natural disasters, violent crimes, or acts of terrorism can use art to express their responses to these incidents in a safe, supportive context. In veterans and other individuals who have used drugs or alcohol to cope with trauma, art can bring about an understanding of the nature of addiction as a disease. It can also be used to reinforce the individual’s commitment to recovery, to promote self-reflection, and to provide an experience of spirituality, notes AATA.The benefits of art therapy are available to individuals from all socioeconomic backgrounds, regardless of their financial resources. Artists for Trauma, a nonprofit organization, uses the creative arts as a tool to help military and civilian survivors overcome the effects of traumatic events and live healthy, fulfilling lives. This organization matches professional artists in the community with individuals in need of trauma therapy. These artists work on a volunteer basis to provide and facilitate free, interactive programs that help to facilitate the recovery process. Programs are offered in hospitals, military facilities, community centers, and other locations. How Does Art Therapy Support Substance Abuse Treatment? Art therapy is a component of a comprehensive treatment program that includes individual therapy, group therapy, family counseling, 12-Step meetings, and other core services. Art therapy complements these services by providing a break from the direct, intensive work of talk therapy and allowing the subconscious to express itself creatively. Art therapy can be a powerful complement to a 12-Step program. According to Art Therapy: Journal of the American Art Therapy Association, clients can use artistic activities to uncover the feelings of guilt, unmanageability, or shame that led them to rehab. For instance, a process known as incident drawings allows clients to illustrate the experiences of feeling self-destructive or out of control, which can lead them to seek healing through a higher power. Therapists often use fluid media, like paint, to help clients experience the sensation of being out of control, which in turn helps them admit their need for sobriety. Art therapy highlights the role of creative activity as a form of nonverbal communication. Language is not always the most effective way to convey the emotions that are uncovered in the recovery process. Art therapy can act as a powerful complement to traditional talk therapy by giving clients an alternative way to describe and communicate their feelings. Once these feelings have been released, art provides a visible, tangible object that can be discussed with the therapist and with peers in a group setting. Throughout the course of a recovery program, the images that clients choose and the feelings that they express may change. Clients who are more advanced in the program may use art to depict the process of transformation that occurs in recovery. After illustrating feelings of shame or guilt, they may feel compelled to express the joy of being released from addiction. Art therapy sessions are integrated into the client’s schedule of recovery activities at a residential treatment program. Depending on the structure of these sessions, clients may either create art pieces independently or work collaboratively on a single project or design. The sessions are facilitated by an art therapist, a professional trained in using art as a medium for recovery and healing. The art therapist guides clients in exploring the underlying emotions, experiences, or memories that arise during the creative process. In order to effectively lead an art therapy session, the therapist should have at least a master’s degree in therapy or counseling, as well as specialized training in this treatment modality. Many art therapists also hold licensure in social work, therapy, or family and marriage counseling. Standards of practice are established by the American Art Therapy Association, a national organization that promotes knowledge of the field and provides educational resources for therapists and the general public. To supplement the role of art, music, or fitness therapies, a comprehensive recovery program will offer services that address the whole person, such as recreational outings, nutritional counseling, and activities that foster spiritual growth. When searching for a recovery program, look for a facility that is open to the integration of cognitive therapies, behavioral modification, and motivational counseling with expressive and experiential modalities. American Art Therapy Association (AATA): This national organization is the authoritative resource in this field, providing educational information for the public and providers, professional certification for art therapists, and support services using the medium of art. Artists for Trauma: Through the efforts of artists who volunteer their time and resources, Artists for Trauma helps civilians and members of the military overcome the effects of trauma through the healing mechanisms of creative expression. Artists for Trauma provides therapeutic sessions on an individual or group basis to individuals seeking recovery from devastating or life-threatening experiences. International Expressive Arts Therapy Association (IEATA): This charitable organization advocates and promotes the use of art as a healing modality around the world. IEATA uses the expressive arts to effect change on a personal and community level. It also establishes standards of practice for the field of art therapy. National Coalition of Creative Arts Therapies Associations (NCCATA): This group is an association of organizations committed to the advancement of art as a therapeutic modality. NCCATA supports professional therapists who are using the arts — including the visual arts, dancing, music, poetry, and other expressive modalities — to promote healing, foster communication, and restore mental health. Trauma-Informed Practices and Expressive Arts Therapy Institute & Learning Center: This institute is dedicated to teaching therapists and other professionals the practice of art therapy as a way to overcome the effects of trauma. Based on the treatment practice known as trauma-informed art therapy, the Institute offers live and online training courses, a certification program, and other valuable resources for mental health workers and graduate students.
import Mathlib /-! # Useful helpers Contains the actual category class `Cat`. -/ /-! ## Constant combinator -/ abbrev 𝕂 {α : Sort u} {β : Sort v} (val : β) : α → β := fun _ => val /-! ## Defining categories -/ --- A category with objects of type `Object`. @[reducible] class Cat (Object : Sort o) (OSem : outParam (Object → Sort osem)) (Arrow : Object → Object → Sort a) (ASem : outParam (Object → Object → Sort asem)) where --- Arrow composition. compose {α β γ} : Arrow β γ → Arrow α β → Arrow α γ --- Arrow concretization. aConcrete : (A : Arrow α β) → ASem α β -- aConcrete_distributive -- {α β γ} -- (f : Arrow β γ) -- (g : Arrow α β) -- : aConcrete (compose f g) = compose (aConcrete f) (aConcrete g) --- Arrow composition is associative. compose_assoc {α β γ δ} (f : Arrow γ δ) (g : Arrow β γ) (h : Arrow α β) : aConcrete (compose f (compose g h)) = aConcrete (compose (compose f g) h) --- Identity, careful not to shadow `id`. protected id {α : outParam Object} : Arrow α α --- `id ∘ f` is `f`. id_compose (f : Arrow α β) : aConcrete (compose id f) = aConcrete f --- `f ∘ id` is `f`. compose_id (f : Arrow α β) : aConcrete (compose f id) = aConcrete f class Cat.Abstract (Object : Sort o) (Arrow : Object → Object → Sort a) extends Cat Object (𝕂 Object) Arrow Arrow where aConcrete a := a --- Nice notation for `Cat.Arrow`, enter `\r=`. infixr:80 " ⇒ " => Cat.Arrow --- Usual function composition. infixr:80 " ∘c " => Cat.compose --- Category **0** with no objects and no arrows. def Cat.zero : Cat.Abstract Empty (fun _ _ => Unit) where id := by intros ; contradiction compose := by intros ; contradiction compose_assoc := by intros ; contradiction id_compose := by intros ; contradiction compose_id := by intros ; contradiction --- Category **1** with one object and its identity arrow. def Cat.one : Cat.Abstract Unit (fun _ _ => Unit) where compose _ _ := () compose_assoc _ _ _ := rfl id := () id_compose _ := rfl compose_id _ := rfl --- Empty structure that stores two booleans as type parameters. --- --- This is going to be the arrow for category `Cat.two`. @[reducible] structure Cat.two.Arrow (b₁ b₂ : Bool) --- Category **2** with two objects, two identity arrows, and an arrow from one object to the other. def Cat.two : Cat.Abstract Bool two.Arrow where compose _ _ := {} compose_assoc _ _ _ := rfl id := {} id_compose _ := rfl compose_id _ := rfl --- Objects of the category **3**. inductive Cat.three.Object | A | B | C --- Arrows of the category **3**. structure Cat.three.Arrow (o₁ o₂ : Cat.three.Object) --- Category **3** with three objects `A`, `B` and `C`. --- --- Besides the three identity arrows, we have `A → B`, `B → C`, and `C → A`. def Cat.three : Cat.Abstract three.Object three.Arrow where compose _ _ := {} compose_assoc _ _ _ := rfl id := {} id_compose _ := rfl compose_id _ := rfl --- Dual of a category. instance Cat.Abstract.dual (cat : Cat.Abstract Object Arrow) : Cat.Abstract Object (fun α β => Arrow β α) where compose f g := cat.compose g f compose_assoc f g h := by simp rw [cat.compose_assoc h g f] id := cat.id id_compose := cat.compose_id compose_id := cat.id_compose --- Applying `Dual` two times yields the original. theorem Cat.Abstract.dual_dual (cat : Cat.Abstract Object Arrow) : cat.dual.dual = cat := rfl instance Cat.Prod (cat₁ : Cat O₁ OSem₁ A₁ ASem₁) (cat₂ : Cat O₂ OSem₂ A₂ ASem₂) : Cat (PProd O₁ O₂) (fun ⟨o₁, o₂⟩ => OSem₁ o₁ × OSem₂ o₂) (fun ⟨α₁, α₂⟩ ⟨β₁, β₂⟩ => PProd (A₁ α₁ β₁) (A₂ α₂ β₂)) (fun ⟨α₁, α₂⟩ ⟨β₁, β₂⟩ => PProd (ASem₁ α₁ β₁) (ASem₂ α₂ β₂)) where aConcrete a := ⟨cat₁.aConcrete a.1, cat₂.aConcrete a.2⟩ compose f g := ⟨cat₁.compose f.1 g.1, cat₂.compose f.2 g.2⟩ compose_assoc {α β γ δ} f g h := let res : _ ∧ _ := ⟨cat₁.compose_assoc f.1 g.1 h.1, cat₂.compose_assoc f.2 g.2 h.2⟩ by simp [res] id := ⟨cat₁.id, cat₂.id⟩ id_compose f := let res : _ ∧ _ := ⟨cat₁.id_compose f.1, cat₂.id_compose f.2⟩ by simp [res] compose_id f := let res : _ ∧ _ := ⟨cat₁.compose_id f.1, cat₂.compose_id f.2⟩ by simp [res] namespace Cat.UpArrow universe o osem a asem variable {Object : Sort o} {ASem : Object → Object → Sort asem} (A : Object → Object → Sort a) inductive Obj (A : Object → Object → Sort a) : Sort (max 1 o a) | mk : A α β → Obj A def Obj.dom : Obj A → Object | @Obj.mk _ _ α _β _ => α def Obj.cod : Obj A → Object | @Obj.mk _ _ _α β _ => β def Obj.get : Obj A → ((α : Object) ×' (β : Object) ×' A α β) | @Obj.mk _ _ α β a => ⟨α, β, a⟩ def Obj.getFun : (self : Obj A) → A self.dom self.cod | @Obj.mk _ _ _α _β a => a def Obj.Concrete (ASem : Object → Object → Sort asem) (self : Obj A) : Sort asem := ASem self.dom self.cod variable {OSem : Object → Sort osem} (cat : Cat Object OSem A ASem) structure Arrow (α β : Obj A) : Sort (max 1 o a) where a : A α.dom β.dom b : A α.cod β.cod legal : let f := α.getFun let f' := β.getFun cat.compose f' a = cat.compose b f def Arrow.Concrete (ASem : Object → Object → Sort asem) (α β : Obj A) : Sort asem := ASem α.dom β.cod def Arrow.concrete (self : Arrow A (cat := cat) α β) : ASem α.dom β.cod := let a := self.a (cat := cat) let f' := β.getFun cat.compose f' a |> cat.aConcrete def Arrow.compose {α β γ} (f : Arrow A cat β γ) (g : Arrow A cat α β) : Arrow A cat α γ where a := cat.compose f.a g.a b := cat.compose f.b g.b legal := let legal_f := f.legal let legal_g := g.legal by simp at legal_f simp at legal_g simp sorry end Cat.UpArrow /-- Given `cat`, builds `cat⟶` (upperscript arrow, dunno how to unicode it). -/ instance Cat.UpArrow [cat : Cat O OSem A ASem] : Cat (UpArrow.Obj A) (UpArrow.Obj.Concrete A ASem) (UpArrow.Arrow A cat) (UpArrow.Arrow.Concrete A ASem) where aConcrete := UpArrow.Arrow.concrete A cat compose := by sorry compose_assoc := by sorry id := by sorry id_compose := by sorry compose_id := by sorry
State Before: α : Type u β : Type v γ : Type w S T : WSeq (WSeq α) ⊢ join (append S T) ~ʷ append (join S) (join T) State After: α : Type u β : Type v γ : Type w S T : WSeq (WSeq α) ⊢ ∀ {s t : WSeq α}, (fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) s t → Computation.LiftRel (LiftRelO (fun x x_1 => x = x_1) fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) (destruct s) (destruct t) Tactic: refine' ⟨fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)), ⟨nil, S, T, by simp, by simp⟩, _⟩ State Before: α : Type u β : Type v γ : Type w S T : WSeq (WSeq α) ⊢ ∀ {s t : WSeq α}, (fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) s t → Computation.LiftRel (LiftRelO (fun x x_1 => x = x_1) fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) (destruct s) (destruct t) State After: α : Type u β : Type v γ : Type w S T : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) ⊢ Computation.LiftRel (LiftRelO (fun x x_1 => x = x_1) fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) (destruct s1) (destruct s2) Tactic: intro s1 s2 h State Before: α : Type u β : Type v γ : Type w S T : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) ⊢ Computation.LiftRel (LiftRelO (fun x x_1 => x = x_1) fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) (destruct s1) (destruct s2) State After: α : Type u β : Type v γ : Type w S T : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) ⊢ ∀ {ca cb : Computation (Option (α × WSeq α))}, (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) ca cb → LiftRelAux (LiftRelO (fun x x_1 => x = x_1) fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) (Computation.destruct ca) (Computation.destruct cb) Tactic: apply lift_rel_rec (fun c1 c2 => ∃ (s : WSeq α) (S T : _), c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) _ _ _ (let ⟨s, S, T, h1, h2⟩ := h ⟨s, S, T, congr_arg destruct h1, congr_arg destruct h2⟩) State Before: α : Type u β : Type v γ : Type w S T : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) ⊢ ∀ {ca cb : Computation (Option (α × WSeq α))}, (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) ca cb → LiftRelAux (LiftRelO (fun x x_1 => x = x_1) fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) (Computation.destruct ca) (Computation.destruct cb) State After: case intro.intro.intro.intro α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) s : WSeq α S T : WSeq (WSeq α) ⊢ LiftRelAux (LiftRelO (fun x x_1 => x = x_1) fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) (Computation.destruct (destruct (append s (join (append S T))))) (Computation.destruct (destruct (append s (append (join S) (join T))))) Tactic: rintro c1 c2 ⟨s, S, T, rfl, rfl⟩ State Before: case intro.intro.intro.intro α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) s : WSeq α S T : WSeq (WSeq α) ⊢ LiftRelAux (LiftRelO (fun x x_1 => x = x_1) fun s1 s2 => ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T))) (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) (Computation.destruct (destruct (append s (join (append S T))))) (Computation.destruct (destruct (append s (append (join S) (join T))))) State After: case intro.intro.intro.intro.h1 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) S T : WSeq (WSeq α) ⊢ LiftRelAux (fun x x_1 => match x, x_1 with | none, none => True | some (a, s), some (b, t) => a = b ∧ ∃ s_1 S T, s = append s_1 (join (append S T)) ∧ t = append s_1 (append (join S) (join T)) | x, x_2 => False) (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) (Computation.destruct (destruct (join (append S T)))) (Computation.destruct (destruct (append (join S) (join T)))) case intro.intro.intro.intro.h2 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) S T : WSeq (WSeq α) a : α s : WSeq α ⊢ ∃ s_1 S_1 T_1, append s (join (append S T)) = append s_1 (join (append S_1 T_1)) ∧ append s (append (join S) (join T)) = append s_1 (append (join S_1) (join T_1)) case intro.intro.intro.intro.h3 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) S T : WSeq (WSeq α) s : WSeq α ⊢ ∃ s_1 S_1 T_1, destruct (append s (join (append S T))) = destruct (append s_1 (join (append S_1 T_1))) ∧ destruct (append s (append (join S) (join T))) = destruct (append s_1 (append (join S_1) (join T_1))) Tactic: induction' s using WSeq.recOn with a s s <;> simp State Before: α : Type u β : Type v γ : Type w S T : WSeq (WSeq α) ⊢ join (append S T) = append nil (join (append S T)) State After: no goals Tactic: simp State Before: α : Type u β : Type v γ : Type w S T : WSeq (WSeq α) ⊢ append (join S) (join T) = append nil (append (join S) (join T)) State After: no goals Tactic: simp State Before: case intro.intro.intro.intro.h1 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) S T : WSeq (WSeq α) ⊢ LiftRelAux (fun x x_1 => match x, x_1 with | none, none => True | some (a, s), some (b, t) => a = b ∧ ∃ s_1 S T, s = append s_1 (join (append S T)) ∧ t = append s_1 (append (join S) (join T)) | x, x_2 => False) (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) (Computation.destruct (destruct (join (append S T)))) (Computation.destruct (destruct (append (join S) (join T)))) State After: case intro.intro.intro.intro.h1.h1 α : Type u β : Type v γ : Type w S T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) T : WSeq (WSeq α) ⊢ LiftRelAux (fun x x_1 => match x, x_1 with | none, none => True | some (a, s), some (b, t) => a = b ∧ ∃ s_1 S T, s = append s_1 (join (append S T)) ∧ t = append s_1 (append (join S) (join T)) | x, x_2 => False) (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) (Computation.destruct (destruct (join T))) (Computation.destruct (destruct (join T))) case intro.intro.intro.intro.h1.h2 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) T : WSeq (WSeq α) s : WSeq α S : WSeq (WSeq α) ⊢ ∃ s_1 S_1 T_1, destruct (append s (join (append S T))) = destruct (append s_1 (join (append S_1 T_1))) ∧ destruct (append s (append (join S) (join T))) = destruct (append s_1 (append (join S_1) (join T_1))) case intro.intro.intro.intro.h1.h3 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) T S : WSeq (WSeq α) ⊢ ∃ s S_1 T_1, destruct (join (append S T)) = destruct (append s (join (append S_1 T_1))) ∧ destruct (append (join S) (join T)) = destruct (append s (append (join S_1) (join T_1))) Tactic: induction' S using WSeq.recOn with s S S <;> simp State Before: case intro.intro.intro.intro.h1.h1 α : Type u β : Type v γ : Type w S T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) T : WSeq (WSeq α) ⊢ LiftRelAux (fun x x_1 => match x, x_1 with | none, none => True | some (a, s), some (b, t) => a = b ∧ ∃ s_1 S T, s = append s_1 (join (append S T)) ∧ t = append s_1 (append (join S) (join T)) | x, x_2 => False) (fun c1 c2 => ∃ s S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) (Computation.destruct (destruct (join T))) (Computation.destruct (destruct (join T))) State After: case intro.intro.intro.intro.h1.h1.h2 α : Type u β : Type v γ : Type w S T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) s : WSeq α T : WSeq (WSeq α) ⊢ ∃ s_1 S T_1, destruct (append s (join T)) = destruct (append s_1 (join (append S T_1))) ∧ destruct (append s (join T)) = destruct (append s_1 (append (join S) (join T_1))) case intro.intro.intro.intro.h1.h1.h3 α : Type u β : Type v γ : Type w S T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) T : WSeq (WSeq α) ⊢ ∃ s S T_1, destruct (join T) = destruct (append s (join (append S T_1))) ∧ destruct (join T) = destruct (append s (append (join S) (join T_1))) Tactic: induction' T using WSeq.recOn with s T T <;> simp State Before: case intro.intro.intro.intro.h1.h1.h2 α : Type u β : Type v γ : Type w S T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) s : WSeq α T : WSeq (WSeq α) ⊢ ∃ s_1 S T_1, destruct (append s (join T)) = destruct (append s_1 (join (append S T_1))) ∧ destruct (append s (join T)) = destruct (append s_1 (append (join S) (join T_1))) State After: no goals Tactic: refine' ⟨s, nil, T, _, _⟩ <;> simp State Before: case intro.intro.intro.intro.h1.h1.h3 α : Type u β : Type v γ : Type w S T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) T : WSeq (WSeq α) ⊢ ∃ s S T_1, destruct (join T) = destruct (append s (join (append S T_1))) ∧ destruct (join T) = destruct (append s (append (join S) (join T_1))) State After: no goals Tactic: refine' ⟨nil, nil, T, _, _⟩ <;> simp State Before: case intro.intro.intro.intro.h1.h2 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) T : WSeq (WSeq α) s : WSeq α S : WSeq (WSeq α) ⊢ ∃ s_1 S_1 T_1, destruct (append s (join (append S T))) = destruct (append s_1 (join (append S_1 T_1))) ∧ destruct (append s (append (join S) (join T))) = destruct (append s_1 (append (join S_1) (join T_1))) State After: no goals Tactic: exact ⟨s, S, T, rfl, rfl⟩ State Before: case intro.intro.intro.intro.h1.h3 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) T S : WSeq (WSeq α) ⊢ ∃ s S_1 T_1, destruct (join (append S T)) = destruct (append s (join (append S_1 T_1))) ∧ destruct (append (join S) (join T)) = destruct (append s (append (join S_1) (join T_1))) State After: no goals Tactic: refine' ⟨nil, S, T, _, _⟩ <;> simp State Before: case intro.intro.intro.intro.h2 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) S T : WSeq (WSeq α) a : α s : WSeq α ⊢ ∃ s_1 S_1 T_1, append s (join (append S T)) = append s_1 (join (append S_1 T_1)) ∧ append s (append (join S) (join T)) = append s_1 (append (join S_1) (join T_1)) State After: no goals Tactic: exact ⟨s, S, T, rfl, rfl⟩ State Before: case intro.intro.intro.intro.h3 α : Type u β : Type v γ : Type w S✝ T✝ : WSeq (WSeq α) s1 s2 : WSeq α h : ∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)) S T : WSeq (WSeq α) s : WSeq α ⊢ ∃ s_1 S_1 T_1, destruct (append s (join (append S T))) = destruct (append s_1 (join (append S_1 T_1))) ∧ destruct (append s (append (join S) (join T))) = destruct (append s_1 (append (join S_1) (join T_1))) State After: no goals Tactic: exact ⟨s, S, T, rfl, rfl⟩
lemma isCont_swap[continuous_intros]: "isCont prod.swap a"
module Bad3 badExpr : () badExpr (whatever : ())
[STATEMENT] lemma sorted_list_of_set_lessThan_Suc [simp]: "sorted_list_of_set {..<Suc k} = sorted_list_of_set {..<k} @ [k]" [PROOF STATE] proof (prove) goal (1 subgoal): 1. sorted_list_of_set {..<Suc k} = sorted_list_of_set {..<k} @ [k] [PROOF STEP] using le0 lessThan_atLeast0 sorted_list_of_set_range upt_Suc_append [PROOF STATE] proof (prove) using this: 0 \<le> ?n {..<?n} = {0..<?n} sorted_list_of_set {?m..<?n} = [?m..<?n] ?i \<le> ?j \<Longrightarrow> [?i..<Suc ?j] = [?i..<?j] @ [?j] goal (1 subgoal): 1. sorted_list_of_set {..<Suc k} = sorted_list_of_set {..<k} @ [k] [PROOF STEP] by presburger
t1 : Bits8 t1 = 2 t2 : Bits8 t2 = 255 t3 : Bits8 t3 = 100 tests8 : List String tests8 = map show [t1 + t2, t1 * t3, the Bits8 (fromInteger (-8)), the Bits8 257, the Bits8 (fromInteger (-1)), prim__shl_Bits8 t3 1, prim__shl_Bits8 t2 1] testsCmp : List String testsCmp = map show [t1 < t2, t3 < (t2 + t1)] testsMax : List String testsMax = [show (the Bits8 (fromInteger (-1))), show (the Bits16 (fromInteger (-1))), show (the Bits32 (fromInteger (-1))), show (the Bits64 (fromInteger (-1)))] main : IO () main = do printLn (t1 + t2) printLn (t1 * t3) printLn (t1 < t2) printLn (prim__shl_Bits8 t3 1) printLn (prim__shl_Bits8 t2 1) printLn (t3 < (t2 + t1)) printLn (the Bits8 (fromInteger (-8))) printLn (the Bits8 257) printLn (the Bits64 1234567890) printLn (the Bits8 (fromInteger (-1))) printLn (the Bits16 (fromInteger (-1))) printLn (the Bits32 (fromInteger (-1))) printLn (the Bits64 (fromInteger (-1)))
Require Import Bool. Require Import Sorting.Permutation. Require Import Omega. Require Import sflib. Require Import Lia. Require Import Common. Require Import Value. Require Import Lang. Require Import Memory. Require Import State. Require Import LoadStore. Require Import SmallStep. Require Import SmallStepAux. Require Import SmallStepWf. Require Import Refinement. Require Import SmallStepRefinement. Require Import Reordering. Require Import GVN1. Module Ir. Module GVN3. (* 3nd condition of replacing p with q: If p and q are both computed by the gep inbounds with same base pointer, it is valid to replace p with q. *) Definition eqprop_valid3 (m:Ir.Memory.t) (p q:Ir.val) := exists p0 idx1 idx2 ty1 ty2, p = Ir.SmallStep.gep p0 idx1 ty1 m true /\ q = Ir.SmallStep.gep p0 idx2 ty2 m true. (********************************************************* Important property of eqprop_valid3: If eqprop_valid3 p q holds, and `icmp eq p, q` evaluates to true, then p and q are exactly the same pointer. *********************************************************) Lemma twos_compl_twos_compl_add_PTRSZ: forall n x, Ir.SmallStep.twos_compl (Ir.SmallStep.twos_compl_add n x Ir.PTRSZ) Ir.PTRSZ = Ir.SmallStep.twos_compl_add n x Ir.PTRSZ. Proof. intros. rewrite Ir.PTRSZ_def. unfold Ir.SmallStep.twos_compl_add. unfold Ir.SmallStep.twos_compl. rewrite Nat.mod_mod. reflexivity. apply shiftl_2_nonzero. Qed. Theorem gep_never_returns_num: forall v p idx ty m inb (HGEP1:Ir.SmallStep.gep p idx ty m inb = v), ~exists n, v = Ir.num n. Proof. intros. unfold Ir.SmallStep.gep in HGEP1. intros HH. inv HH. des_ifs. Qed. (* I had to split the big theorem into lemmas due to Coq bug - Coq does not terminate processing of 'Qed.', due to unknown reason :( *) Lemma eqprop_valid3_after_icmpeq_true_log: forall md st st' r ptrty op1 op2 p1 p2 e l0 o0 idx1 ty1 idx2 ty2 (HWF:Ir.Config.wf md st) (HINST:Some (Ir.Inst.iicmp_eq r ptrty op1 op2) = Ir.Config.cur_inst md st) (HOP1:Some (Ir.ptr p1) = Ir.Config.get_val st op1) (HOP2:Some (Ir.ptr p2) = Ir.Config.get_val st op2) (* geps *) (HGEP1:(Ir.ptr p1) = Ir.SmallStep.gep (Ir.plog l0 o0) idx1 ty1 (Ir.Config.m st) true) (HGEP2:(Ir.ptr p2) = Ir.SmallStep.gep (Ir.plog l0 o0) idx2 ty2 (Ir.Config.m st) true) (* have a small step *) (HSTEP:Ir.SmallStep.sstep md st (Ir.SmallStep.sr_success e st')) (* p1 == p2 is true *) (HTRUE:Some (Ir.num 1) = Ir.Config.get_val st' (Ir.opreg r)), p1 = p2. Proof. intros. assert (HS:Ir.Config.s st <> []). { unfold Ir.Config.cur_inst in HINST. unfold Ir.Config.cur_fdef_pc in HINST. des_ifs. } inv HSTEP. { inv HISTEP; try congruence. { unfold Ir.SmallStep.inst_det_step in HNEXT. rewrite <- HINST in HNEXT. rewrite <- HOP1, <- HOP2 in HNEXT. unfold Ir.SmallStep.icmp_eq_ptr in HNEXT. unfold Ir.SmallStep.gep in *. des_ifs. { rewrite Ir.SmallStep.get_val_update_reg_and_incrpc in HTRUE. unfold Ir.Config.get_val in HTRUE. rewrite Ir.Config.get_rval_update_rval_id in HTRUE. inv HTRUE. des_ifs. rewrite Nat.eqb_eq in Heq3. congruence. assumption. } { rewrite Ir.SmallStep.get_val_update_reg_and_incrpc in HTRUE. unfold Ir.Config.get_val in HTRUE. rewrite Ir.Config.get_rval_update_rval_id in HTRUE. inv HTRUE. des_ifs. } } { rewrite <- HINST in HCUR. inv HCUR. rewrite <- HOP1 in HOP0. inv HOP0. rewrite <- HOP2 in HOP3. inv HOP3. unfold Ir.SmallStep.gep in *. unfold Ir.SmallStep.icmp_eq_ptr_nondet_cond in *. des_ifs; rewrite Nat.eqb_refl in HNONDET; inv HNONDET. } } { apply Ir.Config.cur_inst_not_cur_terminator in HINST. unfold Ir.SmallStep.t_step in HTSTEP. rewrite <- HINST in HTSTEP. congruence. } Qed. (* due to Coq bug, I made a separated lemmax *) Lemma gep_helper_small: forall n l o x1 x3 st p0 n'1 (HVAL2 : Ir.SmallStep.gep (Ir.pphy n l o) x1 x3 (Ir.Config.m st) true = Ir.ptr p0) (Heqn'1: n'1 = Ir.SmallStep.twos_compl_add n (x1 * Ir.ty_bytesz x3) Ir.PTRSZ), p0 = Ir.pphy n'1 (n::n'1::l) o. Proof. intros. unfold Ir.SmallStep.gep in HVAL2. des_ifs. Qed. Lemma gep_helper: forall n l o x1 x3 x0 x2 st p0 p st' r e md (HVAL2 : Ir.SmallStep.gep (Ir.pphy n l o) x1 x3 (Ir.Config.m st) true = Ir.ptr p0) (HVAL1 : Ir.SmallStep.gep (Ir.pphy n l o) x0 x2 (Ir.Config.m st) true = Ir.ptr p) (HTRUE : Some (Ir.num 1) = Ir.Config.get_val st' (Ir.opreg r)) (HNEXT : Some (Ir.SmallStep.sr_success e st') = match Ir.SmallStep.icmp_eq_ptr p p0 (Ir.Config.m st) with | Some b => Some (Ir.SmallStep.sr_success Behaviors.Ir.e_none (Ir.SmallStep.update_reg_and_incrpc md st r (Ir.SmallStep.to_num b))) | None => None end) (HS : Ir.Config.s st <> []), Ir.ptr p = Ir.ptr p0. Proof. intros. eapply gep_helper_small in HVAL2; try reflexivity. eapply gep_helper_small in HVAL1; try reflexivity. rewrite HVAL1, HVAL2 in HNEXT. unfold Ir.SmallStep.icmp_eq_ptr in HNEXT. unfold Ir.SmallStep.p2N in HNEXT. rewrite Nat.min_id in HNEXT. rewrite twos_compl_twos_compl_add_PTRSZ in HNEXT. inversion HNEXT. rewrite H1 in HTRUE. rewrite Ir.SmallStep.get_val_update_reg_and_incrpc in HTRUE. unfold Ir.Config.get_val in HTRUE. rewrite Ir.Config.get_rval_update_rval_id in HTRUE. inversion HTRUE. destruct (Ir.SmallStep.twos_compl_add n (x0 * Ir.ty_bytesz x2) Ir.PTRSZ =? Ir.SmallStep.twos_compl_add n (x1 * Ir.ty_bytesz x3) Ir.PTRSZ) eqn:Heq; try congruence. rewrite Nat.eqb_eq in Heq. rewrite HVAL1, HVAL2, Heq. reflexivity. assumption. Qed. (* This is really strange.. Why Qed never ends? *) Theorem eqprop_valid3_after_icmpeq_true: forall md st st' r ptrty op1 op2 v1 v2 e (HWF:Ir.Config.wf md st) (HINST:Some (Ir.Inst.iicmp_eq r ptrty op1 op2) = Ir.Config.cur_inst md st) (HOP1:Some v1 = Ir.Config.get_val st op1) (HOP2:Some v2 = Ir.Config.get_val st op2) (* eqprop_valid3 holds *) (HEQPROP:eqprop_valid3 (Ir.Config.m st) v1 v2) (* have a small step *) (HSTEP:Ir.SmallStep.sstep md st (Ir.SmallStep.sr_success e st')) (* p1 == p2 is true *) (HTRUE:Some (Ir.num 1) = Ir.Config.get_val st' (Ir.opreg r)), v1 = v2. Proof. intros. assert (HS:Ir.Config.s st <> []). { unfold Ir.Config.cur_inst in HINST. unfold Ir.Config.cur_fdef_pc in HINST. des_ifs. } inv HSTEP. { inv HISTEP; try congruence. { inv HEQPROP. inv H. inv H0. inv H. inv H0. inv H. destruct x. { destruct (Ir.SmallStep.gep (Ir.plog b n) x0 x2 (Ir.Config.m st) true) eqn:HVAL1; destruct (Ir.SmallStep.gep (Ir.plog b n) x1 x3 (Ir.Config.m st) true) eqn:HVAL2; try (apply gep_never_returns_num in HVAL1; exfalso; apply HVAL1; eexists; reflexivity); try (apply gep_never_returns_num in HVAL2; exfalso; apply HVAL2; eexists; reflexivity). { exploit eqprop_valid3_after_icmpeq_true_log. { eassumption. } { eassumption. } { eassumption. } { eassumption. } { rewrite HVAL1. reflexivity. } { rewrite HVAL2. reflexivity. } { eapply Ir.SmallStep.ss_inst. eapply Ir.SmallStep.s_det. eassumption. } { eassumption. } intros HH. congruence. } { unfold Ir.SmallStep.inst_det_step in HNEXT. rewrite <- HINST in HNEXT. rewrite <- HOP2 in HNEXT. des_ifs. rewrite Ir.SmallStep.get_val_update_reg_and_incrpc in HTRUE. unfold Ir.Config.get_val in HTRUE. rewrite Ir.Config.get_rval_update_rval_id in HTRUE. inv HTRUE. assumption. } { unfold Ir.SmallStep.inst_det_step in HNEXT. rewrite <- HINST in HNEXT. rewrite <- HOP1 in HNEXT. des_ifs. rewrite Ir.SmallStep.get_val_update_reg_and_incrpc in HTRUE. unfold Ir.Config.get_val in HTRUE. rewrite Ir.Config.get_rval_update_rval_id in HTRUE. inv HTRUE. assumption. } { unfold Ir.SmallStep.inst_det_step in HNEXT. rewrite <- HINST in HNEXT. rewrite <- HOP2 in HNEXT. des_ifs. } } { (* phy. *) unfold Ir.SmallStep.inst_det_step in HNEXT. rewrite <- HINST in HNEXT. rewrite <- HOP1, <- HOP2 in HNEXT. destruct (Ir.SmallStep.gep (Ir.pphy n l o) x0 x2 (Ir.Config.m st) true) eqn:HVAL1; destruct (Ir.SmallStep.gep (Ir.pphy n l o) x1 x3 (Ir.Config.m st) true) eqn:HVAL2; try (apply gep_never_returns_num in HVAL1; exfalso; apply HVAL1; eexists; reflexivity); try (apply gep_never_returns_num in HVAL2; exfalso; apply HVAL2; eexists; reflexivity). { eapply gep_helper; try eassumption. } { inv HNEXT. rewrite Ir.SmallStep.get_val_update_reg_and_incrpc in HTRUE. unfold Ir.Config.get_val in HTRUE. rewrite Ir.Config.get_rval_update_rval_id in HTRUE. inv HTRUE. assumption. } { inv HNEXT. rewrite Ir.SmallStep.get_val_update_reg_and_incrpc in HTRUE. unfold Ir.Config.get_val in HTRUE. rewrite Ir.Config.get_rval_update_rval_id in HTRUE. inv HTRUE. assumption. } { reflexivity. } } } { (* well, cannot be nondet... *) rewrite <- HINST in HCUR. inv HCUR. rewrite <- HOP1 in HOP0. inv HOP0. rewrite <- HOP2 in HOP3. inv HOP3. inv HEQPROP. inv H. inv H0. inv H. inv H0. destruct H. destruct x. { assert (HOFS1:exists ofs1, p1 = (Ir.plog b ofs1)). { unfold Ir.SmallStep.gep in H. unfold Ir.SmallStep.gep in H0. unfold Ir.SmallStep.icmp_eq_ptr_nondet_cond in HNONDET. des_ifs; eexists; reflexivity. } assert (HOFS2:exists ofs2, p2 = (Ir.plog b ofs2)). { unfold Ir.SmallStep.gep in H. unfold Ir.SmallStep.gep in H0. unfold Ir.SmallStep.icmp_eq_ptr_nondet_cond in HNONDET. des_ifs; eexists; reflexivity. } inv HOFS1. inv HOFS2. unfold Ir.SmallStep.icmp_eq_ptr_nondet_cond in HNONDET. des_ifs; rewrite Nat.eqb_refl in HNONDET; inv HNONDET. } { assert (HOFS1:exists a1 b1 c1, p1 = (Ir.pphy a1 b1 c1)). { unfold Ir.SmallStep.gep in H. unfold Ir.SmallStep.gep in H0. unfold Ir.SmallStep.icmp_eq_ptr_nondet_cond in HNONDET. des_ifs; eexists; reflexivity. } assert (HOFS2:exists a2 b2 c2, p2 = (Ir.pphy a2 b2 c2)). { unfold Ir.SmallStep.gep in H. unfold Ir.SmallStep.gep in H0. unfold Ir.SmallStep.icmp_eq_ptr_nondet_cond in HNONDET. des_ifs; eexists; reflexivity. } inv HOFS1. inv H1. inv H2. inv HOFS2. inv H1. inv H2. unfold Ir.SmallStep.icmp_eq_ptr_nondet_cond in HNONDET. des_ifs. } } } { (* terminator! *) apply Ir.Config.cur_inst_not_cur_terminator in HINST. unfold Ir.SmallStep.t_step in HTSTEP. rewrite <- HINST in HTSTEP. congruence. } Qed. (********************************************************* Okay, from theorem `eqprop_valid3_after_icmpeq_true`, we can say that two pointers have same value after `p == q` check. It is trivial to have same execution when same value is given, hence not proved. *********************************************************) End GVN3. End Ir.
#include <stdio.h> #include <gsl/gsl_sf_bessel.h> int main (void) { double x, y; x = 5.0; y = gsl_sf_bessel_J0 (x); printf ("J0(%g) = %.18e\n", x, y); return 0; }
module FishInElab import Language.Reflection %default total %language ElabReflection x : List String x = ["a", "b"] infixl 1 >==> -- From prelude: --(>=>) : Monad m => (a -> m b) -> (b -> m c) -> (a -> m c) --(>=>) f g = \x => f x >>= g (>==>) : Monad m => (a -> m b) -> (b -> m c) -> (a -> m c) (>==>) f g = \x => f x >>= \r => g r %runElab traverse_ (pure >==> logMsg "debug" 0) x -- works %runElab traverse_ (pure >=> \s => logMsg "debug" 0 s) x -- works %runElab traverse_ (pure >=> logMsg "debug" 0) x -- should work, but does not
def f (x : α) := x theorem ex1 (a : α) (b : List α) : f (a::b = []) = False := by simp [f] def length : List α → Nat | [] => 0 | a::as => length as + 1 theorem ex2 (a b c : α) (as : List α) : length (a :: b :: as) > length as := by simp [length] apply Nat.lt.step apply Nat.ltSuccSelf def fact : Nat → Nat | 0 => 1 | x+1 => (x+1) * fact x theorem ex3 : fact x > 0 := by induction x with | zero => rfl | succ x ih => simp [fact] apply Nat.mulPos apply Nat.zeroLtSucc apply ih def head [Inhabited α] : List α → α | [] => arbitrary | a::_ => a theorem ex4 [Inhabited α] (a : α) (as : List α) : head (a::as) = a := by simp [head] def foo := 10 theorem ex5 (x : Nat) : foo + x = 10 + x := by simp [foo] done def g (x : Nat) : Nat := do let x ← pure x return x theorem ex6 : g x = x := by simp [g, bind, pure] def f1 : StateM Nat Unit := do modify fun x => g x def f2 : StateM Nat Unit := do let s ← get set <| g s theorem ex7 : f1 = f2 := by simp [f1, f2, bind, StateT.bind, get, getThe, MonadStateOf.get, StateT.get, pure, set, StateT.set, modify, modifyGet, MonadStateOf.modifyGet, StateT.modifyGet] def h (x : Nat) : Sum (Nat × Nat) Nat := Sum.inl (x, x) def bla (x : Nat) := match h x with | Sum.inl (y, z) => y + z | Sum.inr _ => 0 theorem ex8 (x : Nat) : bla x = x + x := by simp [bla, h]
Sometimes it is the things you see every day which inspire you. A colour or texture catches your eye, and you're hooked. The itch starts, and you find you have to paint it. Whatever it might be. This happened for me a couple of years ago, when I was working with the lovely Vital Veg at Midmar. Every week I packed beautiful, colourful veg into veg bags for customers. Some of the veg came home with me. And some of that came with me to the weekly art class I was attending. Another influence fed into this process. A few years ago, I attended a workshop with Sofia Perina-Miller, whose work I also greatly admire. She paints fabulous striking flowers, as well as many other subjects. She showed us how to paint directly onto paper, without doing any initial drawing. This was an entirely new experience for me - and I found that I loved the freedom of it! Instead of feeling constrained by the pencil lines, I was "free" to paint directly, loosely, using vibrant colours, which resulted in more lively work. Sofia usually adds meticulous pen and ink details to her work. I left mine as they were; as I may have mentioned before I have rather limited patience! There is always a certain amount of fear involved in painting this way. I had to learn to be brave, to trust that the colours I was choosing and the marks I was making were strong and true and confident. This was no time for fiddling around with details and tentative marks. Before I started, I would look carefully at the veg, get a feel for the overall shape and size and proportions, the main colours, the shadows on the paper. Really look, and get a feel for it. It helped to stand up, to have everything I needed to hand and to just do it, quickly. I love this way of working; writing this makes me want to do some more of this kind of work. Some of my veg paintings are available as digital downloads from my Etsy shop. Various items (prints, mugs, phone covers, tote bags etc.) sporting my veg paintings can also be found on Redbubble. I often make soup. At the organic veg farm where I work part-time, we take it in turns to bring a pot of soup to the veg shed on the day we pack veg bags for customers. One of the things I love about soup is that it is very forgiving. You can throw just about anything into it and it is usually pretty tasty and good. (The only exception seems to be kiwi fruit, which a friend reminded me of today - that did not turn out well. I do quite often put apple or pear in soup though, lends a lovely sweetness). Most of us who takes turns with the soup pot admit to making "bottom of the fridge" soup, with whatever is left and is maybe looking a little tired. Some celery, onion, a courgette, a bit of broccoli, the odd kale leaf and some carrots - add ham stock, a tin of chopped tomatoes and hey presto, it's minestrone! Minestrone is one of my favourites and yet I don't recall having it at home when I was a child. We had broth (not a favourite; I disliked the gloopy texture of the barley), and homemade tomato soup with lots of carrots and was it sago, perhaps, to thicken it? My favourite was cucumber soup, creamy and buttery and delicious. My dad loved consomme, hot or cold (brown meaty jelly with chopped chives on top). We had chicken soup too, made using a boiling fowl, with rice and leeks and chopped parsley from the garden to garnish it. We used to laugh at Mum, who would make soup from the peapods after the sweet garden peas had been shelled from them. "Is that grass soup?" we would ask. I quite often produce "green soup" of slightly dubious origins myself, these days, so I can now appreciate the greenness of her ways. It's a real comfort food. And not just the eating of it, or supping of it, but the act of making it. I remember retreating to the kitchen of my mother-in-law's house the day after my father-in-law died very suddenly, over 25 years ago now. We went to stay with her, with our six month old son. To try to help; to organise the funeral, make endless cups of tea for people who came in to offer condolences; to try and make sense of it all. All I could do was make soup. I chopped and stirred and added stock. I left it to simmer, tasted it, ladled it into bowls for whoever wanted some. It seemed to help. It helped me, to feel I was providing comfort, of sorts. I think I maybe even baked. There was comfort in it for me too. Just the rhythm of washing and peeling and chopping, stirring and tasting and serving. Life going on, in some small way.
# included in runtests.jl # Very similar to client_serverWS_test.jl # Test sending / receiving messages correctly, # closing from within websocket handlers, # symmetry of client and server side websockets, # stress tests opening and closing a sequence of servers. # At this time, we unfortunately get irritating messages # 'Workqueue inconsistency detected:...' # @info "External server http request" # @test 200 == HTTP.request("GET", EXTERNALHTTP).status @info "Listen: Open, http response, close. Repeat three times. Takes a while." for i = 1:3 let server = startserver(url=SURL,port=PORT) status = HTTP.request("GET", "http://$SURL:$PORT").status println("Status($(i)): $(status)") @test 200 == status close(server) end end @info "Listen: Client side initates message exchange." let server = startserver(url=SURL,port=PORT) WebSockets.open(initiatingws, "ws://$SURL:$PORT") close(server) end @info "Listen: Server side initates message exchange." let server = startserver(url=SURL,port=PORT) WebSockets.open(echows, "ws://$SURL:$PORT", subprotocol = SUBPROTOCOL) close(server) end @info "Listen: Server side initates message exchange. Close from within server side handler." let server = startserver(url=SURL,port=PORT) WebSockets.open(echows, "ws://$SURL:$PORT", subprotocol = SUBPROTOCOL_CLOSE) close(server) end nothing
[STATEMENT] lemma rqrm_\<alpha>_lookup_update[simp]: "rqrm_invar rqrm \<Longrightarrow> ls_\<alpha> (rqrm_lookup (rqrm_add q r rqrm) q') = ( if q=q' then insert r (ls_\<alpha> (rqrm_lookup rqrm q')) else ls_\<alpha> (rqrm_lookup rqrm q') )" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rqrm_invar rqrm \<Longrightarrow> ls.\<alpha> (rqrm_lookup (rqrm_add q r rqrm) q') = (if q = q' then insert r (ls.\<alpha> (rqrm_lookup rqrm q')) else ls.\<alpha> (rqrm_lookup rqrm q')) [PROOF STEP] by (simp add: rqrm_lookup_def rqrm_add_def rqrm_invar_def hm.correct ls.correct split: option.split_asm option.split)
--- author: Nathan Carter ([email protected]) --- This answer assumes you have imported SymPy as follows. ```python from sympy import * # load all math functions init_printing( use_latex='mathjax' ) # use pretty math output ``` Let's choose an example formula whose antiderivative we will compute. ```python var( 'x' ) formula = 3*sqrt(x) formula ``` $\displaystyle 3 \sqrt{x}$ Use the `Integral` function to build a definite integral without evaluating it. The second parameter is the variable with respect to which you're integrating. ```python Integral( formula, x ) ``` $\displaystyle \int 3 \sqrt{x}\, dx$ Use the `integrate` function to perform the integration, showing the answer. ```python integrate( formula, x ) ``` $\displaystyle 2 x^{\frac{3}{2}}$ ```python integrate( formula, x ) + var('C') # same, but with a constant of integration ``` $\displaystyle C + 2 x^{\frac{3}{2}}$
import category_theory.category.default universes v u -- The order in this declaration matters: v often needs to be explicitly specified while u often can be omitted namespace category_theory variables (C : Type u) [category.{v} C] --rewrite this /- # Category world ## Level 7: Composition of monomorphisms Now we show that the composition of two monomorphisms produces another monomorphism.-/ /- Lemma If $$f : X ⟶ Y$$ and $$g : X ⟶ Y$$ are monomorphisms, then $$f ≫ g : X ⟶ Z$$ is a monomorphism. -/ lemma mono_comp' {X Y Z : C} (f : X ⟶ Y) [mono f] (g : Y ⟶ Z) [mono g] : mono (f ≫ g) := begin split, intros Z h l hyp, rw ← cancel_mono f, rw ← cancel_mono g, rw category.assoc, rw category.assoc, exact hyp, end end category_theory
[STATEMENT] lemma set_diag_mat_smult: assumes "A\<in> carrier_mat n n" shows "set (diag_mat (x \<cdot>\<^sub>m A)) = {x * a |a. a\<in> set (diag_mat A)}" (is "?L = ?R") [PROOF STATE] proof (prove) goal (1 subgoal): 1. set (diag_mat (x \<cdot>\<^sub>m A)) = {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] proof [PROOF STATE] proof (state) goal (2 subgoals): 1. set (diag_mat (x \<cdot>\<^sub>m A)) \<subseteq> {x * a |a. a \<in> set (diag_mat A)} 2. {x * a |a. a \<in> set (diag_mat A)} \<subseteq> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] show "?L \<subseteq> ?R" [PROOF STATE] proof (prove) goal (1 subgoal): 1. set (diag_mat (x \<cdot>\<^sub>m A)) \<subseteq> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] proof [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] fix b [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] assume "b \<in> set (diag_mat (x \<cdot>\<^sub>m A))" [PROOF STATE] proof (state) this: b \<in> set (diag_mat (x \<cdot>\<^sub>m A)) goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] hence "\<exists>i < length (diag_mat (x \<cdot>\<^sub>m A)). nth (diag_mat (x \<cdot>\<^sub>m A)) i = b" [PROOF STATE] proof (prove) using this: b \<in> set (diag_mat (x \<cdot>\<^sub>m A)) goal (1 subgoal): 1. \<exists>i<length (diag_mat (x \<cdot>\<^sub>m A)). diag_mat (x \<cdot>\<^sub>m A) ! i = b [PROOF STEP] using in_set_conv_nth[of b] [PROOF STATE] proof (prove) using this: b \<in> set (diag_mat (x \<cdot>\<^sub>m A)) (b \<in> set ?xs) = (\<exists>i<length ?xs. ?xs ! i = b) goal (1 subgoal): 1. \<exists>i<length (diag_mat (x \<cdot>\<^sub>m A)). diag_mat (x \<cdot>\<^sub>m A) ! i = b [PROOF STEP] by simp [PROOF STATE] proof (state) this: \<exists>i<length (diag_mat (x \<cdot>\<^sub>m A)). diag_mat (x \<cdot>\<^sub>m A) ! i = b goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] from this [PROOF STATE] proof (chain) picking this: \<exists>i<length (diag_mat (x \<cdot>\<^sub>m A)). diag_mat (x \<cdot>\<^sub>m A) ! i = b [PROOF STEP] obtain i where "i < length (diag_mat (x \<cdot>\<^sub>m A))" and "nth (diag_mat (x \<cdot>\<^sub>m A)) i = b" [PROOF STATE] proof (prove) using this: \<exists>i<length (diag_mat (x \<cdot>\<^sub>m A)). diag_mat (x \<cdot>\<^sub>m A) ! i = b goal (1 subgoal): 1. (\<And>i. \<lbrakk>i < length (diag_mat (x \<cdot>\<^sub>m A)); diag_mat (x \<cdot>\<^sub>m A) ! i = b\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by auto [PROOF STATE] proof (state) this: i < length (diag_mat (x \<cdot>\<^sub>m A)) diag_mat (x \<cdot>\<^sub>m A) ! i = b goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] note iprop = this [PROOF STATE] proof (state) this: i < length (diag_mat (x \<cdot>\<^sub>m A)) diag_mat (x \<cdot>\<^sub>m A) ! i = b goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] hence "i < dim_row (x \<cdot>\<^sub>m A)" [PROOF STATE] proof (prove) using this: i < length (diag_mat (x \<cdot>\<^sub>m A)) diag_mat (x \<cdot>\<^sub>m A) ! i = b goal (1 subgoal): 1. i < dim_row (x \<cdot>\<^sub>m A) [PROOF STEP] unfolding diag_mat_def [PROOF STATE] proof (prove) using this: i < length (map (\<lambda>i. (x \<cdot>\<^sub>m A) $$ (i, i)) [0..<dim_row (x \<cdot>\<^sub>m A)]) map (\<lambda>i. (x \<cdot>\<^sub>m A) $$ (i, i)) [0..<dim_row (x \<cdot>\<^sub>m A)] ! i = b goal (1 subgoal): 1. i < dim_row (x \<cdot>\<^sub>m A) [PROOF STEP] by simp [PROOF STATE] proof (state) this: i < dim_row (x \<cdot>\<^sub>m A) goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] hence "i < n" [PROOF STATE] proof (prove) using this: i < dim_row (x \<cdot>\<^sub>m A) goal (1 subgoal): 1. i < n [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: i < dim_row (x \<cdot>\<^sub>m A) A \<in> carrier_mat n n goal (1 subgoal): 1. i < n [PROOF STEP] by simp [PROOF STATE] proof (state) this: i < n goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] have "b = (x \<cdot>\<^sub>m A)$$(i,i)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. b = (x \<cdot>\<^sub>m A) $$ (i, i) [PROOF STEP] using iprop [PROOF STATE] proof (prove) using this: i < length (diag_mat (x \<cdot>\<^sub>m A)) diag_mat (x \<cdot>\<^sub>m A) ! i = b goal (1 subgoal): 1. b = (x \<cdot>\<^sub>m A) $$ (i, i) [PROOF STEP] unfolding diag_mat_def [PROOF STATE] proof (prove) using this: i < length (map (\<lambda>i. (x \<cdot>\<^sub>m A) $$ (i, i)) [0..<dim_row (x \<cdot>\<^sub>m A)]) map (\<lambda>i. (x \<cdot>\<^sub>m A) $$ (i, i)) [0..<dim_row (x \<cdot>\<^sub>m A)] ! i = b goal (1 subgoal): 1. b = (x \<cdot>\<^sub>m A) $$ (i, i) [PROOF STEP] by simp [PROOF STATE] proof (state) this: b = (x \<cdot>\<^sub>m A) $$ (i, i) goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] also [PROOF STATE] proof (state) this: b = (x \<cdot>\<^sub>m A) $$ (i, i) goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] have "... = x * A$$(i,i)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (x \<cdot>\<^sub>m A) $$ (i, i) = x * A $$ (i, i) [PROOF STEP] using \<open>i < n\<close> assms [PROOF STATE] proof (prove) using this: i < n A \<in> carrier_mat n n goal (1 subgoal): 1. (x \<cdot>\<^sub>m A) $$ (i, i) = x * A $$ (i, i) [PROOF STEP] unfolding uminus_mat_def [PROOF STATE] proof (prove) using this: i < n A \<in> carrier_mat n n goal (1 subgoal): 1. (x \<cdot>\<^sub>m A) $$ (i, i) = x * A $$ (i, i) [PROOF STEP] by auto [PROOF STATE] proof (state) this: (x \<cdot>\<^sub>m A) $$ (i, i) = x * A $$ (i, i) goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] also [PROOF STATE] proof (state) this: (x \<cdot>\<^sub>m A) $$ (i, i) = x * A $$ (i, i) goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] have "... \<in> ?R" [PROOF STATE] proof (prove) goal (1 subgoal): 1. x * A $$ (i, i) \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] using iprop assms \<open>i < n\<close> in_set_conv_nth[of "A$$(i,i)"] [PROOF STATE] proof (prove) using this: i < length (diag_mat (x \<cdot>\<^sub>m A)) diag_mat (x \<cdot>\<^sub>m A) ! i = b A \<in> carrier_mat n n i < n (A $$ (i, i) \<in> set ?xs) = (\<exists>ia<length ?xs. ?xs ! ia = A $$ (i, i)) goal (1 subgoal): 1. x * A $$ (i, i) \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] by (metis (mono_tags, lifting) carrier_matD(1) diag_elems_mem diag_elems_set_diag_mat mem_Collect_eq) [PROOF STATE] proof (state) this: x * A $$ (i, i) \<in> {x * a |a. a \<in> set (diag_mat A)} goal (1 subgoal): 1. \<And>xa. xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) \<Longrightarrow> xa \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: b \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] show "b \<in> ?R" [PROOF STATE] proof (prove) using this: b \<in> {x * a |a. a \<in> set (diag_mat A)} goal (1 subgoal): 1. b \<in> {x * a |a. a \<in> set (diag_mat A)} [PROOF STEP] . [PROOF STATE] proof (state) this: b \<in> {x * a |a. a \<in> set (diag_mat A)} goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: set (diag_mat (x \<cdot>\<^sub>m A)) \<subseteq> {x * a |a. a \<in> set (diag_mat A)} goal (1 subgoal): 1. {x * a |a. a \<in> set (diag_mat A)} \<subseteq> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. {x * a |a. a \<in> set (diag_mat A)} \<subseteq> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] show "?R \<subseteq> ?L" [PROOF STATE] proof (prove) goal (1 subgoal): 1. {x * a |a. a \<in> set (diag_mat A)} \<subseteq> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] proof [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] fix b [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] assume "b\<in> ?R" [PROOF STATE] proof (state) this: b \<in> {x * a |a. a \<in> set (diag_mat A)} goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] hence "\<exists>i < length (diag_mat A). x * (nth (diag_mat A) i) = b" [PROOF STATE] proof (prove) using this: b \<in> {x * a |a. a \<in> set (diag_mat A)} goal (1 subgoal): 1. \<exists>i<length (diag_mat A). x * diag_mat A ! i = b [PROOF STEP] using in_set_conv_nth[of x] [PROOF STATE] proof (prove) using this: b \<in> {x * a |a. a \<in> set (diag_mat A)} (x \<in> set ?xs) = (\<exists>i<length ?xs. ?xs ! i = x) goal (1 subgoal): 1. \<exists>i<length (diag_mat A). x * diag_mat A ! i = b [PROOF STEP] by (smt (z3) in_set_conv_nth mem_Collect_eq) [PROOF STATE] proof (state) this: \<exists>i<length (diag_mat A). x * diag_mat A ! i = b goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] from this [PROOF STATE] proof (chain) picking this: \<exists>i<length (diag_mat A). x * diag_mat A ! i = b [PROOF STEP] obtain i where "i < length (diag_mat A)" and "x * (nth (diag_mat A) i) = b" [PROOF STATE] proof (prove) using this: \<exists>i<length (diag_mat A). x * diag_mat A ! i = b goal (1 subgoal): 1. (\<And>i. \<lbrakk>i < length (diag_mat A); x * diag_mat A ! i = b\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by auto [PROOF STATE] proof (state) this: i < length (diag_mat A) x * diag_mat A ! i = b goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] note iprop = this [PROOF STATE] proof (state) this: i < length (diag_mat A) x * diag_mat A ! i = b goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] hence "i < dim_row (x \<cdot>\<^sub>m A)" [PROOF STATE] proof (prove) using this: i < length (diag_mat A) x * diag_mat A ! i = b goal (1 subgoal): 1. i < dim_row (x \<cdot>\<^sub>m A) [PROOF STEP] unfolding diag_mat_def [PROOF STATE] proof (prove) using this: i < length (map (\<lambda>i. A $$ (i, i)) [0..<dim_row A]) x * map (\<lambda>i. A $$ (i, i)) [0..<dim_row A] ! i = b goal (1 subgoal): 1. i < dim_row (x \<cdot>\<^sub>m A) [PROOF STEP] by simp [PROOF STATE] proof (state) this: i < dim_row (x \<cdot>\<^sub>m A) goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] hence "i < n" [PROOF STATE] proof (prove) using this: i < dim_row (x \<cdot>\<^sub>m A) goal (1 subgoal): 1. i < n [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: i < dim_row (x \<cdot>\<^sub>m A) A \<in> carrier_mat n n goal (1 subgoal): 1. i < n [PROOF STEP] by simp [PROOF STATE] proof (state) this: i < n goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] have "b = x *A$$(i,i)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. b = x * A $$ (i, i) [PROOF STEP] using iprop [PROOF STATE] proof (prove) using this: i < length (diag_mat A) x * diag_mat A ! i = b goal (1 subgoal): 1. b = x * A $$ (i, i) [PROOF STEP] unfolding diag_mat_def [PROOF STATE] proof (prove) using this: i < length (map (\<lambda>i. A $$ (i, i)) [0..<dim_row A]) x * map (\<lambda>i. A $$ (i, i)) [0..<dim_row A] ! i = b goal (1 subgoal): 1. b = x * A $$ (i, i) [PROOF STEP] by simp [PROOF STATE] proof (state) this: b = x * A $$ (i, i) goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] also [PROOF STATE] proof (state) this: b = x * A $$ (i, i) goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] have "... = (x \<cdot>\<^sub>m A)$$(i,i)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. x * A $$ (i, i) = (x \<cdot>\<^sub>m A) $$ (i, i) [PROOF STEP] using \<open>i < n\<close> assms [PROOF STATE] proof (prove) using this: i < n A \<in> carrier_mat n n goal (1 subgoal): 1. x * A $$ (i, i) = (x \<cdot>\<^sub>m A) $$ (i, i) [PROOF STEP] unfolding uminus_mat_def [PROOF STATE] proof (prove) using this: i < n A \<in> carrier_mat n n goal (1 subgoal): 1. x * A $$ (i, i) = (x \<cdot>\<^sub>m A) $$ (i, i) [PROOF STEP] by auto [PROOF STATE] proof (state) this: x * A $$ (i, i) = (x \<cdot>\<^sub>m A) $$ (i, i) goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] also [PROOF STATE] proof (state) this: x * A $$ (i, i) = (x \<cdot>\<^sub>m A) $$ (i, i) goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] have "... \<in> ?L" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (x \<cdot>\<^sub>m A) $$ (i, i) \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] using iprop assms \<open>i < n\<close> in_set_conv_nth[of "A$$(i,i)"] [PROOF STATE] proof (prove) using this: i < length (diag_mat A) x * diag_mat A ! i = b A \<in> carrier_mat n n i < n (A $$ (i, i) \<in> set ?xs) = (\<exists>ia<length ?xs. ?xs ! ia = A $$ (i, i)) goal (1 subgoal): 1. (x \<cdot>\<^sub>m A) $$ (i, i) \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] by (metis \<open>i < dim_row (x \<cdot>\<^sub>m A)\<close> diag_elems_mem diag_elems_set_diag_mat) [PROOF STATE] proof (state) this: (x \<cdot>\<^sub>m A) $$ (i, i) \<in> set (diag_mat (x \<cdot>\<^sub>m A)) goal (1 subgoal): 1. \<And>xa. xa \<in> {x * a |a. a \<in> set (diag_mat A)} \<Longrightarrow> xa \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: b \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] show "b \<in> ?L" [PROOF STATE] proof (prove) using this: b \<in> set (diag_mat (x \<cdot>\<^sub>m A)) goal (1 subgoal): 1. b \<in> set (diag_mat (x \<cdot>\<^sub>m A)) [PROOF STEP] . [PROOF STATE] proof (state) this: b \<in> set (diag_mat (x \<cdot>\<^sub>m A)) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: {x * a |a. a \<in> set (diag_mat A)} \<subseteq> set (diag_mat (x \<cdot>\<^sub>m A)) goal: No subgoals! [PROOF STEP] qed
acScanFileAndFlagObject(*ObjPath,*FilePath,*Resource) { # Run clamscan script on resource msiExecCmd("scanfile.py", *FilePath, *Resource, null, null, *CmdOut); # Save operation status assign(*Status, $status); # Get stdout from last call msiGetStdoutInExecCmdOut(*CmdOut, *StdoutStr); # Passed, failed, or error? if (*Status == 0) then # # Scan successful, object passed { # # Get timestamp msiGetSystemTime(*Time, human); # # Create new KeyValPair_MS_T msiAddKeyVal(*KVP, "VIRUS_SCAN_PASSED.*Time", *StdoutStr); # # Add new metadata triplet to object msiAssociateKeyValuePairsToObj(*KVP, *ObjPath, "-d"); } else { if (*Status == 344000) then # # Scan successful, object failed { # # Get timestamp msiGetSystemTime(*Time, human); # # Create new KeyValPair_MS_T msiAddKeyVal(*KVP, "VIRUS_SCAN_FAILED.*Time", *StdoutStr); # # Add new metadata triplet to object msiAssociateKeyValuePairsToObj(*KVP, *ObjPath, "-d"); } else # # Scan failed (command execution error) { nop; } } } INPUT *foo = "" OUTPUT ruleExecOut
Require Export euclidean__axioms. Require Export euclidean__defs. Require Export lemma__8__2. Require Export lemma__8__3. Require Export lemma__collinearorder. Require Export lemma__congruenceflip. Require Export lemma__congruencesymmetric. Require Export lemma__congruencetransitive. Require Export lemma__droppedperpendicularunique. Require Export lemma__extension. Require Export lemma__extensionunique. Require Export lemma__inequalitysymmetric. Require Export lemma__ray4. Require Export logic. Definition lemma__8__7 : forall A B C, (euclidean__defs.Per C B A) -> (~(euclidean__defs.Per A C B)). Proof. intro A. intro B. intro C. intro H. assert (* Cut *) (euclidean__axioms.neq B A) as H0. - assert (exists X, (euclidean__axioms.BetS C B X) /\ ((euclidean__axioms.Cong C B X B) /\ ((euclidean__axioms.Cong C A X A) /\ (euclidean__axioms.neq B A)))) as H0 by exact H. assert (exists X, (euclidean__axioms.BetS C B X) /\ ((euclidean__axioms.Cong C B X B) /\ ((euclidean__axioms.Cong C A X A) /\ (euclidean__axioms.neq B A)))) as __TmpHyp by exact H0. destruct __TmpHyp as [x H1]. destruct H1 as [H2 H3]. destruct H3 as [H4 H5]. destruct H5 as [H6 H7]. exact H7. - assert (* Cut *) (euclidean__defs.Per A B C) as H1. -- apply (@lemma__8__2.lemma__8__2 C B A H). -- assert (* Cut *) (euclidean__axioms.neq B C) as H2. --- assert (exists X, (euclidean__axioms.BetS A B X) /\ ((euclidean__axioms.Cong A B X B) /\ ((euclidean__axioms.Cong A C X C) /\ (euclidean__axioms.neq B C)))) as H2 by exact H1. assert (exists X, (euclidean__axioms.BetS A B X) /\ ((euclidean__axioms.Cong A B X B) /\ ((euclidean__axioms.Cong A C X C) /\ (euclidean__axioms.neq B C)))) as __TmpHyp by exact H2. destruct __TmpHyp as [x H3]. destruct H3 as [H4 H5]. destruct H5 as [H6 H7]. destruct H7 as [H8 H9]. assert (exists X, (euclidean__axioms.BetS C B X) /\ ((euclidean__axioms.Cong C B X B) /\ ((euclidean__axioms.Cong C A X A) /\ (euclidean__axioms.neq B A)))) as H10 by exact H. assert (exists X, (euclidean__axioms.BetS C B X) /\ ((euclidean__axioms.Cong C B X B) /\ ((euclidean__axioms.Cong C A X A) /\ (euclidean__axioms.neq B A)))) as __TmpHyp0 by exact H10. destruct __TmpHyp0 as [x0 H11]. destruct H11 as [H12 H13]. destruct H13 as [H14 H15]. destruct H15 as [H16 H17]. exact H9. --- assert (* Cut *) (euclidean__axioms.neq C B) as H3. ---- apply (@lemma__inequalitysymmetric.lemma__inequalitysymmetric B C H2). ---- assert (* Cut *) (exists E, (euclidean__axioms.BetS B C E) /\ (euclidean__axioms.Cong C E C B)) as H4. ----- apply (@lemma__extension.lemma__extension B C C B H2 H3). ----- destruct H4 as [E H5]. destruct H5 as [H6 H7]. assert (* Cut *) (euclidean__axioms.Col B C E) as H8. ------ right. right. right. right. left. exact H6. ------ assert (* Cut *) (euclidean__axioms.Col E C B) as H9. ------- assert (* Cut *) ((euclidean__axioms.Col C B E) /\ ((euclidean__axioms.Col C E B) /\ ((euclidean__axioms.Col E B C) /\ ((euclidean__axioms.Col B E C) /\ (euclidean__axioms.Col E C B))))) as H9. -------- apply (@lemma__collinearorder.lemma__collinearorder B C E H8). -------- destruct H9 as [H10 H11]. destruct H11 as [H12 H13]. destruct H13 as [H14 H15]. destruct H15 as [H16 H17]. exact H17. ------- assert (euclidean__defs.Per A B C) as H10 by exact H1. assert (* Cut *) (euclidean__defs.Out B C E) as H11. -------- apply (@lemma__ray4.lemma__ray4 B C E). ---------right. right. exact H6. --------- exact H2. -------- assert (* Cut *) (euclidean__defs.Per A B E) as H12. --------- apply (@lemma__8__3.lemma__8__3 A B C E H10 H11). --------- assert (* Cut *) (euclidean__defs.Per E B A) as H13. ---------- apply (@lemma__8__2.lemma__8__2 A B E H12). ---------- assert (* Cut *) (~(euclidean__defs.Per A C B)) as H14. ----------- intro H14. assert (* Cut *) (euclidean__defs.Per B C A) as H15. ------------ apply (@lemma__8__2.lemma__8__2 A C B H14). ------------ assert (exists F, (euclidean__axioms.BetS B C F) /\ ((euclidean__axioms.Cong B C F C) /\ ((euclidean__axioms.Cong B A F A) /\ (euclidean__axioms.neq C A)))) as H16 by exact H15. destruct H16 as [F H17]. destruct H17 as [H18 H19]. destruct H19 as [H20 H21]. destruct H21 as [H22 H23]. assert (* Cut *) (euclidean__axioms.Cong F C B C) as H24. ------------- apply (@lemma__congruencesymmetric.lemma__congruencesymmetric F B C C H20). ------------- assert (* Cut *) (euclidean__axioms.Cong C F B C) as H25. -------------- assert (* Cut *) ((euclidean__axioms.Cong C F C B) /\ ((euclidean__axioms.Cong C F B C) /\ (euclidean__axioms.Cong F C C B))) as H25. --------------- apply (@lemma__congruenceflip.lemma__congruenceflip F C B C H24). --------------- destruct H25 as [H26 H27]. destruct H27 as [H28 H29]. exact H28. -------------- assert (* Cut *) (euclidean__axioms.Cong C E B C) as H26. --------------- assert (* Cut *) ((euclidean__axioms.Cong E C B C) /\ ((euclidean__axioms.Cong E C C B) /\ (euclidean__axioms.Cong C E B C))) as H26. ---------------- apply (@lemma__congruenceflip.lemma__congruenceflip C E C B H7). ---------------- destruct H26 as [H27 H28]. destruct H28 as [H29 H30]. exact H30. --------------- assert (* Cut *) (euclidean__axioms.Cong B C C E) as H27. ---------------- apply (@lemma__congruencesymmetric.lemma__congruencesymmetric B C E C H26). ---------------- assert (* Cut *) (euclidean__axioms.Cong C F C E) as H28. ----------------- apply (@lemma__congruencetransitive.lemma__congruencetransitive C F B C C E H25 H27). ----------------- assert (* Cut *) (F = E) as H29. ------------------ apply (@lemma__extensionunique.lemma__extensionunique B C F E H18 H6 H28). ------------------ assert (* Cut *) (euclidean__axioms.BetS E C B) as H30. ------------------- apply (@euclidean__axioms.axiom__betweennesssymmetry B C E H6). ------------------- assert (* Cut *) (euclidean__axioms.Cong F A B A) as H31. -------------------- apply (@lemma__congruencesymmetric.lemma__congruencesymmetric F B A A H22). -------------------- assert (* Cut *) (euclidean__axioms.Cong E A B A) as H32. --------------------- apply (@eq__ind__r euclidean__axioms.Point E (fun F0 => (euclidean__axioms.BetS B C F0) -> ((euclidean__axioms.Cong B C F0 C) -> ((euclidean__axioms.Cong B A F0 A) -> ((euclidean__axioms.Cong F0 C B C) -> ((euclidean__axioms.Cong C F0 B C) -> ((euclidean__axioms.Cong C F0 C E) -> ((euclidean__axioms.Cong F0 A B A) -> (euclidean__axioms.Cong E A B A))))))))) with (x := F). ----------------------intro H32. intro H33. intro H34. intro H35. intro H36. intro H37. intro H38. exact H38. ---------------------- exact H29. ---------------------- exact H18. ---------------------- exact H20. ---------------------- exact H22. ---------------------- exact H24. ---------------------- exact H25. ---------------------- exact H28. ---------------------- exact H31. --------------------- assert (* Cut *) (euclidean__axioms.Cong E C B C) as H33. ---------------------- assert (* Cut *) ((euclidean__axioms.Cong E C C B) /\ ((euclidean__axioms.Cong E C B C) /\ (euclidean__axioms.Cong C E C B))) as H33. ----------------------- apply (@lemma__congruenceflip.lemma__congruenceflip C E B C H26). ----------------------- destruct H33 as [H34 H35]. destruct H35 as [H36 H37]. exact H36. ---------------------- assert (* Cut *) (euclidean__defs.Per E C A) as H34. ----------------------- exists B. split. ------------------------ exact H30. ------------------------ split. ------------------------- exact H33. ------------------------- split. -------------------------- exact H32. -------------------------- exact H23. ----------------------- assert (* Cut *) (C = B) as H35. ------------------------ apply (@lemma__droppedperpendicularunique.lemma__droppedperpendicularunique E B C A H34 H13 H9). ------------------------ apply (@H3 H35). ----------- exact H14. Qed.
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import algebra.field_power import data.rat /-! # Archimedean groups and fields. This file defines the archimedean property for ordered groups and proves several results connected to this notion. Being archimedean means that for all elements `x` and `y>0` there exists a natural number `n` such that `x ≤ n • y`. ## Main definitions * `archimedean` is a typeclass for an ordered additive commutative monoid to have the archimedean property. * `archimedean.floor_ring` defines a floor function on an archimedean linearly ordered ring making it into a `floor_ring`. * `round` defines a function rounding to the nearest integer for a linearly ordered field which is also a floor ring. ## Main statements * `ℕ`, `ℤ`, and `ℚ` are archimedean. -/ variables {α : Type*} /-- An ordered additive commutative monoid is called `archimedean` if for any two elements `x`, `y` such that `0 < y` there exists a natural number `n` such that `x ≤ n • y`. -/ class archimedean (α) [ordered_add_comm_monoid α] : Prop := (arch : ∀ (x : α) {y}, 0 < y → ∃ n : ℕ, x ≤ n • y) namespace linear_ordered_add_comm_group variables [linear_ordered_add_comm_group α] [archimedean α] /-- An archimedean decidable linearly ordered `add_comm_group` has a version of the floor: for `a > 0`, any `g` in the group lies between some two consecutive multiples of `a`. -/ lemma exists_int_smul_near_of_pos {a : α} (ha : 0 < a) (g : α) : ∃ (k : ℤ), k • a ≤ g ∧ g < (k + 1) • a := begin let s : set ℤ := {n : ℤ | n • a ≤ g}, obtain ⟨k, hk : -g ≤ k • a⟩ := archimedean.arch (-g) ha, have h_ne : s.nonempty := ⟨-k, by simpa using neg_le_neg hk⟩, obtain ⟨k, hk⟩ := archimedean.arch g ha, have h_bdd : ∀ n ∈ s, n ≤ (k : ℤ), { assume n hn, apply (gsmul_le_gsmul_iff ha).mp, rw ← gsmul_coe_nat at hk, exact le_trans hn hk }, obtain ⟨m, hm, hm'⟩ := int.exists_greatest_of_bdd ⟨k, h_bdd⟩ h_ne, refine ⟨m, hm, _⟩, by_contra H, linarith [hm' _ $ not_lt.mp H] end lemma exists_int_smul_near_of_pos' {a : α} (ha : 0 < a) (g : α) : ∃ (k : ℤ), 0 ≤ g - k • a ∧ g - k • a < a := begin obtain ⟨k, h1, h2⟩ := exists_int_smul_near_of_pos ha g, rw add_gsmul at h2, refine ⟨k, sub_nonneg.mpr h1, _⟩, simpa [sub_lt_iff_lt_add'] using h2 end end linear_ordered_add_comm_group theorem exists_nat_gt [ordered_semiring α] [nontrivial α] [archimedean α] (x : α) : ∃ n : ℕ, x < n := let ⟨n, h⟩ := archimedean.arch x zero_lt_one in ⟨n+1, lt_of_le_of_lt (by rwa ← nsmul_one) (nat.cast_lt.2 (nat.lt_succ_self _))⟩ theorem exists_nat_ge [ordered_semiring α] [archimedean α] (x : α) : ∃ n : ℕ, x ≤ n := begin nontriviality α, exact (exists_nat_gt x).imp (λ n, le_of_lt) end lemma add_one_pow_unbounded_of_pos [ordered_semiring α] [nontrivial α] [archimedean α] (x : α) {y : α} (hy : 0 < y) : ∃ n : ℕ, x < (y + 1) ^ n := have 0 ≤ 1 + y, from add_nonneg zero_le_one hy.le, let ⟨n, h⟩ := archimedean.arch x hy in ⟨n, calc x ≤ n • y : h ... = n * y : nsmul_eq_mul _ _ ... < 1 + n * y : lt_one_add _ ... ≤ (1 + y) ^ n : one_add_mul_le_pow' (mul_nonneg hy.le hy.le) (mul_nonneg this this) (add_nonneg zero_le_two hy.le) _ ... = (y + 1) ^ n : by rw [add_comm]⟩ section linear_ordered_ring variables [linear_ordered_ring α] [archimedean α] lemma pow_unbounded_of_one_lt (x : α) {y : α} (hy1 : 1 < y) : ∃ n : ℕ, x < y ^ n := sub_add_cancel y 1 ▸ add_one_pow_unbounded_of_pos _ (sub_pos.2 hy1) /-- Every x greater than or equal to 1 is between two successive natural-number powers of every y greater than one. -/ lemma exists_nat_pow_near {x : α} {y : α} (hx : 1 ≤ x) (hy : 1 < y) : ∃ n : ℕ, y ^ n ≤ x ∧ x < y ^ (n + 1) := have h : ∃ n : ℕ, x < y ^ n, from pow_unbounded_of_one_lt _ hy, by classical; exact let n := nat.find h in have hn : x < y ^ n, from nat.find_spec h, have hnp : 0 < n, from pos_iff_ne_zero.2 (λ hn0, by rw [hn0, pow_zero] at hn; exact (not_le_of_gt hn hx)), have hnsp : nat.pred n + 1 = n, from nat.succ_pred_eq_of_pos hnp, have hltn : nat.pred n < n, from nat.pred_lt (ne_of_gt hnp), ⟨nat.pred n, le_of_not_lt (nat.find_min h hltn), by rwa hnsp⟩ theorem exists_int_gt (x : α) : ∃ n : ℤ, x < n := let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa ← coe_coe⟩ theorem exists_int_lt (x : α) : ∃ n : ℤ, (n : α) < x := let ⟨n, h⟩ := exists_int_gt (-x) in ⟨-n, by rw int.cast_neg; exact neg_lt.1 h⟩ theorem exists_floor (x : α) : ∃ (fl : ℤ), ∀ (z : ℤ), z ≤ fl ↔ (z : α) ≤ x := begin haveI := classical.prop_decidable, have : ∃ (ub : ℤ), (ub:α) ≤ x ∧ ∀ (z : ℤ), (z:α) ≤ x → z ≤ ub := int.exists_greatest_of_bdd (let ⟨n, hn⟩ := exists_int_gt x in ⟨n, λ z h', int.cast_le.1 $ le_trans h' $ le_of_lt hn⟩) (let ⟨n, hn⟩ := exists_int_lt x in ⟨n, le_of_lt hn⟩), refine this.imp (λ fl h z, _), cases h with h₁ h₂, exact ⟨λ h, le_trans (int.cast_le.2 h) h₁, h₂ z⟩, end end linear_ordered_ring section linear_ordered_field variables [linear_ordered_field α] /-- Every positive `x` is between two successive integer powers of another `y` greater than one. This is the same as `exists_int_pow_near'`, but with ≤ and < the other way around. -/ lemma exists_int_pow_near [archimedean α] {x : α} {y : α} (hx : 0 < x) (hy : 1 < y) : ∃ n : ℤ, y ^ n ≤ x ∧ x < y ^ (n + 1) := by classical; exact let ⟨N, hN⟩ := pow_unbounded_of_one_lt x⁻¹ hy in have he: ∃ m : ℤ, y ^ m ≤ x, from ⟨-N, le_of_lt (by { rw [fpow_neg y (↑N), gpow_coe_nat], exact (inv_lt hx (lt_trans (inv_pos.2 hx) hN)).1 hN })⟩, let ⟨M, hM⟩ := pow_unbounded_of_one_lt x hy in have hb: ∃ b : ℤ, ∀ m, y ^ m ≤ x → m ≤ b, from ⟨M, λ m hm, le_of_not_lt (λ hlt, not_lt_of_ge (fpow_le_of_le (le_of_lt hy) (le_of_lt hlt)) (lt_of_le_of_lt hm (by rwa ← gpow_coe_nat at hM)))⟩, let ⟨n, hn₁, hn₂⟩ := int.exists_greatest_of_bdd hb he in ⟨n, hn₁, lt_of_not_ge (λ hge, not_le_of_gt (int.lt_succ _) (hn₂ _ hge))⟩ /-- Every positive `x` is between two successive integer powers of another `y` greater than one. This is the same as `exists_int_pow_near`, but with ≤ and < the other way around. -/ lemma exists_int_pow_near' [archimedean α] {x : α} {y : α} (hx : 0 < x) (hy : 1 < y) : ∃ n : ℤ, y ^ n < x ∧ x ≤ y ^ (n + 1) := let ⟨m, hle, hlt⟩ := exists_int_pow_near (inv_pos.2 hx) hy in have hyp : 0 < y, from lt_trans zero_lt_one hy, ⟨-(m+1), by rwa [fpow_neg, inv_lt (fpow_pos_of_pos hyp _) hx], by rwa [neg_add, neg_add_cancel_right, fpow_neg, le_inv hx (fpow_pos_of_pos hyp _)]⟩ /-- For any `y < 1` and any positive `x`, there exists `n : ℕ` with `y ^ n < x`. -/ lemma exists_pow_lt_of_lt_one [archimedean α] {x y : α} (hx : 0 < x) (hy : y < 1) : ∃ n : ℕ, y ^ n < x := begin by_cases y_pos : y ≤ 0, { use 1, simp only [pow_one], linarith, }, rw [not_le] at y_pos, rcases pow_unbounded_of_one_lt (x⁻¹) (one_lt_inv y_pos hy) with ⟨q, hq⟩, exact ⟨q, by rwa [inv_pow', inv_lt_inv hx (pow_pos y_pos _)] at hq⟩ end /-- Given `x` and `y` between `0` and `1`, `x` is between two successive powers of `y`. This is the same as `exists_nat_pow_near`, but for elements between `0` and `1` -/ lemma exists_nat_pow_near_of_lt_one [archimedean α] {x : α} {y : α} (xpos : 0 < x) (hx : x ≤ 1) (ypos : 0 < y) (hy : y < 1) : ∃ n : ℕ, y ^ (n + 1) < x ∧ x ≤ y ^ n := begin rcases exists_nat_pow_near (one_le_inv_iff.2 ⟨xpos, hx⟩) (one_lt_inv_iff.2 ⟨ypos, hy⟩) with ⟨n, hn, h'n⟩, refine ⟨n, _, _⟩, { rwa [inv_pow', inv_lt_inv xpos (pow_pos ypos _)] at h'n }, { rwa [inv_pow', inv_le_inv (pow_pos ypos _) xpos] at hn } end variables [floor_ring α] lemma sub_floor_div_mul_nonneg (x : α) {y : α} (hy : 0 < y) : 0 ≤ x - ⌊x / y⌋ * y := begin conv in x {rw ← div_mul_cancel x (ne_of_lt hy).symm}, rw ← sub_mul, exact mul_nonneg (sub_nonneg.2 (floor_le _)) (le_of_lt hy) end lemma sub_floor_div_mul_lt (x : α) {y : α} (hy : 0 < y) : x - ⌊x / y⌋ * y < y := sub_lt_iff_lt_add.2 begin conv in y {rw ← one_mul y}, conv in x {rw ← div_mul_cancel x (ne_of_lt hy).symm}, rw ← add_mul, exact (mul_lt_mul_right hy).2 (by rw add_comm; exact lt_floor_add_one _), end end linear_ordered_field instance : archimedean ℕ := ⟨λ n m m0, ⟨n, by simpa only [mul_one, nat.nsmul_eq_mul] using nat.mul_le_mul_left n m0⟩⟩ instance : archimedean ℤ := ⟨λ n m m0, ⟨n.to_nat, le_trans (int.le_to_nat _) $ by simpa only [nsmul_eq_mul, int.nat_cast_eq_coe_nat, zero_add, mul_one] using mul_le_mul_of_nonneg_left (int.add_one_le_iff.2 m0) (int.coe_zero_le n.to_nat)⟩⟩ /-- A linear ordered archimedean ring is a floor ring. This is not an `instance` because in some cases we have a computable `floor` function. -/ noncomputable def archimedean.floor_ring (α) [linear_ordered_ring α] [archimedean α] : floor_ring α := { floor := λ x, classical.some (exists_floor x), le_floor := λ z x, classical.some_spec (exists_floor x) z } section linear_ordered_field variables [linear_ordered_field α] theorem archimedean_iff_nat_lt : archimedean α ↔ ∀ x : α, ∃ n : ℕ, x < n := ⟨@exists_nat_gt α _ _, λ H, ⟨λ x y y0, (H (x / y)).imp $ λ n h, le_of_lt $ by rwa [div_lt_iff y0, ← nsmul_eq_mul] at h⟩⟩ theorem archimedean_iff_nat_le : archimedean α ↔ ∀ x : α, ∃ n : ℕ, x ≤ n := archimedean_iff_nat_lt.trans ⟨λ H x, (H x).imp $ λ _, le_of_lt, λ H x, let ⟨n, h⟩ := H x in ⟨n+1, lt_of_le_of_lt h (nat.cast_lt.2 (lt_add_one _))⟩⟩ theorem exists_rat_gt [archimedean α] (x : α) : ∃ q : ℚ, x < q := let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa rat.cast_coe_nat⟩ theorem archimedean_iff_rat_lt : archimedean α ↔ ∀ x : α, ∃ q : ℚ, x < q := ⟨@exists_rat_gt α _, λ H, archimedean_iff_nat_lt.2 $ λ x, let ⟨q, h⟩ := H x in ⟨nat_ceil q, lt_of_lt_of_le h $ by simpa only [rat.cast_coe_nat] using (@rat.cast_le α _ _ _).2 (le_nat_ceil _)⟩⟩ theorem archimedean_iff_rat_le : archimedean α ↔ ∀ x : α, ∃ q : ℚ, x ≤ q := archimedean_iff_rat_lt.trans ⟨λ H x, (H x).imp $ λ _, le_of_lt, λ H x, let ⟨n, h⟩ := H x in ⟨n+1, lt_of_le_of_lt h (rat.cast_lt.2 (lt_add_one _))⟩⟩ variable [archimedean α] theorem exists_rat_lt (x : α) : ∃ q : ℚ, (q : α) < x := let ⟨n, h⟩ := exists_int_lt x in ⟨n, by rwa rat.cast_coe_int⟩ theorem exists_rat_btwn {x y : α} (h : x < y) : ∃ q : ℚ, x < q ∧ (q:α) < y := begin cases exists_nat_gt (y - x)⁻¹ with n nh, cases exists_floor (x * n) with z zh, refine ⟨(z + 1 : ℤ) / n, _⟩, have n0' := (inv_pos.2 (sub_pos.2 h)).trans nh, have n0 := nat.cast_pos.1 n0', rw [rat.cast_div_of_ne_zero, rat.cast_coe_nat, rat.cast_coe_int, div_lt_iff n0'], refine ⟨(lt_div_iff n0').2 $ (lt_iff_lt_of_le_iff_le (zh _)).1 (lt_add_one _), _⟩, rw [int.cast_add, int.cast_one], refine lt_of_le_of_lt (add_le_add_right ((zh _).1 (le_refl _)) _) _, rwa [← lt_sub_iff_add_lt', ← sub_mul, ← div_lt_iff' (sub_pos.2 h), one_div], { rw [rat.coe_int_denom, nat.cast_one], exact one_ne_zero }, { intro H, rw [rat.coe_nat_num, ← coe_coe, nat.cast_eq_zero] at H, subst H, cases n0 }, { rw [rat.coe_nat_denom, nat.cast_one], exact one_ne_zero } end theorem exists_nat_one_div_lt {ε : α} (hε : 0 < ε) : ∃ n : ℕ, 1 / (n + 1: α) < ε := begin cases exists_nat_gt (1/ε) with n hn, use n, rw [div_lt_iff, ← div_lt_iff' hε], { apply hn.trans, simp [zero_lt_one] }, { exact n.cast_add_one_pos } end theorem exists_pos_rat_lt {x : α} (x0 : 0 < x) : ∃ q : ℚ, 0 < q ∧ (q : α) < x := by simpa only [rat.cast_pos] using exists_rat_btwn x0 end linear_ordered_field section variables [linear_ordered_field α] [floor_ring α] /-- `round` rounds a number to the nearest integer. `round (1 / 2) = 1` -/ def round (x : α) : ℤ := ⌊x + 1 / 2⌋ @[simp] lemma round_zero : round (0 : α) = 0 := floor_eq_iff.2 (by norm_num) @[simp] lemma round_one : round (1 : α) = 1 := floor_eq_iff.2 (by norm_num) lemma abs_sub_round (x : α) : abs (x - round x) ≤ 1 / 2 := begin rw [round, abs_sub_le_iff], have := floor_le (x + 1 / 2), have := lt_floor_add_one (x + 1 / 2), split; linarith end @[simp, norm_cast] theorem rat.cast_floor (x : ℚ) : ⌊(x:α)⌋ = ⌊x⌋ := floor_eq_iff.2 (by exact_mod_cast floor_eq_iff.1 (eq.refl ⌊x⌋)) @[simp, norm_cast] theorem rat.cast_ceil (x : ℚ) : ⌈(x:α)⌉ = ⌈x⌉ := by rw [ceil, ← rat.cast_neg, rat.cast_floor, ← ceil] @[simp, norm_cast] theorem rat.cast_round (x : ℚ) : round (x:α) = round x := have ((x + 1 / 2 : ℚ) : α) = x + 1 / 2, by simp, by rw [round, round, ← this, rat.cast_floor] end section variables [linear_ordered_field α] [archimedean α] theorem exists_rat_near (x : α) {ε : α} (ε0 : 0 < ε) : ∃ q : ℚ, abs (x - q) < ε := let ⟨q, h₁, h₂⟩ := exists_rat_btwn $ lt_trans ((sub_lt_self_iff x).2 ε0) ((lt_add_iff_pos_left x).2 ε0) in ⟨q, abs_sub_lt_iff.2 ⟨sub_lt.1 h₁, sub_lt_iff_lt_add.2 h₂⟩⟩ instance : archimedean ℚ := archimedean_iff_rat_le.2 $ λ q, ⟨q, by rw rat.cast_id⟩ end
//================================================================================================== /*! @file @copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ //================================================================================================== #ifndef BOOST_SIMD_FUNCTION_SINCOSPI_HPP_INCLUDED #define BOOST_SIMD_FUNCTION_SINCOSPI_HPP_INCLUDED #if defined(DOXYGEN_ONLY) namespace boost { namespace simd { /*! @ingroup group-trigonometric This function object computes simultaneously and at lower cost the sine and cosine of the input in \f$\pi\f$ multiples. @par Header <boost/simd/function/sincospi.hpp> @see sincosd, sincos @par Example: @snippet sincospi.cpp sincospi @par Possible output: @snippet sincospi.txt sincospi **/ std::pair<IEEEValue, IEEEValue> sincospi(IEEEValue const& x); } } #endif #include <boost/simd/function/scalar/sincospi.hpp> #include <boost/simd/function/simd/sincospi.hpp> #endif
-- Copyright 2017-2018 The Lathe Authors -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -- either express or implied. See the License for the specific -- language governing permissions and limitations under the License. Let's represent towers as towers of one less degree where the highest-degree holes are now contained in the islands. So ^`( ~`( ,( ,( ) ) ) ) is to be represented like so: `( something ,( ) something ) Islands must have an overall balanced structure to them. The first "something" island opens the higher-degree hole, and the second "something" closes it. A single island may close and open many holes, and it may even dip into a hole without closing it, like the middle part of this: ^`( ~`( ,( ,( ) ) ,( ,( ) ) ) ) `( ------ ,( ) ---- ,( ) --- ) As a lower-degree example, `( ,( ) ) is to be represented like so: ( something ) Clearly, everything at that degree will be represented as "( something )" for some value of "something," so that can be the base case of our representation. exprOf : Nat -> Type -> Type exprOf d i = Expr d 0 (\_ _ -> ()) i exprBranchType : (d : Nat) -> (c : Nat -> Nat -> Type) -> (i : Type) -> Type exprBranchType = (nextStartingDepth : Nat) * (i * exprOf d (Expr (1 + d) nextStartingDepth c i)) exprMap : (d : Nat) -> (startingDepth : Nat) -> (c : Nat -> Nat -> Type) -> (i : Type) -> (i' : type) -> (i -> i') -> Expr d startingDepth c i -> Expr d startingDepth c i' exprMap d startingDepth c i i' f expr = case expr of exprNil d'' s'' c'' i'' content'' => exprNil d'' s'' c'' i' content'' exprCons d'' startingDepth'' c'' i'' branches'' content'' => exprCons d'' startingDepth'' c'' i' (exprMap d'' startingDepth'' c'' (exprBranchType d'' c'' i'') (exprBranchType d'' c'' i') (\(nextStartingDepth * (iVal * branches)) -> nextStartingDepth * (f iVal * exprMap d'' 0 (\_ _ -> ()) (Expr d nextStartingDepth c'' i'') (Expr d nextStartingDepth c'' i') (exprMap d nextStartingDepth c'' i'' i' f) branches)) branches'') type Expr (degree : Nat) (startingDepth : Nat) (content : Nat -> exprOf d Nat -> Type) (interpolation : Type) where exprNil : (d : Nat) -> (s : Nat) -> (c : Nat -> exprOf d Nat -> Type) -> (i : Type) -> c s (exprNil d 0 (\_ _ -> ()) Nat) -> Expr (1 + d) s c i exprCons : (d : Nat) -> (startingDepth : Nat) -> (c : Nat -> Nat -> Type) -> (i : Type) -> (branches : exprOf d (exprBranchType d c i)) -> c startingDepth (exprMap d 0 (\_ _ -> ()) (exprBranchType d c i) Nat (\(nextStartingDepth * _) -> nextStartingDepth) branches) -> Expr (1 + d) startingDepth c i -- TODO: Whoops, the above `Expr` has no constructors for degree 0, -- and its constructors for degrees greater than 0 aren't using island -- content values to represent higher-degree holes. Finish making a -- version of expr which does this, below. vec : Nat -> Type -> Type vec n t = case n of 0 => () * () 1 + n' => t * vec n' t exprInfoType : Nat -> Type exprInfoType degree = case degree of 0 => (balanceStateType : Type) * let bl = List balanceStateType in (bl -> () -> Type) * (bl -> () -> Type) 1 + degree' => (balanceStateType : Type) * let bl = List balanceStateType in (bl -> exprOf degree' bl -> Type) * (bl -> exprOf degree' bl -> Type) type List (a : Type) where nil : (a : Type) -> List a cons : (a : Type) -> a -> List a -> List a exprInfo : (degree : Nat) -> (balanceStateType0 : Type) -> (List balanceStateType0 -> Type) -> (List balanceStateType0 -> Type) -> exprInfoType degree exprInfo degree balanceStateType0 i0 l0 = case degree of 0 => balanceStateType0 * (\currentBalance () -> i0 currentBalance) * (\currentBalance () -> l0 currentBalance) 1 + degree' => let balanceStateTypeN * iN * lN = exprInfo degree' balanceStateType0 i0 l0 in List balanceStateTypeN * (\currentBalance edge -> Expr degree' (balanceStateTypeN * iN * (\currentBalance edge -> (case currentBalance of nil subBalanceType => Bot cons subBalanceType subBalance subBalances => exprOf degree' ( (E) + ())) + ()) (nil balanceStateTypeN)) * (\currentBalance edge -> ()) island : Nat -> (balanceStateType : Type) -> balanceStateType -> Type island degree balanceStateType startingBalance = Expr degree Nat c' type Expr (degree : Nat) (balanceStateType * i * l * ti : exprInfoType degree) List balanceStateType where expr : (d : Nat) -> (balanceStateType : Type) -> (balanceStateType * i * l * ti : exprInfoType d) -> (startingBalance : List balanceStateType) -> (case d of 0 => () * i startingBalance () 1 + d' => let balanceStateType' * i' * l' * ti' = ti in (e : Expr d' ti ( -- TODO: Implement island. (island d' balanceStateType c (lakeType * lakeTypes) startingBalance) lakeTypes 0) * i startingBalance -- TODO: Implement exprMap, and pass it whatever other -- arguments it needs here. (exprMap (\newStartingBalance lake -> newStartingBalance) e)) -> Expr d balanceStateType c (lakeType * lakeTypes) startingBalance that degree we only have a single "something" in the representation no
[STATEMENT] theorem (in Group) iso_class_reps : defines "GIRRS \<equiv> GIrrRep_repset :: ('f::field,'g) aezfun set set" assumes "of_nat (card G) \<noteq> (0::'f)" shows "finite GIRRS" "\<forall>U\<in>GIRRS. IrrFinGroupRepresentation G (*) U" "\<And>U W. \<lbrakk> U \<in> GIRRS; W \<in> GIRRS; U \<noteq> W \<rbrakk> \<Longrightarrow> \<not> (FGModule.isomorphic G (*) U (*) W)" "\<And>fgsmult V. IrrFinGroupRepresentation G fgsmult V \<Longrightarrow> \<exists>U\<in>GIRRS. FGModule.isomorphic G fgsmult V (*) U" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (finite GIRRS &&& \<forall>U\<in>GIRRS. IrrFinGroupRepresentation G (*) U) &&& (\<And>U W. \<lbrakk>U \<in> GIRRS; W \<in> GIRRS; U \<noteq> W\<rbrakk> \<Longrightarrow> \<nexists>T. FGModuleIso G (*) U (*) T W) &&& (\<And>fgsmult V. IrrFinGroupRepresentation G fgsmult V \<Longrightarrow> \<exists>U\<in>GIRRS. \<exists>T. FGModuleIso G fgsmult V (*) T U) [PROOF STEP] using assms finite_GIrrRep_repset all_irr_GIrrRep_repset isodistinct_GIrrRep_repset IrrFinGroupRepresentation.iso_to_GIrrRep_rep [PROOF STATE] proof (prove) using this: GIRRS \<equiv> GIrrRep_repset of_nat (card G) \<noteq> (0::'f) finite GIrrRep_repset of_nat (card G) \<noteq> (0::?'f) \<Longrightarrow> \<forall>U\<in>GIrrRep_repset. IrrFinGroupRepresentation G (*) U \<lbrakk>of_nat (card G) \<noteq> (0::?'f); ?V \<in> GIrrRep_repset; ?W \<in> GIrrRep_repset; ?V \<noteq> ?W\<rbrakk> \<Longrightarrow> \<nexists>T. FGModuleIso G (*) ?V (*) T ?W IrrFinGroupRepresentation ?G ?smult ?V \<Longrightarrow> \<exists>U\<in>Group.GIrrRep_repset ?G. \<exists>T. FGModuleIso ?G ?smult ?V (*) T U goal (1 subgoal): 1. (finite GIRRS &&& \<forall>U\<in>GIRRS. IrrFinGroupRepresentation G (*) U) &&& (\<And>U W. \<lbrakk>U \<in> GIRRS; W \<in> GIRRS; U \<noteq> W\<rbrakk> \<Longrightarrow> \<nexists>T. FGModuleIso G (*) U (*) T W) &&& (\<And>fgsmult V. IrrFinGroupRepresentation G fgsmult V \<Longrightarrow> \<exists>U\<in>GIRRS. \<exists>T. FGModuleIso G fgsmult V (*) T U) [PROOF STEP] by auto
function [I] = imgread(img, c) % % Copyright Aditya Khosla http://mit.edu/khosla % % Please cite this paper if you use this code in your publication: % A. Khosla, J. Xiao, A. Torralba, A. Oliva % Memorability of Image Regions % Advances in Neural Information Processing Systems (NIPS) 2012 % if(ischar(img)) I = imread(img); else I=img; end scale = min(min(c.maxsize/size(I, 1), c.maxsize/size(I, 2)), 1); if(scale~=1) I = imresize(I, scale); end if(size(I,3)==1) I=cat(3, I, I, I); end
stop("need to assign directories") project.dir <- ... ## base directory of the project (contains working/data/ folder) aries.dir <- ... ## location of ALSPAC methylation data alspac.dir <- ... ## location of ALSPAC questionnaire and clinic data
I am inspired by the Russian communist wiki:WikiPedia:Alexandra_Kollontai Alexandra Kollontai. I am a proponent of free love, socialist feminism, and cant wait for the withering away of the family. Signed up 20057 20070228 23:11 nbsp Consider using your Importance of using your RealName real name. Users/JasonAller
State Before: α : Type u_1 β : Type u_2 γ : Type u_3 inst✝¹ : CommMonoid α inst✝ : CommMonoid β s : Finset γ f : γ → α g : γ → β this : DecidableEq γ ⊢ ∀ ⦃a : γ⦄ {s : Finset γ}, ¬a ∈ s → (∏ x in s, f x, ∏ x in s, g x) = ∏ x in s, (f x, g x) → (∏ x in insert a s, f x, ∏ x in insert a s, g x) = ∏ x in insert a s, (f x, g x) State After: no goals Tactic: simp (config := { contextual := true }) [Prod.ext_iff]
import definitions import point3 import data.nat.prime open nat /-- point 4, first part-/ lemma luc_fib (m : ℕ) : luc (m + 3) = 2 * fib (m + 3) + fib m := int.coe_nat_inj $ by rw [int.coe_nat_add, int.coe_nat_mul]; rw [← fib_down, ← fib_down, ← luc_down, Luc, Fib, Fib]; rw [α_Fib, α_Fib, β_Fib]; dsimp; rw [add_neg_cancel_right]; repeat { rw Fib_add_one_add_one }; simp [add_mul] lemma fib_succ_coprime (m : ℕ) : coprime (fib (m + 1)) (fib m) := nat.rec_on m dec_trivial $ λ n ih, show gcd (fib n + fib (n+1)) (fib (n+1)) = 1, by rw [nat.gcd_add, nat.gcd_comm, coprime.gcd_eq_one ih] lemma gcd_fib_luc_dvd_two (m : ℕ) : gcd (fib m) (luc m) ∣ 2 := nat.cases_on m dec_trivial $ λ n, nat.cases_on n dec_trivial $ λ n, nat.cases_on n dec_trivial $ λ n, show gcd (fib (n+3)) (luc (n+3)) ∣ 2, by rw [luc_fib, nat.gcd_comm, add_comm, nat.gcd_add_mul_right]; change gcd (fib n) (fib (n+1) + (fib n + fib (n+1))) ∣ 2; rw [nat.gcd_comm, add_left_comm, add_comm, nat.gcd_add, ← mul_two]; rw [coprime.gcd_mul_left_cancel 2 (fib_succ_coprime n)]; apply nat.gcd_dvd_left -- Prime trick thanks to Chris and Mario. /-- point 4, last part-/ lemma gcd_fib_luc_one_or_two (m : ℕ) : gcd (fib m) (luc m) = 1 ∨ gcd (fib m) (luc m) = 2 := (dvd_prime prime_two).1 $ gcd_fib_luc_dvd_two m
/- Copyright (c) 2021 Manuel Candales. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Manuel Candales -/ import data.real.basic import data.set.basic import data.set.finite /-! # IMO 2008 Q2 (a) Prove that ``` x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 ≥ 1 ``` for all real numbers `x`,`y`, `z`, each different from 1, and satisfying `xyz = 1`. (b) Prove that equality holds above for infinitely many triples of rational numbers `x`, `y`, `z`, each different from 1, and satisfying `xyz = 1`. # Solution (a) Since `xyz = 1`, we can apply the substitution `x = a/b`, `y = b/c`, `z = c/a`. Then we define `m = c-b`, `n = b-a` and rewrite the inequality as `LHS - 1 ≥ 0` using `c`, `m` and `n`. We factor `LHS - 1` as a square, which finishes the proof. (b) We present a set `W` of rational triples. We prove that `W` is a subset of the set of rational solutions to the equation, and that `W` is infinite. -/ lemma subst_abc {x y z : ℝ} (h : x*y*z = 1) : ∃ a b c : ℝ, a ≠ 0 ∧ b ≠ 0 ∧ c ≠ 0 ∧ x = a/b ∧ y = b/c ∧ z = c /a := begin use [x, 1, 1/y], obtain ⟨⟨hx, hy⟩, hz⟩ : (x ≠ 0 ∧ y ≠ 0) ∧ z ≠ 0, by simpa [not_or_distrib] using trans_rel_right (≠) h one_ne_zero, have : z * (y * x) = 1, by { rw ← h, ac_refl }, field_simp * end theorem imo2008_q2a (x y z : ℝ) (h : x*y*z = 1) (hx : x ≠ 1) (hy : y ≠ 1) (hz : z ≠ 1) : x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 ≥ 1 := begin obtain ⟨a, b, c, ha, hb, hc, rfl, rfl, rfl⟩ := subst_abc h, obtain ⟨m, n, rfl, rfl⟩ : ∃ m n, b = c - m ∧ a = c - m - n, { use [c - b, b - a], simp }, have hm_ne_zero : m ≠ 0, { contrapose! hy, field_simp, assumption }, have hn_ne_zero : n ≠ 0, { contrapose! hx, field_simp, assumption }, have hmn_ne_zero : m + n ≠ 0, { contrapose! hz, field_simp, linarith }, have hc_sub_sub : c - (c - m - n) = m + n, by abel, rw [ge_iff_le, ← sub_nonneg], convert sq_nonneg ((c*(m^2+n^2+m*n) - m*(m+n)^2) / (m*n*(m+n)) ), field_simp *, ring end def rational_solutions := { s : ℚ×ℚ×ℚ | ∃ (x y z : ℚ), s = (x, y, z) ∧ x ≠ 1 ∧ y ≠ 1 ∧ z ≠ 1 ∧ x*y*z = 1 ∧ x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2 = 1 } theorem imo2008_q2b : set.infinite rational_solutions := begin let W := { s : ℚ×ℚ×ℚ | ∃ (x y z : ℚ), s = (x, y, z) ∧ ∃ t : ℚ, t > 0 ∧ x = -(t+1)/t^2 ∧ y = t/(t+1)^2 ∧ z = -t*(t+1)}, have hW_sub_S : W ⊆ rational_solutions, { intros s hs_in_W, rw rational_solutions, simp only [set.mem_set_of_eq] at hs_in_W ⊢, rcases hs_in_W with ⟨x, y, z, h₁, t, ht_gt_zero, hx_t, hy_t, hz_t⟩, use [x, y, z], have ht_ne_zero : t ≠ 0, exact ne_of_gt ht_gt_zero, have ht1_ne_zero : t+1 ≠ 0, linarith[ht_gt_zero], have key_gt_zero : t^2 + t + 1 > 0, linarith[pow_pos ht_gt_zero 2, ht_gt_zero], have key_ne_zero : t^2 + t + 1 ≠ 0, exact ne_of_gt key_gt_zero, have h₂ : x ≠ 1, { rw hx_t, field_simp, linarith[key_gt_zero] }, have h₃ : y ≠ 1, { rw hy_t, field_simp, linarith[key_gt_zero] }, have h₄ : z ≠ 1, { rw hz_t, linarith[key_gt_zero] }, have h₅ : x*y*z = 1, { rw [hx_t, hy_t, hz_t], field_simp, ring }, have h₆ : x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2 = 1, { have hx1 : (x - 1)^2 = (t^2 + t + 1)^2/t^4, { field_simp, rw hx_t, field_simp, ring }, have hy1 : (y - 1)^2 = (t^2 + t + 1)^2/(t+1)^4, { field_simp, rw hy_t, field_simp, ring }, have hz1 : (z - 1)^2 = (t^2 + t + 1)^2, { rw hz_t, ring }, calc x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2 = (x^2*t^4 + y^2*(t+1)^4 + z^2)/(t^2 + t + 1)^2 : by { rw [hx1, hy1, hz1], field_simp } ... = 1 : by { rw [hx_t, hy_t, hz_t], field_simp, ring } }, exact ⟨h₁, h₂, h₃, h₄, h₅, h₆⟩ }, have hW_inf : set.infinite W, { let g : ℚ×ℚ×ℚ → ℚ := (λs, -s.2.2), let K := g '' W, have hK_not_bdd : ¬bdd_above K, { rw not_bdd_above_iff, intro q, let t : ℚ := max (q+1) 1, use t*(t+1), have h₁ : t * (t + 1) ∈ K, { let x : ℚ := -(t + 1)/t^2, let y : ℚ := t/(t+1)^2, set z : ℚ := -t*(t+1) with hz_def, simp only [set.mem_image, prod.exists], use [x, y, z], split, simp only [set.mem_set_of_eq], { use [x, y, z], split, refl, { use t, split, { simp only [gt_iff_lt, lt_max_iff], right, exact zero_lt_one }, exact ⟨rfl, rfl, rfl⟩ } }, { have hg : g(x, y, z) = -z := rfl, rw [hg, hz_def], ring } }, have h₂ : q < t * (t + 1), { calc q < q + 1 : by linarith ... ≤ t : le_max_left (q + 1) 1 ... ≤ t+t^2 : by linarith [sq_nonneg t] ... = t*(t+1) : by ring }, exact ⟨h₁, h₂⟩ }, have hK_inf : set.infinite K, { intro h, apply hK_not_bdd, exact set.finite.bdd_above h }, exact set.infinite_of_infinite_image g hK_inf }, exact hW_inf.mono hW_sub_S, end
module LeastSquares ( VarName , LinExpr(..) , LinContr(..) , QuadExpr(..) , minimize ) where import Data.List (elemIndex, foldl1') import qualified Data.Map.Strict as M import Data.Maybe (fromJust) import qualified Data.Set as S import Numeric.LinearAlgebra type VarName = String type CanonicalMap = M.Map VarName (Matrix R) infix 4 :==: data LinExpr = Var VarName Int | Coeff R | Vec (Vector R) | Mat (Matrix R) | Neg LinExpr | Sum LinExpr LinExpr | Prod LinExpr LinExpr deriving (Show, Eq) instance Num LinExpr where (+) = Sum a - b = Sum a (Neg b) (*) = Prod negate = Neg signum = undefined abs = undefined fromInteger a = Coeff (fromInteger a) data LinContr = LinExpr :==: LinExpr data QuadExpr = SumSquares LinExpr | CoeffQuad R | ProdQuad QuadExpr QuadExpr | SumQuad QuadExpr QuadExpr instance Num QuadExpr where (+) = SumQuad (*) = ProdQuad (-) = undefined negate = undefined signum = undefined abs = undefined fromInteger a = CoeffQuad (fromInteger a) class CanonExpr e where varSet :: e -> S.Set (VarName, Int) canonicalize :: e -> CanonicalMap -- Canonicalize a generic expression -- The vector is stored as a column matrix under the variable "". instance CanonExpr LinExpr where varSet (Var v s) = S.singleton (v, s) varSet (Coeff _) = S.empty varSet (Vec _) = S.empty varSet (Mat _) = S.empty varSet (Neg e) = varSet e varSet (Prod _ e) = varSet e varSet (Sum e1 e2) = varSet e1 `S.union` varSet e2 canonicalize (Var v s) = M.singleton v (ident s) canonicalize (Vec v) = M.singleton "" (asColumn v) canonicalize (Neg e) = M.map negate $ canonicalize e canonicalize (Prod (Coeff c) e) = M.map (scale c) $ canonicalize e canonicalize (Prod (Mat m) e) = M.map (m <>) $ canonicalize e canonicalize (Sum e1 e2) = M.unionWith (+) (canonicalize e1) (canonicalize e2) canonicalize _ = error "Expression is not well-formed" -- Canonicalize an expression in the constraint instance CanonExpr LinContr where varSet (e1 :==: e2) = varSet e1 `S.union` varSet e2 canonicalize (e1 :==: e2) = canonicalize (e1 - e2) -- Canonicalize an expression in the objective, which consists of SumSquares. instance CanonExpr QuadExpr where varSet (SumSquares e) = varSet e varSet (CoeffQuad _) = S.empty varSet (ProdQuad _ e) = varSet e varSet (SumQuad e1 e2) = varSet e1 `S.union` varSet e2 canonicalize (SumSquares e) = canonicalize e canonicalize (ProdQuad (CoeffQuad c) e) = M.map (scale (sqrt c)) $ canonicalize e canonicalize (SumQuad e1 e2) = canonicalize e1 `vstack` canonicalize e2 canonicalize _ = error "Expression is not well-formed" -- Combine two canonical maps by stacking one on top of another. vstack :: CanonicalMap -> CanonicalMap -> CanonicalMap vstack m1 m2 = M.fromSet combine (M.keysSet m1 `S.union` M.keysSet m2) where combine k = lookupDefault k m1 === lookupDefault k m2 lookupDefault k m = M.findWithDefault (konst 0 (firstDim m, 1)) k m firstDim = rows . snd . fromJust . M.lookupGE "" :: CanonicalMap -> Int minimize :: QuadExpr -> [LinContr] -> M.Map VarName (Vector R) minimize obj [] = unpack vars $ a <\> (-b) where (a,b) = pack vars . canonicalize $ obj vars = varSet obj minimize obj constraints = unpack vars $ mat <\> (-vec) where mat = fromBlocks [[2 * tr a <> a, tr c], [c, 0]] vec = vjoin [2 * tr a #> b, d] (a,b) = pack vars . canonicalize $ obj (c,d) = pack vars $ foldl1' vstack cds cds = map canonicalize constraints vars = varSet obj `S.union` S.unions (map varSet constraints) pack :: S.Set (VarName, Int) -> CanonicalMap -> (Matrix R, Vector R) pack vars m = (a, b) where a = fromBlocks [map getCoefficient (S.toAscList vars)] b = flatten $ M.findWithDefault (konst 0 (rows a, 1)) "" m getCoefficient (varName,s) = M.findWithDefault (konst 0 (s, s)) varName m -- The vector given to unpack might be longer than the total size of the -- variables. It might contain the dual variable values, for example. unpack :: S.Set (VarName, Int) -> Vector R -> M.Map VarName (Vector R) unpack vars result = M.fromList $ zip varNames coefficients where coefficients = map getCoefficient varList getCoefficient (varName,s) = subVector (startIndex varName) s result startIndex varName = cumsum !! fromJust (elemIndex varName varNames) cumsum = scanl (+) 0 varSizes (varNames,varSizes) = unzip varList varList = S.toAscList vars
Require Import Equations.Prop.Equations. Inductive term : Set := | Var (n : nat) | App (t : term) (l : list term). Equations id_term (t : term) : term := { id_term (Var n) := Var n; id_term (App t l) := App (id_term t) (id_tlist l) } where id_tlist (t : list term) : list term := { id_tlist nil := nil; id_tlist (cons t ts) := cons (id_term t) (id_tlist ts) }. Definition check := eq_refl : List.map id_term = id_tlist.
Vintage Metal Chairs. Vintage Steel Desk Chair Inside Metal Chairs Idea 7. Vintage Metal Chairs Wayfair For Inspirations 17. Metal Lawn Chair EBay Throughout Vintage Chairs Design 3. For SALE Vintage Metal Chairs From Bali By Bjørkheim With Designs 13. How To Paint Vintage Metal Chairs Gardening Pinterest Inside Design 6. Top The Village Of Retro Furniture Vintage Metal Dining Chair Anti Pertaining To Chairs Design 4. Amazon Com Vintage Tabouret Stacking Chair Set Of 4 Steel With Metal Chairs Plan 0. Shop Jasper Laine Vintage Metal Dining Chairs Set Of 2 Free Inside Design 9. Coral Coast Paradise Cove Retro Metal Arm Chair Walmart Com Regarding Vintage Chairs Decor 1. Magnussen Home Stovall Vintage Metal Dining Chair AHFA Throughout Chairs Plans 18. Vintage Metal Folding Chair Green Chairs Throughout Decor 14. Vintage Metal Furniture VINTAGE METAL CHAIRS Pinterest Porch Intended For Chairs Designs 8.
// Package Path Definition #include <Configuration.h> // Import ROS and Rviz visualization #include <ros/ros.h> #include "geometry_msgs/PoseStamped.h" #include "geometry_msgs/PoseArray.h" #include "geometry_msgs/Pose.h" #include <tf/transform_listener.h> #include <avatar_locomanipulation/visualization_nodes/bag_visualization_node.hpp> #include <avatar_locomanipulation/helpers/yaml_data_saver.hpp> #include <avatar_locomanipulation/helpers/param_handler.hpp> #include <iostream> #include <fstream> #include <math.h> #include <boost/function.hpp> #include <boost/bind.hpp> void visualize_bag_and_waypoints(geometry_msgs::PoseArray & waypoints){ // Initialize ROS node for publishing joint messages ros::NodeHandle n; ros::Rate loop_rate(20); std::string parameter = "hand_trajectory/bag_lift_putdown_parameters.yaml"; BagVisualizationNode bag_obj(&n, parameter); // Waypoint Pose Publisher ros::Publisher hand_pose_pub = n.advertise<geometry_msgs::PoseArray>("waypoint_poses", 100); // Initialize Transforms and Messages ros::Publisher bag_viz_pub = n.advertise<visualization_msgs::MarkerArray>("bag_visualization", 1000); visualization_msgs::MarkerArray bag_msg; bag_obj.fillBagMarkerArray(bag_msg); // Transform Broadcasters for getting the wp1 in world then hinge in wp1 // Initialize Transforms and Messages tf::TransformBroadcaster br_center; tf::TransformBroadcaster br_bag; // The transforms tf::Transform tf_world_center; tf::Transform tf_center_bag; // tf::Transform tf_wp1_hinge; bag_obj.s_sub = bag_obj.nh->subscribe<std_msgs::Float64>("/s_value", 1, boost::bind(&BagVisualizationNode::s_callback, &bag_obj, _1)); while (ros::ok()){ bag_obj.getVizInformation(tf_world_center, tf_center_bag); br_center.sendTransform(tf::StampedTransform(tf_world_center, ros::Time::now(), "world", "center_frame")); br_bag.sendTransform(tf::StampedTransform(tf_center_bag, ros::Time::now(), "center_frame", "bag_frame")); bag_viz_pub.publish(bag_msg); hand_pose_pub.publish(waypoints); ros::spinOnce(); loop_rate.sleep(); } } int main(int argc, char **argv){ ros::init(argc, argv, "bag_visualization"); // Initialize Param Handler ParamHandler param_handler; // Initialize the waypoint posearray geometry_msgs::PoseArray waypoint_poses; // Initialize the temp poses for building ^ geometry_msgs::Pose temp; // Load the yaml file param_handler.load_yaml_file(THIS_PACKAGE_PATH"hand_trajectory/bag_lift_turn_putdown_trajectory.yaml"); int num_wps; param_handler.getInteger("num_waypoints", num_wps); std::string waypoint_string; double x, y, z, rx, ry, rz, rw; waypoint_poses.header.frame_id = "center_frame"; for(int i=1; i<=num_wps; ++i){ waypoint_string = "waypoint_" + std::to_string(i); param_handler.getNestedValue({waypoint_string, "x"}, x); param_handler.getNestedValue({waypoint_string, "y"}, y); param_handler.getNestedValue({waypoint_string, "z"}, z); param_handler.getNestedValue({waypoint_string, "rx"}, rx); param_handler.getNestedValue({waypoint_string, "ry"}, ry); param_handler.getNestedValue({waypoint_string, "rz"}, rz); param_handler.getNestedValue({waypoint_string, "rw"}, rw); temp.position.x = x; temp.position.y = y; temp.position.z = z; temp.orientation.x = rx; temp.orientation.y = ry; temp.orientation.z = rz; temp.orientation.w = rw; waypoint_poses.poses.push_back(temp); } visualize_bag_and_waypoints(waypoint_poses); }
/* specfunc/bessel_Y0.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Author: G. Jungman */ #include <config.h> #include <gsl/gsl_math.h> #include <gsl/gsl_errno.h> #include "gsl_sf_trig.h" #include "gsl_sf_bessel.h" #include "error.h" #include "bessel.h" #include "bessel_amp_phase.h" #include "cheb_eval.c" /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/ /* based on SLATEC besy0, 1980 version, w. fullerton */ /* chebyshev expansions series for by0 on the interval 0. to 1.60000d+01 with weighted error 1.20e-17 log weighted error 16.92 significant figures required 16.15 decimal places required 17.48 */ static double by0_data[13] = { -0.011277839392865573, -0.128345237560420350, -0.104378847997942490, 0.023662749183969695, -0.002090391647700486, 0.000103975453939057, -0.000003369747162423, 0.000000077293842676, -0.000000001324976772, 0.000000000017648232, -0.000000000000188105, 0.000000000000001641, -0.000000000000000011 }; static cheb_series by0_cs = { by0_data, 12, -1, 1, 8 }; /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/ int gsl_sf_bessel_Y0_e(const double x, gsl_sf_result * result) { const double two_over_pi = 2.0/M_PI; const double xmax = 1.0/GSL_DBL_EPSILON; /* CHECK_POINTER(result) */ if (x <= 0.0) { DOMAIN_ERROR(result); } else if(x < 4.0) { gsl_sf_result J0; gsl_sf_result c; int stat_J0 = gsl_sf_bessel_J0_e(x, &J0); cheb_eval_e(&by0_cs, 0.125*x*x-1.0, &c); result->val = two_over_pi*(-M_LN2 + log(x))*J0.val + 0.375 + c.val; result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val) + c.err; return stat_J0; } else if(x < xmax) { /* Leading behaviour of phase is x, which is exact, * so the error is bounded. */ const double z = 32.0/(x*x) - 1.0; gsl_sf_result c1; gsl_sf_result c2; gsl_sf_result sp; const int stat_c1 = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bm0_cs, z, &c1); const int stat_c2 = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bth0_cs, z, &c2); const int stat_sp = gsl_sf_bessel_sin_pi4_e(x, c2.val/x, &sp); const double sqrtx = sqrt(x); const double ampl = (0.75 + c1.val) / sqrtx; result->val = ampl * sp.val; result->err = fabs(sp.val) * c1.err/sqrtx + fabs(ampl) * sp.err; result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); return GSL_ERROR_SELECT_3(stat_sp, stat_c1, stat_c2); } else { UNDERFLOW_ERROR(result); } } /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/ #include "eval.h" double gsl_sf_bessel_Y0(const double x) { EVAL_RESULT(gsl_sf_bessel_Y0_e(x, &result)); }
Require Import Bedrock. Import DefineStructured. Section Lambda. Variable imports : LabelMap.t assert. Hypothesis imports_global : importsGlobal imports. Variable modName : string. Variable body : cmd imports modName. Variable precondition : assert. Hint Extern 1 (_ < _)%N => nomega. Hint Extern 1 (not (@eq LabelMap.key _ _)) => lomega. Hint Extern 1 (@eq LabelMap.key _ _ -> False) => lomega. Hint Extern 1 (LabelMap.MapsTo _ _ _) => apply imps_exit. Transparent evalInstrs. Definition Lambda__ : cmd imports modName. red; refine (fun pre => let cout := body precondition in {| Postcondition := (fun st => Ex st', Ex fp, [| evalInstrs (fst st) st' (Assign Rp (RvImm fp) :: nil) = Some (snd st) |] /\ pre (fst st, st') /\ Cptr fp precondition)%PropX; VerifCond := (forall specs st, ~interp specs (cout.(Postcondition) st)) :: cout.(VerifCond); Generate := fun Base Exit => let cg := Generate cout (Nsucc (Nsucc Base)) Base in {| Entry := 1; Blocks := (cout.(Postcondition), (nil, Uncond (RvLabel (modName, Local Base)))) :: (pre, (Assign Rp (RvLabel (modName, Local (Nsucc (Nsucc Base) + cg.(Entry)))) :: nil, Uncond (RvLabel (modName, Local Exit)))) :: cg.(Blocks) |} |}); abstract (struct; repeat match goal with | [ H : forall k v, _ |- context[match Labels _ ?k with None => _ | _ => _ end] ] => edestruct (H k); eauto; intuition; match goal with | [ H : _ = _ |- _ ] => rewrite H end end; repeat esplit; eauto; propxFo; eauto). Defined. End Lambda. Definition Lambda_ (vars : list string) (pre : spec) (Body : chunk) : chunk := fun ns res => Structured nil (fun im mn H => Lambda__ im H mn (toCmd ($[Sp+0] <- Rp;; (fun _ _ => Structured nil (fun im mn _ => Structured.Assert_ im mn (Precondition pre (Some vars))));; (fun ns res => Body ns (res - (List.length vars - List.length (Formals pre)))%nat))%SP mn H vars (Reserved pre)) (Precondition pre None)). Notation "rv <-- 'Lambda' () [ p ] b 'end'" := (Seq (Lambda_ nil p b) (Assign' rv Rp)) (no associativity, at level 95, f at level 0) : SP_scope. Notation "rv <-- 'Lambda' ( x1 , .. , xN ) [ p ] b 'end'" := (Seq (Lambda_ (cons x1 (.. (cons xN nil) ..)) p b) (Assign' rv Rp)) (no associativity, at level 95, f at level 0) : SP_scope.
import multiset data.fintype.basic linear_algebra.dimension set_pi arithmetic measure_theory.measure.measure_space_def data.multiset linear_algebra.finite_dimensional analysis.inner_product_space.projection analysis.inner_product_space.dual data.multiset.basic data.nat.basic open_locale pointwise -- needed to get decidable_eq for sets! open classical local attribute [instance] prop_decidable variables {V: Type} [inner_product_space ℝ V] [finite_dimensional ℝ V] instance submodule.complete_space (E : submodule ℝ V) : complete_space E := is_complete.complete_space_coe (submodule.complete_of_finite_dimensional E) noncomputable def vector_orth (u : V) : submodule ℝ V := (submodule.span ℝ ({u} : set V))ᗮ lemma mem_vector_orth {u : V} {x : V} : x ∈ vector_orth u ↔ ⟪x, u⟫_ℝ = 0 := begin simp only [vector_orth, submodule.mem_orthogonal, submodule.mem_span_singleton], split, { intro h, rw [real_inner_comm], refine h u _, exact ⟨1, one_smul _ _⟩, }, { rintro h u ⟨a, rfl⟩, simp only [inner_smul_left, is_R_or_C.conj_to_real, mul_eq_zero], right, rw [real_inner_comm], exact h, } end noncomputable abbreviation dim := finite_dimensional.finrank ℝ abbreviation diff (A : set V) := A -ᵥ A noncomputable def common_dimension (C : multiset (set V)) : ℕ := finite_dimensional.finrank ℝ (vector_span ℝ C.sum) lemma mem_of_mem_of_generator {A : set V} {x : V} (h : x ∈ A) : x ∈ submodule.span ℝ A := begin refine (set.mem_of_mem_of_subset h _ : x ∈ ↑(submodule.span ℝ A)), apply submodule.subset_span, end lemma vector_span_zero (A : set V) (h : (0 : V) ∈ A) : vector_span ℝ A = submodule.span ℝ A := begin simp only [vector_span], apply submodule.complete_lattice.le_antisymm, begin refine submodule.span_le.mpr (_ : A -ᵥ A ⊆ ↑(submodule.span ℝ A)), rw [set.subset_def], intros x hmem, rcases set.mem_sub.mp hmem with ⟨a, b, ⟨ha, hb, rfl⟩⟩, refine (submodule.sub_mem _ _ _ : a - b ∈ submodule.span ℝ A), exact mem_of_mem_of_generator ha, exact mem_of_mem_of_generator hb, end, begin apply submodule.span_mono, simp only [has_subset.subset, has_le.le], intros x x_in_A, refine set.mem_sub.mpr ⟨x, 0, _⟩, simp [h, x_in_A], end end lemma exists_zero_translate (A : set V) : ∃ x : V, A + {x} = ∅ ∨ (0 : V) ∈ (A + {x}) := begin by_cases A = ∅, begin rcases h with rfl, simp, end, begin have := set.ne_empty_iff_nonempty.mp h, rcases set.nonempty_def.mp this with ⟨y, hy⟩, refine ⟨-y, or.inr _⟩, rw [show 0 = y + (-y), by simp], apply set.mem_add.mpr, tauto, end end lemma submodule_sum_eq_sup (E F : submodule ℝ V) : E + F = E ⊔ F := rfl lemma zero_subset_submodule (E : submodule ℝ V) : {(0 : V)} ⊆ (E : set V) := begin simp, end lemma set_add_zero (A : set V) : A + {(0 : V)} = A := begin simp, end lemma set_add_le_add_right (A B C : set V) (h : B ⊆ C) : A + B ⊆ A + C := begin rintro x ⟨a, b, ⟨ha, hb, rfl⟩⟩, refine ⟨a, b, _⟩, -- exists.intro; interesting that it works tauto, end lemma set_add_le_add_left (A B C : set V) (h : A ⊆ B) : A + C ⊆ B + C := begin rintro x ⟨a, b, ⟨ha, hb, rfl⟩⟩, refine ⟨a, b, _⟩, -- exists.intro; interesting that it works tauto, end lemma set_le_add_right (E F : set V) (h : (0: V) ∈ F) : E ⊆ E + F := begin conv {to_lhs, rw [←@set_add_zero V _ _ E]}, apply_rules [set_add_le_add_right, set.singleton_subset_iff.mpr h], end lemma set_le_add_left (E F : set V) (h : (0: V) ∈ F) : E ⊆ F + E := begin rw [add_comm], exact set_le_add_right E F h, end lemma submodule_sum_eq_mink_sum {E F : submodule ℝ V} : ((E + F : submodule ℝ V) : set V) = (E : set V) + (F : set V) := begin have E_le : E ≤ E + F := by simp, have F_le : F ≤ E + F := by simp, apply le_antisymm, begin let G := submodule.span ℝ ((E : set V) + (F : set V)), have inG : E + F ≤ G := begin have : Π(H K : submodule ℝ V), (H : set V) ⊆ (H : set V) + (K : set V) := begin intros H K, conv { to_lhs, rw [←@set_add_zero V _ _ H], }, apply_rules [set_add_le_add_right, zero_subset_submodule], end, begin refine complete_lattice.sup_le E F G _ _, begin rw [←submodule.span_eq E], apply submodule.span_mono, refine set_le_add_right E F _, apply submodule.zero_mem, end, begin rw [←submodule.span_eq F], apply submodule.span_mono, refine set_le_add_left F E _, apply submodule.zero_mem, end end end, have G_EF : (G : set V) ≤ (E : set V) + (F : set V) := begin intros x hx, refine submodule.span_induction hx _ _ _ _, begin tauto, end, begin refine ⟨0, 0, ⟨_, _, _⟩⟩, apply submodule.zero_mem, apply submodule.zero_mem, simp, end, begin rintro x y ⟨ex, fx, ⟨hex, hfx, rfl⟩⟩ ⟨ey, fy, ⟨hey, hfy, rfl⟩⟩, refine ⟨ex + ey, fx + fy, _, _, _⟩, apply submodule.add_mem E hex hey, apply submodule.add_mem F hfx hfy, abel, end, begin rintro a x ⟨e, f, ⟨he, hf, rfl⟩⟩, refine ⟨a • e, a • f, _, _, _⟩, apply submodule.smul_mem E a he, apply submodule.smul_mem F a hf, simp, end end, refine le_trans inG G_EF, end, begin rintro x ⟨e, f, he, hf, rfl⟩, refine submodule.add_mem (E + F) _ _, exact E_le he, exact F_le hf, end end lemma add_subset_submodule {A B : set V} {E : submodule ℝ V} (hA : A ⊆ E) (hB : B ⊆ E): A + B ⊆ E := begin intros s hs, rcases set.mem_add.mp hs with ⟨a, b, ⟨ha, hb, rfl⟩⟩, apply submodule.add_mem, exact @set.mem_of_mem_of_subset _ _ _ _ ha hA, exact @set.mem_of_mem_of_subset _ _ _ _ hb hB, end lemma submodule_subset_of_le {E F : submodule ℝ V} : E ≤ F = ((E : set V) ⊆ (F : set V)) := begin apply propext, apply iff.intro, all_goals { intros h e he, exact h he, } end lemma set_ABAB_AABB {A B : set V} : (A + B) - (A + B) = (A - A) + (B - B) := begin apply le_antisymm, all_goals { rintro _ ⟨_, _, ⟨a, b, ha, hb, rfl⟩, ⟨c, d, hc, hd, rfl⟩, rfl⟩, }, begin refine ⟨a - c, b - d, ⟨a, c, _, _, rfl⟩, ⟨b, d, _, _, rfl⟩, _⟩, any_goals {assumption}, abel, end, begin refine ⟨a + c, b + d, ⟨a, c, _, _, rfl⟩, ⟨b, d, _, _, rfl⟩, _⟩, any_goals {assumption}, abel, end end lemma zero_mem_diff_of_nonempty {A : set V} (ne : A.nonempty) : (0 : V) ∈ A - A := begin letI ne' := set.nonempty.to_subtype ne, rcases set.exists_mem_of_nonempty A with ⟨⟨x, hx⟩, -⟩, rw [show (0 : V) = x - x, by simp], refine set.sub_mem_sub _ _, all_goals {assumption}, end lemma nonempty_sets_of_nonempty_sum {A B : set V} (h : set.nonempty (A + B)) : set.nonempty A ∧ set.nonempty B := begin rcases h with ⟨x, ⟨a, b, ha, hb, rfl⟩⟩, exact ⟨⟨a, ha⟩, ⟨b, hb⟩⟩, end lemma multiset_sum_nonempty_of_elements {A : multiset (set V)} (h : ∀ a : set V, a ∈ A → a.nonempty): A.sum.nonempty := begin unfreezingI { induction A using pauls_multiset_induction with as b ih, { simp [set.zero_nonempty], }, { simp only [multiset.sum_cons], apply set.add_nonempty.mpr, split, { refine h b _, simp, }, { apply ih, intros c hc, refine h c _, simp [hc], } } } end lemma diff_set_le_add (A B : set V) (Bne : set.nonempty B) : diff A ⊆ diff (B + A) := begin rcases Bne with ⟨b, hb⟩, rintro d ⟨a, a', ha, ha', rfl⟩, refine ⟨b + a, b + a', ⟨b, a, _⟩, ⟨b, a', _⟩, _⟩, any_goals {simp}, all_goals {tauto}, end def multiset_all_nonempty (F : multiset (set V)) := ∀ x ∈ F, set.nonempty x lemma all_nonempty_of_le {F G : multiset (set V)} (h : F ≤ G) : multiset_all_nonempty G → multiset_all_nonempty F := begin intros neG x hx, refine neG x _, exact multiset.mem_of_le h hx, end lemma diff_multiset_sum_mono {F G : multiset (set V)} (h : F ≤ G) (hne : ∀ x ∈ G, set.nonempty x) : diff F.sum ⊆ diff G.sum := begin rcases multiset.le_iff_exists_add.mp h with ⟨E, rfl⟩, simp only [multiset.sum_add], rw [add_comm], refine diff_set_le_add F.sum E.sum _, refine multiset_sum_nonempty_of_elements _, intros a ha, refine hne a _, apply multiset.mem_add.mpr, tauto, end -- I almost forgot that the sets must not be empty... lemma vector_span_sum_commute (A B : set V) (Ane : A.nonempty) (Bne : B.nonempty) : vector_span ℝ (A + B) = (vector_span ℝ A) + (vector_span ℝ B) := begin apply submodule.complete_lattice.le_antisymm, begin simp only [vector_span], refine submodule.span_le.mpr _, rintros x ⟨ab1, ab2, ⟨⟨a1, b1, ⟨ha1, hb1, rfl⟩⟩, ⟨a2, b2, ⟨ha2, hb2, rfl⟩⟩, rfl⟩⟩, have : a1 + b1 - (a2 + b2) = a1 - a2 + (b1 - b2) := by abel, simp only [has_vsub.vsub, this], rw [submodule_sum_eq_mink_sum], apply set.add_mem_add, begin refine submodule.subset_span _, refine ⟨a1, a2, ha1, ha2, rfl⟩, end, begin refine submodule.subset_span _, refine ⟨b1, b2, hb1, hb2, rfl⟩, end end, begin simp only [submodule_subset_of_le, submodule_sum_eq_mink_sum], rintro x ⟨a, b, ha, hb, rfl⟩, change a + b ∈ vector_span ℝ (A + B), simp only [vector_span] at *, simp only [set_vsub_eq_sub] at *, simp only [set_ABAB_AABB], refine submodule.add_mem _ _ _, all_goals {refine submodule.span_mono _ (by assumption)}, --wow, it works! begin refine set_le_add_right _ _ _, exact zero_mem_diff_of_nonempty Bne, end, begin refine set_le_add_left _ _ _, exact zero_mem_diff_of_nonempty Ane, end end end def semicritical (C : multiset (set V)) := ∀ τ : multiset (set V), τ ≤ C → common_dimension τ ≥ τ.card def project_set (E : submodule ℝ V): set V → set E := λ A, orthogonal_projection E '' A def project_collection (E : submodule ℝ V) (C : multiset (set V)) : multiset (set E) := C.map (project_set E) lemma minksum_proj_commute (E : submodule ℝ V) (A B : set V) : project_set E (A + B) = project_set E A + project_set E B := begin apply set.ext, intro x, simp only [project_set, set.mem_add, set.mem_image] at *, apply iff.intro, begin intro h, rcases h with ⟨-, ⟨⟨a, b, ⟨ha, hb, rfl⟩⟩, rfl⟩⟩, rw [continuous_linear_map.map_add], tauto, end, begin intro h, rcases h with ⟨pa, pb, ⟨⟨a, ⟨ha, rfl⟩⟩, ⟨b, ⟨hb, rfl⟩⟩, rfl⟩⟩, rw [←continuous_linear_map.map_add], tauto, end end lemma minksum_proj_commute_list (E : submodule ℝ V) (C : list (set V)) : project_set E C.sum = (C.map $ project_set E).sum := begin induction C, begin simp [project_set], trivial, end, begin simp [←C_ih, minksum_proj_commute], end, end lemma minksum_proj_commute_multiset (E : submodule ℝ V) (C : multiset (set V)) : project_set E C.sum = (project_collection E C).sum := begin induction C, begin simp only [multiset.quot_mk_to_coe'', project_collection, multiset.coe_map, multiset.coe_sum], apply minksum_proj_commute_list, end, trivial, end lemma subcollection_semicritical {C D: multiset (set V)} (hDC : D ≤ C) (hsc : semicritical C) : semicritical D := begin intro S, intro hSD, apply hsc, apply le_trans hSD hDC, end def cart_prod {V W : Type} (A : set V) (B : set W) : set (V × W) := { x : V × W | x.fst ∈ A ∧ x.snd ∈ B } lemma set_image2_eq_image_times {V W : Type} {A B : set V} {f : V → V → W} : set.image2 f A B = set.image (function.uncurry f) (cart_prod A B) := begin simp [set.image2, set.image, function.uncurry, cart_prod], apply le_antisymm, { rintro _ ⟨a, ⟨ha, b, hb, h⟩⟩, refine ⟨a, b, ⟨ha, hb⟩, h⟩, }, { rintro _ ⟨a, b, ⟨ha, hb⟩, h⟩, exact ⟨a, ha, b, hb, h⟩, } end lemma set_sum_project_commute (A B : set V) (E : submodule ℝ V) : project_set E (A + B) = (project_set E A) + (project_set E B) := begin simp only [project_set], apply le_antisymm, { rintro e ⟨x, ⟨⟨a, b, ha, hb, rfl⟩, rfl⟩⟩, rw [(orthogonal_projection E).map_add], apply set.add_mem_add, { refine ⟨a, _⟩, tauto, }, { refine ⟨b, _⟩, tauto, } }, { rintro e ⟨pa, pb, ⟨a, ha, rfl⟩, ⟨b, hb, rfl⟩, rfl⟩, rw [←(orthogonal_projection E).map_add], refine ⟨a+b, _⟩, split, any_goals {refl}, apply set.add_mem_add, all_goals {assumption}, } end -- maybe generalizable to the situation when add commutes with any f lemma multiset_sum_project_set_commute (C : multiset (set V)) (E : submodule ℝ V) : project_set E C.sum = (C.map (project_set E)).sum := begin induction C using pauls_multiset_induction with C c ih, { simp only [project_set, multiset.sum_zero, set.image_zero, map_zero, multiset.map_zero], trivial, }, { simp only [multiset.sum_cons, set_sum_project_commute], simp only [multiset.map_cons, multiset.sum_cons], rw [ih], } end noncomputable def proj (E : submodule ℝ V) := (orthogonal_projection E).to_linear_map lemma ker_of_orthogonal_projection (E : submodule ℝ V) : (proj E).ker = Eᗮ := begin apply le_antisymm, { rintro x hx, have hx' : orthogonal_projection E x = 0 := hx, rw [show x = x - orthogonal_projection E x, by simp [hx']], apply sub_orthogonal_projection_mem_orthogonal, }, { rintro x hx, refine orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero hx, } end lemma ker_of_complementary_orthogonal_projection (E : submodule ℝ V) : (proj Eᗮ).ker = E := begin conv {to_rhs, rw [←submodule.orthogonal_orthogonal E]}, apply ker_of_orthogonal_projection, end lemma surjective_orthogonal_projection (E : submodule ℝ V): function.surjective (proj E) := begin rintro e, refine ⟨e, _⟩, simp only [proj, continuous_linear_map.to_linear_map_eq_coe, continuous_linear_map.coe_coe, orthogonal_projection_mem_subspace_eq_self], end lemma range_of_orthogonal_projection (E : submodule ℝ V): (proj E).range = ⊤ := begin apply linear_map.range_eq_top.mpr, simp only [proj, continuous_linear_map.to_linear_map_eq_coe, continuous_linear_map.coe_coe], apply surjective_orthogonal_projection, end lemma dim_add_dim_orthogonal (E : submodule ℝ V) : dim E + dim Eᗮ = dim V := begin have : dim E = dim (⊤ : submodule ℝ E) := finrank_top.symm, rw [←ker_of_orthogonal_projection E, this, ←range_of_orthogonal_projection E], apply linear_map.finrank_range_add_finrank_ker, end def submodule_inclusion (W : submodule ℝ V) : W →ₗ[ℝ] V := begin refine ⟨_, _, _⟩, exact (coe : W → V), tauto, tauto, end lemma submodule_inclusion_injective {W : submodule ℝ V} : function.injective (submodule_inclusion W) := begin rintro x y, simp [submodule_inclusion], end def submodule_to_submodule_inclusion {S T : submodule ℝ V} (h : S ≤ T) : S →ₗ[ℝ] T := begin refine ⟨_, _, _⟩, { rintro x, exact ⟨x.1, h x.2⟩, }, {tauto}, {tauto}, end def submodule_to_submodule_inclusion_injective {S T : submodule ℝ V} (h : S ≤ T) : function.injective (submodule_to_submodule_inclusion h) := begin intros x y, simp [submodule_to_submodule_inclusion], end noncomputable def submodule_submodule_to_submodule {W : submodule ℝ V} (U : submodule ℝ W) : submodule ℝ V := submodule.span ℝ ((coe : W → V) '' U) lemma submod_submod_eq_submod_set {W : submodule ℝ V} (U : submodule ℝ W) : (submodule_submodule_to_submodule U : set V) = ((coe : W → V) '' U) := begin apply le_antisymm, { rintro x hx, refine submodule.span_induction hx _ _ _ _, { tauto, }, { simp only [set.mem_image, set_like.mem_coe, submodule.coe_eq_zero, exists_eq_right, submodule.zero_mem], }, { rintro y z ⟨py, hyU, rfl⟩ ⟨pz, hzU, rfl⟩, refine ⟨py + pz, _⟩, split, { apply submodule.add_mem _ hyU hzU, }, simp only [submodule.coe_add], }, { rintro a y ⟨py, pyU, rfl⟩, refine ⟨a • py, _⟩, split, { apply submodule.smul_mem _ a pyU, }, simp only [submodule.coe_smul_of_tower], }, }, { apply submodule.subset_span, } end def submodule_submodule_mapsto_submodule {W : submodule ℝ V} (U : submodule ℝ W) : U →ₗ[ℝ] submodule_submodule_to_submodule U := begin refine ⟨_, _, _⟩, { rintro v, refine ⟨v.1.1, _⟩, simp only [submodule_submodule_to_submodule], refine submodule.subset_span _, refine ⟨v.1, _⟩, simp, }, { tauto, }, { tauto, }, end lemma sub_inequality_from_add_inequality {a b c : ℕ} : a + b ≥ c → a ≥ c - b := begin exact tsub_le_iff_right.mpr, end lemma image_eq_range_dom_restrict {K : Type} {V : Type} [field K] [add_comm_group V] [module K V] {V₂ : Type} [add_comm_group V₂] [module K V₂] [finite_dimensional K V] (f : V →ₗ[K] V₂) (W : submodule K V) : W.map f = (f.dom_restrict W).range := begin apply le_antisymm, { rintro y ⟨x, ⟨hx, rfl⟩⟩, rw [show f x = f.dom_restrict W ⟨x, hx⟩, by refl], apply linear_map.mem_range_self, }, { rintro y ⟨⟨x, hx⟩, rfl⟩, rw [show f.dom_restrict W ⟨x, hx⟩ = f x, by refl], apply submodule.mem_map_of_mem hx, } end lemma map_ker_restrict {K : Type} {V : Type} [field K] [add_comm_group V] [module K V] {V₂ : Type} [add_comm_group V₂] [module K V₂] (f : V →ₗ[K] V₂) (W : submodule K V) : (f.dom_restrict W).ker.map W.subtype = f.ker ⊓ W := begin unfold linear_map.dom_restrict, rw [linear_map.ker_comp], apply le_antisymm, { refine le_inf _ _, {apply submodule.map_comap_le}, { conv {to_rhs, rw [←submodule.range_subtype W]}, apply linear_map.map_le_range, } }, { rintro x ⟨hxf, hxW⟩, refine ⟨⟨x, hxW⟩, _⟩, simp only [hxf, submodule.comap_coe, submodule.coe_subtype, set.mem_preimage, submodule.coe_mk, eq_self_iff_true, and_self], } end def ker_restrict_equiv {K : Type} {V : Type} [field K] [add_comm_group V] [module K V] {V₂ : Type} [add_comm_group V₂] [module K V₂] (f : V →ₗ[K] V₂) (W : submodule K V) : (f.dom_restrict W).ker ≃ₗ[K] (f.ker ⊓ W : submodule K V) := begin rw [←map_ker_restrict], apply submodule.equiv_subtype_map, end def ker_dom_restrict_inclusion {K : Type} {V : Type} [field K] [add_comm_group V] [module K V] {V₂ : Type} [add_comm_group V₂] [module K V₂] [finite_dimensional K V] (f : V →ₗ[K] V₂) (W : submodule K V) : (f.dom_restrict W).ker →ₗ[K] f.ker := begin let g := W.subtype, let h := (f.dom_restrict W).ker.subtype, let k := g ∘ₗ h, refine k.cod_restrict f.ker _, rintro ⟨c, hc⟩, exact hc, end def ker_dom_restrict_inclusion_injective {K : Type} {V : Type} [field K] [add_comm_group V] [module K V] {V₂ : Type} [add_comm_group V₂] [module K V₂] [finite_dimensional K V] (f : V →ₗ[K] V₂) (W : submodule K V) : function.injective (ker_dom_restrict_inclusion f W) := begin have : function.injective (coe : f.ker → V) := subtype.coe_injective, rintro x y, unfold ker_dom_restrict_inclusion, simp only, -- remove let intro h, replace h := congr_arg (coe : f.ker → V) h, simp only [linear_map.cod_restrict_apply, linear_map.comp_apply] at h, simp only [submodule.coe_subtype] at h, exact subtype.coe_injective (subtype.coe_injective h), end lemma subspace_rank_nullity {K : Type} {V : Type} [field K] [add_comm_group V] [module K V] {V₂ : Type} [add_comm_group V₂] [module K V₂] [finite_dimensional K V] (f : V →ₗ[K] V₂) (W : submodule K V) : finite_dimensional.finrank K (W.map f) + finite_dimensional.finrank K (f.ker ⊓ W : submodule K V) = finite_dimensional.finrank K W := begin let g := f.dom_restrict W, rw [image_eq_range_dom_restrict], have := ker_restrict_equiv f W, rw [←linear_equiv.finrank_eq this], apply linear_map.finrank_range_add_finrank_ker g, end lemma dim_image_le_self {K : Type} {V : Type} [field K] [add_comm_group V] [module K V] {V₂ : Type} [add_comm_group V₂] [module K V₂] [finite_dimensional K V] (f : V →ₗ[K] V₂) (W : submodule K V) : finite_dimensional.finrank K (W.map f) ≤ finite_dimensional.finrank K W := begin rw [←subspace_rank_nullity f W], simp only [le_add_iff_nonneg_right, zero_le'], end lemma dim_image_ge_dim_domain_sub_dim_ker {K : Type} {V : Type} [field K] [add_comm_group V] [module K V] {V₂ : Type} [add_comm_group V₂] [module K V₂] [finite_dimensional K V] (f : V →ₗ[K] V₂) (W : submodule K V) : finite_dimensional.finrank K (W.map f) ≥ finite_dimensional.finrank K W - finite_dimensional.finrank K f.ker := begin let g := f.dom_restrict W, have hrange : W.map f = g.range := image_eq_range_dom_restrict f W, have hker : finite_dimensional.finrank K g.ker ≤ finite_dimensional.finrank K f.ker := begin let incl : g.ker →ₗ[K] f.ker := ker_dom_restrict_inclusion f W, have incl_inj : function.injective incl := ker_dom_restrict_inclusion_injective f W, apply linear_map.finrank_le_finrank_of_injective incl_inj, end, have rn := linear_map.finrank_range_add_finrank_ker g, rw [←hrange] at rn, apply tsub_le_iff_right.mpr, rw [←rn], refine add_le_add (le_refl _) _, assumption, apply_instance, end noncomputable def project_subspace (E F : submodule ℝ V) : submodule ℝ E := F.map (orthogonal_projection E).to_linear_map @[simp] lemma multiset.sum_project_subspace (E : submodule ℝ V) (C : multiset (submodule ℝ V)) : project_subspace E C.sum = (C.map (project_subspace E)).sum := begin apply C.sum_linear_map, apply_instance, end lemma map_vector_span {R : Type} {M : Type} {M₂ : Type} [field R] [add_comm_group M] [module R M] {σ₁₂ : R →+* R} [add_comm_group M₂] [module R M₂] [ring_hom_surjective σ₁₂] (f : M →ₛₗ[σ₁₂] M₂) (s : set M) : submodule.map f (vector_span R s) = vector_span R (f '' s) := begin simp only [vector_span], simp only [submodule.map_span], congr, apply le_antisymm, { rintro x ⟨d, ⟨a, b, ha, hb, rfl⟩, rfl⟩, refine ⟨f a, f b, _⟩, refine ⟨⟨a, ⟨ha, rfl⟩⟩, ⟨b, ⟨hb, rfl⟩⟩, _⟩, simp only [linear_map.map_sub, vsub_eq_sub], }, { rintro x ⟨fa, fb, ⟨a, ha, rfl⟩, ⟨b, hb, rfl⟩, rfl⟩, refine ⟨a - b, _⟩, split, { refine ⟨a, b, ha, hb, rfl⟩, }, simp only [linear_map.map_sub], refl, }, end lemma project_subspace_vector_span {A : set V} {E : submodule ℝ V} : project_subspace E (vector_span ℝ A) = vector_span ℝ (project_set E A) := begin simp only [project_subspace, map_vector_span, continuous_linear_map.to_linear_map_eq_coe, continuous_linear_map.coe_coe], refl, end lemma vector_span_projection_sum_commute {C : multiset (set V)} {E : submodule ℝ V} : vector_span ℝ (project_collection Eᗮ C).sum = project_subspace Eᗮ (vector_span ℝ C.sum) := begin simp only [project_collection], rw [←multiset_sum_project_set_commute C Eᗮ], simp only [project_subspace, project_set], rw [map_vector_span (orthogonal_projection Eᗮ).to_linear_map], simp only [continuous_linear_map.to_linear_map_eq_coe, continuous_linear_map.coe_coe], end lemma common_dimension_projection {C : multiset (set V)} {E : submodule ℝ V} : common_dimension (project_collection Eᗮ C) = finite_dimensional.finrank ℝ (project_subspace Eᗮ (vector_span ℝ C.sum)) := begin simp only [common_dimension], rw [vector_span_projection_sum_commute], end lemma kernel_eq (E : submodule ℝ V) : (orthogonal_projection E).ker = (orthogonal_projection E).to_linear_map.ker := begin simp only [continuous_linear_map.ker], refl, end lemma common_dimension_project_collection (C : multiset (set V)) (E : submodule ℝ V) : common_dimension (project_collection Eᗮ C) ≥ common_dimension C - finite_dimensional.finrank ℝ E := begin simp only [common_dimension_projection], dsimp only [project_subspace, common_dimension, vector_span], have rn := dim_image_ge_dim_domain_sub_dim_ker (orthogonal_projection Eᗮ).to_linear_map (submodule.span ℝ (C.sum -ᵥ C.sum)), have : (orthogonal_projection Eᗮ).to_linear_map.ker = E := begin rw [←kernel_eq Eᗮ], convert ker_of_orthogonal_projection Eᗮ, simp only [submodule.orthogonal_orthogonal E], end, rw [this] at rn, assumption, end lemma finrank_le_of_le {E F : submodule ℝ V} (h : E ≤ F) : dim E ≤ dim F := begin have ok : ∀ x : E, E.subtype x ∈ F := begin intro x, apply h, simp only [submodule.coe_subtype, submodule.coe_mem], end, let f := E.subtype.cod_restrict F ok, have f_inj : function.injective f := begin refine (@set.injective_cod_restrict _ _ E.subtype F ok).mpr _, apply submodule.injective_subtype, end, apply linear_map.finrank_le_finrank_of_injective f_inj, end /- lemma vector_span_ball {x : V} {ε : ℝ} (εpos : ε > 0) : vector_span ℝ (metric.ball x ε) = ⊤ := sorry -/ lemma span_top_of_ball_subset {A : set V} {x : V} {ε : ℝ} (εpos : ε > 0) (h : metric.ball x ε ⊆ A) : submodule.span ℝ A = ⊤ := begin simp only [←top_le_iff], rintro v -, by_cases he : v = x, { rw [he], apply submodule.subset_span, apply h, apply metric.mem_ball_self εpos, }, let w := (ε / (2 * ∥v - x∥)) • (v - x) + x, have hz := he ∘ norm_sub_eq_zero_iff.mp, have hpos := norm_sub_pos_iff.mpr he, have hw : w ∈ submodule.span ℝ A, { simp only [w], apply submodule.subset_span, apply h, simp only [metric.mem_ball, dist_eq_norm], simp only [one_div, mul_inv_rev, add_sub_cancel, norm_smul], simp only [real.norm_eq_abs, abs_div, abs_mul, abs_two, abs_norm_eq_norm], simp only [abs_eq_self.mpr (le_of_lt εpos), div_mul_eq_div_div], simp only [div_mul], rw [div_self hz, div_one], exact half_lt_self εpos, }, have hx : x ∈ submodule.span ℝ A, { apply submodule.subset_span, apply h, apply metric.mem_ball_self εpos, }, have hvw : v = (2 * ∥v - x∥ / ε) • (w - x) + x, { simp only [w, add_sub_cancel, smul_smul], rw [div_mul_div_cancel _ (ne_of_gt εpos)], rw [div_self (double_ne_zero hz)], simp only [one_smul, sub_add_cancel], }, rw [hvw], refine submodule.add_mem _ _ _, { refine submodule.smul_mem _ _ _, refine submodule.sub_mem _ _ _, all_goals {assumption}, }, {assumption}, end lemma vector_span_top_of_ball_subset {A : set V} {x : V} {ε : ℝ} (εpos : ε > 0) (h : metric.ball x ε ⊆ A) : vector_span ℝ A = ⊤ := begin simp only [vector_span], suffices hh : metric.ball 0 ε ⊆ diff A, { exact span_top_of_ball_subset εpos hh, }, intros y hy, simp only [metric.mem_ball] at hy, refine ⟨x + y, x, _, _, _⟩, { apply h, simp only [metric.mem_ball, dist_self_add_left], simpa only [dist_eq_norm, sub_zero] using hy, }, { apply h, exact metric.mem_ball_self εpos, }, { simp only [vsub_eq_sub, add_sub_cancel'], }, end lemma le_orthogonal_symm (E F : submodule ℝ V) : E ≤ Fᗮ ↔ F ≤ Eᗮ := begin suffices h : ∀ E F : submodule ℝ V, E ≤ Fᗮ → F ≤ Eᗮ, { split, all_goals {exact h _ _}, }, clear E F, intros E F h, rw [←submodule.orthogonal_orthogonal F], apply submodule.orthogonal_le, exact h, end lemma inner_orthogonal_eq_inner (E : submodule ℝ V) (u : E) (x : V) : ⟪((proj E) x : V), (u : V)⟫_ℝ = ⟪x, u⟫_ℝ := begin symmetry, apply eq_of_sub_eq_zero, -- simp only [submodule.coe_inner], rw [←inner_sub_left], simp only [proj, continuous_linear_map.to_linear_map_eq_coe, continuous_linear_map.coe_coe, orthogonal_projection_inner_eq_zero, submodule.coe_mem], end lemma map_proj_orthogonal (E F : submodule ℝ V) : Fᗮ.map (proj E) = (F.comap E.subtype)ᗮ := begin rw [←submodule.orthogonal_orthogonal (Fᗮ.map (proj E))], refine congr_arg submodule.orthogonal _, ext, simp only [submodule.mem_map, submodule.mem_comap, submodule.mem_orthogonal, submodule.coe_subtype, submodule.coe_inner], simp only [forall_exists_index, and_imp, forall_apply_eq_imp_iff₂], split, { intros h, have : x.val ∈ Fᗮᗮ, { simp only [submodule.mem_orthogonal], intros u hu, have := h u hu, simpa only [inner_orthogonal_eq_inner] using this, }, { simpa only [submodule.orthogonal_orthogonal] using this, }, }, { intros xF v hv, simp only [real_inner_comm] at hv, simpa only [inner_orthogonal_eq_inner] using hv x xF, }, end lemma mem_orthogonal_span (A : set V) (x : V) : x ∈ (submodule.span ℝ A)ᗮ ↔ ∀ u : V, u ∈ A → ⟪u, x⟫_ℝ = 0 := begin split, { rw [submodule.mem_orthogonal], intros hx u hu, refine hx u _, apply submodule.subset_span, exact hu, }, { intro h, rw [submodule.mem_orthogonal], intros u hu, apply submodule.span_induction hu, { exact h, }, { simp only [inner_zero_left], }, { intros y z hy hz, simp only [inner_add_left, hy, hz, add_zero], }, { intros a y hy, simp only [inner_smul_left, hy, mul_zero], }, }, end lemma singleton_add_space_eq {E : submodule ℝ V} {x : V} (xE : x ∈ E) : ({x} : set V) + ↑E = ↑E := begin ext y, split, { rintro ⟨xx, e, hxx, eE, rfl⟩, rcases (set.eq_of_mem_singleton hxx).symm with rfl, exact E.add_mem xE eE, }, { intros yE, exact ⟨x, y - x, set.mem_singleton _, E.sub_mem yE xE, add_sub_cancel'_right _ _⟩, }, end lemma eq_orthogonal_symm (E F : submodule ℝ V) : E = Fᗮ ↔ F = Eᗮ := begin split, all_goals { intro h, rw [h, submodule.orthogonal_orthogonal], }, end lemma inner_left_continuous (u : V) : continuous (flip inner u : V → ℝ) := begin let f : V → V × V := λ v, (v, u), let g : V × V → ℝ := λ x, ⟪x.fst, x.snd⟫_ℝ, let h := g ∘ f, have gc : continuous g := continuous_inner, have hc : continuous h := by continuity, exact hc, end lemma inner_right_continuous (u : V) : continuous (inner u : V → ℝ) := begin let f : V → V × V := λ v, (u, v), let g : V × V → ℝ := λ x, ⟪x.fst, x.snd⟫_ℝ, let h := g ∘ f, have gc : continuous g := continuous_inner, have hc : continuous h := by continuity, exact hc, end lemma inner_product_space.to_dual_symm_apply' {x : V} {y : normed_space.dual ℝ V} : ⟪x, (inner_product_space.to_dual ℝ V).symm y⟫_ℝ = y x := begin rw [real_inner_comm], exact inner_product_space.to_dual_symm_apply, end noncomputable def of_dual' (f : V →ₗ[ℝ] ℝ) : V := (inner_product_space.to_dual ℝ V).symm ⟨f, linear_map.continuous_of_finite_dimensional f⟩ lemma coe_ball_submodule {E : submodule ℝ V} (u : E) (ε : ℝ) : coe '' metric.ball u ε = metric.ball (u : V) ε ∩ E := begin ext, simp only [set.mem_image, metric.mem_ball, set.mem_inter_iff], split, { rintro ⟨e, he, rfl⟩, refine ⟨_, e.property⟩, simpa only [subtype.dist_eq] using he, }, { rintro ⟨h, xE⟩, refine ⟨⟨x, xE⟩, _, rfl⟩, { simpa only [subtype.dist_eq, subtype.coe_mk] using h, }, }, end lemma ball_spans_submodule (E : submodule ℝ V) (u : V) (uE : u ∈ E) {ε : ℝ} (εpos : ε > 0) : submodule.span ℝ (metric.ball u ε ∩ E) = E := begin let u' : E := ⟨u, uE⟩, suffices h : submodule.span ℝ (metric.ball u' ε) = ⊤, { simp only [u'] at h, replace h := congr_arg (submodule.map E.subtype) h, simp only [submodule.map_span] at h, simp only [submodule.coe_subtype, submodule.map_subtype_top] at h, simpa only [coe_ball_submodule, submodule.coe_mk] using h, }, exact span_top_of_ball_subset εpos (subset_refl _), end lemma dist_inner_inner (v₁ v₂ w₁ w₂ : V) : ⟪v₁, w₁⟫_ℝ ≤ ⟪v₂, w₂⟫_ℝ + (∥v₂ - v₁∥ * ∥w₁∥ + ∥v₂∥ * ∥w₂ - w₁∥) := begin conv { to_lhs, rw [←add_sub_cancel'_right v₂ v₁], simp only [inner_add_left], }, conv { to_lhs, congr, { rw [←add_sub_cancel'_right w₂ w₁], simp only [inner_add_right], }, }, simp only [add_assoc], refine add_le_add_left _ _, refine le_trans (add_le_add (real_inner_le_norm _ _) (real_inner_le_norm _ _)) _, simp only [←dist_eq_norm], rw [dist_comm v₁ v₂, dist_comm w₁ w₂, add_comm], end
module Data.InSet import Data.Bool import Data.Bool.Xor import public Data.InSet.Equality import Decidable.Equality %default total --------------------- --------------------- --- --- --- DEFINITIONS --- --- --- --------------------- --------------------- infix 6 == infix 7 `isin`, `notin` infixl 8 +, -, ^ infixl 9 *, # ------------------- --- Type itself --- ------------------- public export InSet : Type -> Type InSet a = a -> Bool -- TODO To think, maybe equality relation should be shown in the `InSet` type as a parameter? -- However, if this is only in the append operation, this gives an ability to union sets with different equalities. ------------------------------------ --- Intesional test of existence --- ------------------------------------ export isin : a -> InSet a -> Bool isin = flip apply public export %inline notin : a -> InSet a -> Bool notin x y = not $ isin x y ---------------- --- Creation --- ---------------- --- Syntax for list-like literals --- public export Nil : InSet a Nil _ = False public export (::) : Equality a => a -> InSet a -> InSet a (::) added parent x = if x =?= added then True else x `isin` parent --- Constants public export %inline Empty : InSet a Empty = [] public export Universe : InSet a Universe _ = True --------------------------- --- Basic set relations --- --------------------------- public export (==) : InSet a -> InSet a -> Type sa == sb = (x : a) -> x `isin` sa = x `isin` sb public export (<=) : InSet a -> InSet a -> Type sa <= sb = (x : a) -> x `isin` sa = True -> x `isin` sb = True public export NotEmpty : {a : Type} -> InSet a -> Type NotEmpty s = (x ** x `isin` s = True) ---------------------------- --- Basic set operations --- ---------------------------- export (+) : InSet a -> InSet a -> InSet a -- union (+) sa sb x = x `isin` sa || x `isin` sb export (#) : InSet a -> InSet a -> InSet a -- intersection (#) sa sb x = x `isin` sa && x `isin` sb export (-) : InSet a -> InSet a -> InSet a -- set difference (-) sa sb x = x `isin` sa && x `notin` sb export (^) : InSet a -> InSet a -> InSet a -- symmetrical difference (^) sa sb x = (x `isin` sa) `xor` (x `isin` sb) export %inline complement : InSet a -> InSet a complement s x = x `notin` s ------------------------------------ --- Non-algebraic set operations --- ------------------------------------ export (*) : InSet a -> InSet b -> InSet (a, b) (*) sx sy (x, y) = x `isin` sx && y `isin` sy -------------- -------------- --- --- --- LAWS --- --- --- -------------- -------------- ------------------------ --- Laws of equality --- ------------------------ export eq_reflexivity : (0 s : InSet a) -> s == s eq_reflexivity _ _ = Refl export eq_symmerty : {0 sa, sb : InSet a} -> (0 _ : sa == sb) -> sb == sa eq_symmerty f x = rewrite f x in Refl export eq_transitivity : {0 sa, sb, sc : InSet a} -> (0 _ : sa == sb) -> (0 _ : sb == sc) -> sa == sc eq_transitivity f g x = rewrite f x in rewrite g x in Refl -- Definition above can be written as -- sa <= sb = (x : a) -> So (x `isin` sa) -> So (x `isin` sb) -- but this leads to constant using `soToEq` and `eqToSo` in proofs. --- Negative equality-related laws --- trueNotFalse : Not (True = False) trueNotFalse Refl impossible export non_empty_is_not_empty : NotEmpty s -> Not (s = Empty) non_empty_is_not_empty (x ** prf_t) prf_f = trueNotFalse $ rewrite sym prf_t in rewrite prf_f in Refl export non_empty_not_eq_empty : NotEmpty s -> Not (s == Empty) non_empty_not_eq_empty (x ** prf_t) prf_f = trueNotFalse $ rewrite sym prf_t in rewrite prf_f x in Refl export cant_in_and_not_in : (s : InSet a) -> (x : a) -> Not (x `isin` s = x `notin` s) cant_in_and_not_in s x prf with (s x) cant_in_and_not_in _ _ Refl | True impossible ------------------------------- --- Laws of subset relation --- ------------------------------- --- Order laws of subset relation --- export subset_equal : {0 sa, sb : InSet a} -> (0 _ : sa == sb) -> sa <= sb subset_equal f x prf = rewrite sym $ f x in rewrite prf in Refl export subset_reflexivity : (0 s : InSet a) -> s <= s subset_reflexivity _ _ = id export subset_antisymmetry : {sa, sb : InSet a} -> sa <= sb -> sb <= sa -> sa == sb subset_antisymmetry f g x with (decEq (sa x) True) subset_antisymmetry f _ x | Yes pa with (decEq (sb x) True) subset_antisymmetry _ _ _ | Yes pa | Yes pb = rewrite pa in rewrite pb in Refl subset_antisymmetry f _ x | Yes pa | No nb = absurd . nb $ f x pa subset_antisymmetry _ g x | No pa with (decEq (sb x) True) subset_antisymmetry _ _ _ | No na | No nb = rewrite notTrueIsFalse na in rewrite notTrueIsFalse nb in Refl subset_antisymmetry _ g x | No na | Yes pb = absurd . na $ g x pb export subset_transitivity : {0 sa, sb, sc : InSet a} -> (0 _ : sa <= sb) -> (0 _ : sb <= sc) -> sa <= sc subset_transitivity f g x y = rewrite g x (f x y) in Refl -- Subset relation's totality seems to be unprovable for intensional sets neither in -- `Either (sa <= sb) (sb <= sa)`, nor in `Not $ sa <= sb => sb <= sa` variant. --- Alternative subset representations with unions and intersections --- export subset_thru_union : {sa, sb : InSet a} -> (0 _ : sa <= sb) -> sa + sb == sb subset_thru_union f x with (decEq (sa x) True) subset_thru_union f x | Yes pa = rewrite pa in rewrite f x pa in Refl subset_thru_union _ _ | No na = rewrite notTrueIsFalse na in Refl export union_thru_subset : {0 sa, sb : InSet a} -> (0 _ : sa + sb == sb) -> sa <= sb union_thru_subset f x y = rewrite sym $ f x in rewrite y in Refl export subset_thru_intersection : {sa, sb : InSet a} -> (0 _ : sa <= sb) -> sa # sb == sa subset_thru_intersection f x with (decEq (sa x) True) subset_thru_intersection f x | Yes pa = rewrite pa in rewrite f x pa in Refl subset_thru_intersection _ _ | No na = rewrite notTrueIsFalse na in Refl export intersection_thru_subset : {0 sa, sb : InSet a} -> (0 _ : sa # sb == sa) -> sa <= sb intersection_thru_subset f x pa = rewrite sym pa in rewrite sym $ f x in rewrite pa in Refl --- Subset with binary set operations --- export subset_for_unioned_right : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa <= sb) -> sa <= sb + sc subset_for_unioned_right sc f x prf = rewrite f x prf in Refl and_true_left_true : (a, b : Bool) -> a && b = True -> a = True and_true_left_true True _ _ = Refl export subset_for_intersected_left : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa <= sb) -> (sa # sc) <= sb subset_for_intersected_left sc f x prf = rewrite f x $ and_true_left_true (sa x) (sc x) prf in Refl export subset_for_diffed_left : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa <= sb) -> (sa - sc) <= sb subset_for_diffed_left sc f x prf = rewrite f x $ and_true_left_true (sa x) (x `notin` sc) prf in Refl -- Particular cases for the properties from above, where `sb = sa` export subset_refl_unioned_right : (0 sa, sc : InSet a) -> sa <= sa + sc subset_refl_unioned_right sa sc = subset_for_unioned_right sc $ subset_reflexivity sa export subset_refl_intersected_left : (0 sa, sc : InSet a) -> (sa # sc) <= sa subset_refl_intersected_left sa sc = subset_for_intersected_left sc $ subset_reflexivity sa export subset_refl_diffed_left : (0 sa, sc : InSet a) -> (sa - sc) <= sa subset_refl_diffed_left sa sc = subset_for_diffed_left sc $ subset_reflexivity sa --- Subset with complement --- export subset_of_complements : {0 sa, sb : InSet a} -> (0 _ : sa <= sb) -> complement sb <= complement sa subset_of_complements f x prf = rewrite sym $ subset_thru_intersection f x in rewrite the (sb x = False) $ rewrite sym $ notInvolutive $ sb x in cong not prf in rewrite andFalseFalse $ sa x in Refl export subset_of_complements_back : {0 sa, sb : InSet a} -> (0 _ : complement sb <= complement sa) -> sa <= sb subset_of_complements_back f x prf = rewrite sym $ subset_of_complements f x (rewrite notInvolutive $ sa x in prf) in rewrite notInvolutive $ sb x in Refl -------------------------------------------------- --- Congruence of relations in specializations --- -------------------------------------------------- --- Append --- export append_eq_cong_l : Equality a => (0 s : InSet a) -> {0 n, m : a} -> (0 _ : n = m) -> n::s == m::s append_eq_cong_l _ prf _ = rewrite prf in Refl export append_eq_cong_r : Equality a => {0 sa, sb : InSet a} -> (n : a) -> (0 _ : sa == sb) -> n::sa == n::sb append_eq_cong_r n f x with (x =?= n) append_eq_cong_r _ _ _ | True = Refl append_eq_cong_r _ f x | False = rewrite f x in Refl --- Union --- export union_eq_cong_l : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa == sb) -> sa + sc == sb + sc union_eq_cong_l _ f x = rewrite f x in Refl export union_eq_cong_r : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa == sb) -> sc + sa == sc + sb union_eq_cong_r _ f x = rewrite f x in Refl -- particular case for `append_eq_cong_l` export union_singleton_eq_cong_l : Equality a => (0 s : InSet a) -> {0 n, m : a} -> (0 _ : n = m) -> [n] + s == [m] + s union_singleton_eq_cong_l _ prf x = rewrite append_eq_cong_l [] prf x in Refl -- TODO to add for subset --- Intersection --- -- TODO to add for equality -- TODO to add for subset --- Difference --- -- TODO to add for equality -- TODO to add for subset --- Symmetrical difference --- -- TODO to add for equality -- TODO to add for subset --- Complement --- -- TODO to add for equality -- TODO to add for subset --- Cartesian product --- export cart_eq_cong_l : {0 sa, sb : InSet a} -> (0 sc : InSet c) -> (0 _ : sa == sb) -> sc * sa == sc * sb cart_eq_cong_l _ f (_, y) = rewrite f y in Refl export cart_eq_cong_r : {0 sa, sb : InSet a} -> (0 sc : InSet c) -> (0 _ : sa == sb) -> sa * sc == sb * sc cart_eq_cong_r _ f (x, _) = rewrite f x in Refl and_true_then_left_true : (a : Bool) -> {b : Bool} -> a && b = True -> a = True and_true_then_left_true True {b=True} Refl = Refl and_true_then_right_true : {a : Bool} -> (b : Bool) -> a && b = True -> b = True and_true_then_right_true {a=True} True Refl = Refl export cart_subset_cong_l : {0 sa, sb : InSet a} -> (0 sc : InSet c) -> (0 _ : sa <= sb) -> sc * sa <= sc * sb cart_subset_cong_l sc f (y, x) prf = rewrite f x $ and_true_then_right_true _ prf in rewrite and_true_then_left_true (sc y) prf in Refl export cart_subset_cong_r : {0 sa, sb : InSet a} -> (0 sc : InSet c) -> (0 _ : sa <= sb) -> sa * sc <= sb * sc cart_subset_cong_r sc f (x, y) prf = rewrite f x $ and_true_then_left_true _ prf in rewrite and_true_then_right_true (sc y) prf in Refl ---------------------- --- Laws of `isin` --- ---------------------- export not_in_empty : Equality a => (0 x : a) -> x `isin` [] = False not_in_empty _ = Refl export x_in_x_etc : Equality a => (0 x : a) -> (0 s : InSet a) -> x `isin` (x::s) = True x_in_x_etc x s = rewrite equ_reflexive x in Refl export x_in_same_etc : Equality a => (0 x, y : a) -> (0 s : InSet a) -> (0 _ : x =?= y = True) -> x `isin` (y::s) = True x_in_same_etc _ _ _ prf = rewrite prf in Refl export not_x_not_in_x_etc : Equality a => (x, y : a) -> NeqPrf x y -> x `isin` [y] = False not_x_not_in_x_etc x y neq = case @@(x =?= y) of (False ** prf) => rewrite prf in Refl (True ** prf) => absurd $ cant_eq_neq (eq_val_to_prf prf) neq export not_in_both : Equality a => (0 x, y : a) -> (0 ys : InSet a) -> (0 _ : x =?= y = False) -> (0 _ : x `isin` ys = False) -> x `isin` (y::ys) = False not_in_both x y ys xy xys = rewrite xy in rewrite xys in Refl export is_in_tail : Equality a => (0 x, y : a) -> (0 ys : InSet a) -> (0 _ : x =?= y = False) -> (0 _ : x `isin` (y::ys) = True) -> x `isin` ys = True is_in_tail _ _ _ xy xyys = rewrite sym xyys in rewrite xy in Refl ---------------------- --- Laws of append --- ---------------------- export append_is_union : Equality a => (n : a) -> (0 s : InSet a) -> n::s == [n] + s append_is_union n _ x with (x =?= n) append_is_union _ _ _ | True = Refl append_is_union _ _ _ | False = Refl --------------------- --- Laws of union --- --------------------- export union_of_self : (0 s : InSet a) -> s + s == s union_of_self s x = rewrite orSameNeutral $ s x in Refl export union_commutative : (0 sa, sb : InSet a) -> sa + sb == sb + sa union_commutative sa sb x = rewrite orCommutative (sa x) (sb x) in Refl export union_associative : (0 sa, sb, sc : InSet a) -> sa + (sb + sc) == (sa + sb) + sc union_associative sa sb sc x = rewrite orAssociative (sa x) (sb x) (sc x) in Refl export union_empty_neutral : (0 s : InSet a) -> s + [] == s union_empty_neutral s x = rewrite orFalseNeutral $ s x in Refl export union_preserves_universe : (0 s : InSet a) -> s + Universe == Universe union_preserves_universe s x = rewrite orTrueTrue $ s x in Refl -- ... with intersection export union_distributes_over_intersection : (0 sa, sb, sc : InSet a) -> sa + (sb # sc) == (sa + sb) # (sa + sc) union_distributes_over_intersection sa sb sc x = rewrite orDistribAndR (sa x) (sb x) (sc x) in Refl -- ... with diff export union_with_diff : (0 sa, sb, sc : InSet a) -> sa + (sb - sc) == (sa + sb) - (sc - sa) union_with_diff sa sb sc x = rewrite orDistribAndR (sa x) (sb x) (not $ sc x) in rewrite notAndIsOr (sc x) (not $ sa x) in rewrite notInvolutive $ sa x in rewrite orCommutative (sa x) (not $ sc x) in Refl -- ... with symdiff -- TODO To make this functon to have `(0 sa, sb : InSet a)` in the signature. export union_thru_symdiff_and_intersection : (sa, sb : InSet a) -> sa + sb == (sa ^ sb) ^ (sa # sb) union_thru_symdiff_and_intersection sa sb x = case (decEq (sa x) True, decEq (sb x) True) of (Yes pa, Yes pb) => rewrite pa in rewrite pb in Refl (Yes pa, No nb) => rewrite pa in rewrite notTrueIsFalse nb in Refl (No na, Yes pb) => rewrite notTrueIsFalse na in rewrite pb in Refl (No na, No nb) => rewrite notTrueIsFalse na in rewrite notTrueIsFalse nb in Refl -- ... with complement export union_with_its_complement : (0 s : InSet a) -> s + complement s == Universe union_with_its_complement s x = rewrite orNotTrue $ s x in Refl ---------------------------- --- Laws of intersection --- ---------------------------- export intersection_of_self : (0 s : InSet a) -> s # s == s intersection_of_self s x = rewrite andSameNeutral $ s x in Refl export intersection_commutative : (0 sa, sb : InSet a) -> sa # sb == sb # sa intersection_commutative sa sb x = rewrite andCommutative (sa x) (sb x) in Refl export intersection_associative : (0 sa, sb, sc : InSet a) -> sa # (sb # sc) == (sa # sb) # sc intersection_associative sa sb sc x = rewrite andAssociative (sa x) (sb x) (sc x) in Refl export intersection_universe_neutral : (0 s : InSet a) -> s # Universe == s intersection_universe_neutral s x = rewrite andTrueNeutral $ s x in Refl export intersection_preserves_empty : (0 s : InSet a) -> s # [] == [] intersection_preserves_empty s x = rewrite andFalseFalse $ s x in Refl -- ... with union export intersection_distributes_over_union : (0 sa, sb, sc : InSet a) -> sa # (sb + sc) == (sa # sb) + (sa # sc) intersection_distributes_over_union sa sb sc x = rewrite andDistribOrR (sa x) (sb x) (sc x) in Refl -- ... with set diff export intersection_diff_swap : (0 sa, sb, sc : InSet a) -> sa # (sb - sc) == sb # (sa - sc) intersection_diff_swap sa sb sc x = rewrite andAssociative (sa x) (sb x) (not $ sc x) in rewrite andAssociative (sb x) (sa x) (not $ sc x) in rewrite andCommutative (sa x) (sb x) in Refl export intersection_diff_assoc : (0 sa, sb, sc : InSet a) -> sa # (sb - sc) == (sa # sb) - sc intersection_diff_assoc sa sb sc x = rewrite sym $ andAssociative (sa x) (sb x) (not $ sc x) in Refl -- ... with symmetrical diff -- TODO To make this functon to have `(0 sa, sb, sc : InSet a)` in the signature. export intersection_distributes_over_symdiff : (sa, sb, sc : InSet a) -> sa # (sb ^ sc) == (sa # sb) ^ (sa # sc) intersection_distributes_over_symdiff sa sb sc x = case decEq (sa x) True of Yes pa => rewrite pa in Refl No na => rewrite notTrueIsFalse na in Refl -- ... with complement export intersection_with_complement : (0 sa, sb : InSet a) -> sa # complement sb == sa - sb intersection_with_complement _ _ _ = Refl export intersection_with_its_complement : (0 s : InSet a) -> s # complement s == [] intersection_with_its_complement s x = rewrite andNotFalse $ s x in Refl ------------------------------ --- Laws of set difference --- ------------------------------ export diff_of_intersection : (0 sa, sb, sc : InSet a) -> sc - (sa # sb) == (sc - sa) + (sc - sb) diff_of_intersection sa sb sc x = rewrite notAndIsOr (sa x) (sb x) in rewrite andDistribOrR (sc x) (not $ sa x) (not $ sb x) in Refl export diff_of_union : (0 sa, sb, sc : InSet a) -> sc - (sa + sb) == (sc - sa) # (sc - sb) diff_of_union sa sb sc x = rewrite notOrIsAnd (sa x) (sb x) in rewrite andAssociative (sc x && not (sa x)) (sc x) (not $ sb x) in rewrite sym $ andAssociative (sc x) (not $ sa x) (sc x) in rewrite andCommutative (not $ sa x) (sc x) in rewrite andAssociative (sc x) (sc x) (not $ sa x) in rewrite andSameNeutral $ sc x in rewrite andAssociative (sc x) (not $ sa x) (not $ sb x) in Refl export diff_of_diff : (0 sa, sb, sc : InSet a) -> sc - (sb - sa) == (sc # sa) + (sc - sb) diff_of_diff sa sb sc x = rewrite notAndIsOr (sb x) (not $ sa x) in rewrite notInvolutive $ sa x in rewrite orCommutative (not $ sb x) (sa x) in rewrite andDistribOrR (sc x) (sa x) (not $ sb x) in Refl export diff_of_self : (0 s : InSet a) -> s - s == [] diff_of_self s x = rewrite andNotFalse $ s x in Refl export diff_of_empty_left : (0 s : InSet a) -> [] - s == [] diff_of_empty_left _ _ = Refl export diff_of_empty_right : (0 s : InSet a) -> s - [] == s diff_of_empty_right s x = rewrite andTrueNeutral $ s x in Refl export diff_of_universe : (0 s : InSet a) -> s - Universe == [] diff_of_universe s x = rewrite andFalseFalse $ s x in Refl export diff_of_complements : (0 sa, sb : InSet a) -> complement sa - complement sb == sb - sa diff_of_complements sa sb x = rewrite andCommutative (sb x) (not $ sa x) in rewrite notInvolutive $ sb x in Refl -------------------------------------- --- Laws of symmetrical difference --- -------------------------------------- -- TODO To make this functon to have `(0 sa, sb : InSet a)` in the signature. export symdiff_as_union_of_diffs : (sa, sb : InSet a) -> sa ^ sb == (sa - sb) + (sb - sa) symdiff_as_union_of_diffs sa sb x = case (decEq (sa x) True, decEq (sb x) True) of (Yes pa, Yes pb) => rewrite pa in rewrite pb in Refl (Yes pa, No nb) => rewrite pa in rewrite notTrueIsFalse nb in Refl (No na, Yes pb) => rewrite notTrueIsFalse na in rewrite pb in Refl (No na, No nb) => rewrite notTrueIsFalse na in rewrite notTrueIsFalse nb in Refl -- TODO To make this functon to have `(0 sa, sb : InSet a)` in the signature. export symdiff_as_diff_of_ui : (sa, sb : InSet a) -> sa ^ sb == (sa + sb) - (sa # sb) symdiff_as_diff_of_ui sa sb x = case (decEq (sa x) True, decEq (sb x) True) of (Yes pa, Yes pb) => rewrite pa in rewrite pb in Refl (Yes pa, No nb) => rewrite pa in rewrite notTrueIsFalse nb in Refl (No na, Yes pb) => rewrite notTrueIsFalse na in rewrite pb in Refl (No na, No nb) => rewrite notTrueIsFalse na in rewrite notTrueIsFalse nb in Refl export symdiff_commutative : (0 sa, sb : InSet a) -> sa ^ sb == sb ^ sa symdiff_commutative sa sb x = rewrite xorCommutative (sa x) (sb x) in Refl export symdiff_associative : (0 sa, sb, sc : InSet a) -> sa ^ (sb ^ sc) == (sa ^ sb) ^ sc symdiff_associative sa sb sc x = rewrite xorAssociative (sa x) (sb x) (sc x) in Refl export symdiff_with_empty : (0 s : InSet a) -> s ^ [] == s symdiff_with_empty s x = rewrite xorCommutative (s x) False in rewrite xorFalseNeutral $ s x in Refl export symdiff_with_self : (0 s : InSet a) -> s ^ s == [] symdiff_with_self s x = rewrite xorSameFalse $ s x in Refl -- TODO To make this functon to have `(0 sa, sb, sc : InSet a)` in the signature. export symdiff_twice_negates : (sa, sb, sc : InSet a) -> (sa ^ sb) ^ (sb ^ sc) == sa ^ sc symdiff_twice_negates sa sb sc x = rewrite xorCommutative (sa x) (sb x) in case decEq (sb x) True of Yes pb => rewrite pb in rewrite xorTrueNot $ sa x in rewrite xorTrueNot $ sc x in rewrite notXorCancel (sa x) (sc x) in Refl No nb => rewrite notTrueIsFalse nb in rewrite xorFalseNeutral $ sa x in rewrite xorFalseNeutral $ sc x in Refl export symdiff_of_complements : (0 sa, sb : InSet a) -> sa ^ sb == complement sa ^ complement sb symdiff_of_complements sa sb x = rewrite notXorCancel (sa x) (sb x) in Refl -------------------------- --- Laws of complement --- -------------------------- export comp_of_union : (0 sa, sb : InSet a) -> complement (sa + sb) == complement sa # complement sb comp_of_union sa sb x = rewrite notOrIsAnd (sa x) (sb x) in Refl export comp_of_intersection : (0 sa, sb : InSet a) -> complement (sa # sb) == complement sa + complement sb comp_of_intersection sa sb x = rewrite notAndIsOr (sa x) (sb x) in Refl export comp_of_empty : complement [] == Universe comp_of_empty _ = Refl export comp_of_universe : complement Universe == [] comp_of_universe _ = Refl export comp_involutive : (0 s : InSet a) -> complement (complement s) == s comp_involutive s x = rewrite notInvolutive $ s x in Refl export comp_of_diff : (0 sa, sb : InSet a) -> complement (sa - sb) == complement sa + sb comp_of_diff sa sb x = rewrite notAndIsOr (sa x) (not $ sb x) in rewrite notInvolutive $ sb x in Refl --------------------------------- --- Laws of cartesian product --- --------------------------------- --- Operations over cartesian products at both sides: export intersection_of_carts : (0 sa, sb : InSet a) -> (0 sc, sd : InSet c) -> (sa * sc) # (sb * sd) == (sa # sb) * (sc # sd) intersection_of_carts sa sb sc sd (x, y) = rewrite sym $ andAssociative (sa x) (sc y) (sb x && sd y) in rewrite sym $ andAssociative (sa x) (sb x) (sc y && sd y) in rewrite andAssociative (sc y) (sb x) (sd y) in rewrite andAssociative (sb x) (sc y) (sd y) in rewrite andCommutative (sb x) (sc y) in Refl export diff_of_carts : (0 sa, sb : InSet a) -> (0 sc, sd : InSet c) -> (sa * sc) - (sb * sd) == sa * (sc - sd) + (sa - sb) * sc export union_of_carts : (0 sa, sb : InSet a) -> (0 sc, sd : InSet c) -> (sa * sc) + (sb * sd) == ((sa - sb) * sc) # ((sa # sb) * (sc + sd)) # ((sb - sa) * sd) --- Distributivity: export cart_distributes_over_intersection : (0 sa : InSet a) -> (0 sb, sc : InSet b) -> sa * (sb # sc) == (sa * sb) # (sa * sc) cart_distributes_over_intersection sa sb sc (x, y) = rewrite sym $ andAssociative (sa x) (sb y) (sa x && sc y) in rewrite andAssociative (sb y) (sa x) (sc y) in rewrite andCommutative (sb y) (sa x) in rewrite sym $ andAssociative (sa x) (sb y) (sc y) in rewrite andAssociative (sa x) (sa x) (sb y && sc y) in rewrite andSameNeutral (sa x) in Refl export cart_distributes_over_union : (0 sa : InSet a) -> (0 sb, sc : InSet b) -> sa * (sb + sc) == (sa * sb) + (sa * sc) export cart_distributes_over_diff : (0 sa : InSet a) -> (0 sb, sc : InSet b) -> sa * (sb - sc) == (sa * sb) - (sa * sc) export complement_of_cart : (0 sa : InSet a) -> (0 sb : InSet b) -> complement (sa * sb) = (complement sa * complement sb) + (complement sa * sb) + (sa * complement sb) --- Cartesian products with relations export subset_of_carts_drops_l : {0 sa, sb : InSet a} -> {0 sc, sd : InSet c} -> (0 _ : NotEmpty sa) -> (0 _ : NotEmpty sc) -> (0 _ : (sa * sc) <= (sb * sd)) -> sa <= sb export subset_of_carts_drops_r : {0 sa, sb : InSet a} -> {0 sc, sd : InSet c} -> (0 _ : NotEmpty sa) -> (0 _ : NotEmpty sc) -> (0 _ : (sa * sc) <= (sb * sd)) -> sc <= sd export cart_of_subsets : {0 sa, sb : InSet a} -> {0 sc, sd : InSet c} -> (0 _ : sa <= sb) -> (0 _ : sc <= sd) -> (sa * sc) <= (sb * sd)
module contactForceLaw_ballWithBall using Modia3D using Modia3D.StaticArrays import Modia3D.ModiaMath vmat1 = Modia3D.Material(color="LightBlue" , transparency=0.5) # material of SolidFileMesh vmat11 = Modia3D.Material(color="Red" , transparency=0.5) vmat2 = deepcopy(vmat1) # material of convex decomposition of SolidFileMesh vmat2.transparency = 0.7 cmat = "Steel" @assembly BallWithBall begin world = Modia3D.Object3D(visualizeFrame=true) sphereMoving = Modia3D.Object3D(world, Modia3D.Solid(Modia3D.SolidSphere(0.5) , "Steel", vmat11; contactMaterial = cmat); r=[0.0, 0.0, 0.0], fixed=false ) # , R=ModiaMath.rot2(-pi/2) ) sphere = Modia3D.Object3D(world, Modia3D.Solid(Modia3D.SolidSphere(1.0) , "Steel", vmat1; contactMaterial = cmat); r=[-3.0, 0.0, 0.0], fixed=true) #, R=ModiaMath.rot2(-pi/3) ) end gravField = Modia3D.UniformGravityField(g=9.81, n=[-1,0,0]) threeD = BallWithBall(sceneOptions=Modia3D.SceneOptions(gravityField=gravField,visualizeFrames=true, defaultFrameLength=0.7,nz_max = 100, enableContactDetection=true, visualizeContactPoints=true, visualizeSupportPoints=true)) model = Modia3D.SimulationModel( threeD ) result = ModiaMath.simulate!(model; stopTime=10.0, tolerance=1e-8,interval=0.001, log=false) println("... success of contactForceLaw_ballWithBall.jl!") end
program helloThread integer :: i,j,N,M integer :: nthread,OMP_GET_NUM_THREADS,OMP_GET_THREAD_NUM,tid N = 2 M = 4 nthread = 2 call omp_set_num_threads(nthread) !requests "nthread" threads !$OMP PARALLEL DO DO i=1,N DO j=1,M TID = OMP_GET_THREAD_NUM() print *, "Printing: i = ",i," j = ",j ,' from thread: ',TID END DO END DO !$OMP END PARALLEL DO end program helloThread
{-# OPTIONS --without-K --rewriting #-} module Classifying where open import Basics open import Flat open import lib.types.Sigma open import lib.Equivalence2 open import lib.types.Truncation BAut : ∀ {i} {X : Type i} (x : X) → Type i BAut {X = X} x = Σ X $ (\y → ∥ x == y ∥) ♭-commutes-with-BAut : {@♭ i : ULevel } (@♭ X : Type i) (@♭ x : X) → (♭ (BAut x)) ≃ BAut (x ^♭) ♭-commutes-with-BAut X x = ♭ (BAut x) ≃⟨ ♭-commutes-with-Σ ⟩ Σ (♭ X) (\u → let♭ y ^♭:= u in♭ (♭ ∥ x == y ∥)) ≃⟨ Σ-emap-r lemma₂ ⟩ Σ (♭ X) (\u → let♭ y ^♭:= u in♭ ∥ ♭ (x == y) ∥) ≃⟨ Σ-emap-r lemma₁ ⟩ BAut (x ^♭) ≃∎ where lemma₁ : (z : ♭ X) → (let♭ y ^♭:= z in♭ ∥ ♭ (x == y) ∥) ≃ ∥ (x ^♭) == z ∥ lemma₁ (z ^♭) = Trunc-emap (♭-identity-eq x z) lemma₂ : (z : ♭ X) → (let♭ y ^♭:= z in♭ (♭ ∥ x == y ∥)) ≃ (let♭ y ^♭:= z in♭ ∥ ♭ (x == y) ∥) lemma₂ (z ^♭) = (♭-Trunc-eq (x == z)) ⁻¹ _is-locally-crisply-discrete : {@♭ i : ULevel} (@♭ X : Type i) → Type i _is-locally-crisply-discrete X = (@♭ x y : X) → (x == y) is-discrete
// ============================================================================= // == IMG.h // == -------------------------------------------------------------------------- // == An image class to be used with temporal superpixels. // == // == All work using this code should cite: // == J. Chang, D. Wei, and J. W. Fisher III. A Video Representation Using // == Temporal Superpixels. CVPR 2013. // == -------------------------------------------------------------------------- // == Written by Jason Chang and Donglai Wei 06-20-2013 // ============================================================================= #ifndef _IMG_H_INCLUDED_ #define _IMG_H_INCLUDED_ #include <iostream> #include <fstream> #include "utils.h" #include "SP.h" #include "NormalD.h" #include "topology.h" #include "array.h" #include <gsl/gsl_linalg.h> #include <gsl/gsl_blas.h> #include "helperMEX.h" using namespace std; class IMG { private: int debug; int xdim; int ydim; int N; arr(double) data; arr(int) label; int K; //NIW new_pos; NormalD new_pos; NormalD new_app; arr(SP*) SP_arr; SP* SP_new; // a pointer to an exemplar "new" SP arr(bool) SP_old; // indicates the SPs that are from a prev frame arr(bool) SP_changed; // indicates which SPs changed in the previous iteration arr(linkedListNode<int>*) border_ptr; arr(linkedListNode<int>*) pixel_ptr; arr(double) T4Table; double log_alpha; // size parameter double log_beta; double area; double area_var; double log_area_var; unsigned long max_UID; double lambda; // flow parameters double lambda_sigma; arr(int) prev_label; arr(double) prev_app_mean; arr(double) prev_pos_mean; int prev_K; arr(double) prev_covariance; arr(double) prev_precision; linkedList< std::pair<int, int> > prev_neighbors; linkedList< double > prev_neighbors_scale; bool alive_dead_changed; double dummy_log_prob; arr(bool) boundary_mask; // flow stuff gsl_vector *vgsl; gsl_vector *ugsl; arr(double) Sxy; arr(double) Syy; arr(double) SxySyy; arr(double) obs_u; arr(double) obs_v; arr(double) temp_Syy; arr(double) temp_d; arr(bool) temp_still_alive; int num_alive; int num_dead; arr(int) all2alive; arr(int) alive2all; arr(int) all2dead; arr(int) dead2all; public: IMG(); virtual ~IMG(); void ReadIMG(); void mxReadIMG(const mxArray *mstruct); void mxWriteIMG(mxArray* plhs[], const mxArray* oldstruct); // -------------------------------------------------------------------------- // -- move_local // -- finds the optimal local joint move of labels and parameters. Chooses // -- a super pixel at random and loops through and updates its borders. // -------------------------------------------------------------------------- bool move_local_IMG(); bool move_switch_IMG(); // -------------------------------------------------------------------------- // -- move_merge // -- finds the optimal merge between all pairs of super pixels // -------------------------------------------------------------------------- void move_merge_IMG(); void move_split_IMG(); void move_IMG(); void Flow_QP2(); void find_SxySyy(arr(int) all2alive, arr(int) alive2all, arr(int) all2dead, arr(int) dead2all); private: // // -- 1. I/O void U_initialize(); void U_relabel_SP(bool final=false); double U_calc_energy(); double U_calc_model_order(int N, bool is_old); // -- 3. border bookkeeping bool U_check_border_pix(int index); bool U_check_border_pix(int index, int cur_label); void U_find_border_SP(int k,arr(bool) neighbors,linkedList<int> &neighborsLL); // -------------------------------------------------------------------------- // -- U_update_border_changed // -- Updates all border linked lists and pointers for the neighbors of a // -- changed pixel at index. // -- // -- parameters: // -- - index : the index of the recently changed pixel // -------------------------------------------------------------------------- void U_update_border_changed(int index); // -------------------------------------------------------------------------- // -- U_update_border_changed_pixel // -- Updates all border linked lists and pointers at index // -- // -- parameters: // -- - index : the index of the recently changed pixel // -------------------------------------------------------------------------- void U_update_border_changed_pixel(int index); // -------------------------------------------------------------------------- // -- U_update_neighbor_list // -- Updates super pixel neighbors used in merge // -- // -- parameters: // -- - neighbors : a boolean array indicating which labels are added // -- - neighborsLL : a linked list of the neighbor indices // -- - index : the index of the point to consider adding // -------------------------------------------------------------------------- void U_update_neighbor_list(arr(bool) neighbors, linkedList<int> &neighborsLL, int index); void U_fix_neighbors_self(int k); void U_fix_neighbors_neighbors(int k); void U_fix_neighbors_neighbors(int k, int kignore); void U_print_neighbors(int k); // -------------------------------------------------------------------------- // -- U_update_neighbors_rem // -- Updates all neighbor lists when a pixel is "removed". A subsequent // -- call to update_neighbors_add should be completed right after this one. // -- The neighboring label should be changed before calling this function. // -- // -- parameters: // -- - old_label : the label of the pixel before it was changed // -- - index : the index bordering the removed pixel // -------------------------------------------------------------------------- void U_update_neighbors_rem(int old_label, int index); // -------------------------------------------------------------------------- // -- U_update_neighbors_add // -- Updates all neighbor lists when a pixel is "added". A previous // -- call to update_neighbors_rem should be completed right before this one. // -- The neighboring label should be changed before calling this function. // -- // -- parameters: // -- - index : the index bordering the removed pixel // -------------------------------------------------------------------------- void U_update_neighbors_add(int index); // -------------------------------------------------------------------------- // -- U_update_neighbors_merge // -- Updates the neighbor lists for merging two super pixels. // -- All labels and SP_arr things should be updated *before* calling this. // -- // -- parameters: // -- - index : the index bordering the removed pixel // -------------------------------------------------------------------------- void U_update_neighbors_merge(int new_label, int old_label); // -------------------------------------------------------------------------- // -- U_update_neighbors_split // -- Updates the neighbor lists for merging two super pixels. // -- All labels and SP_arr things should be updated *before* calling this. // -- // -- parameters: // -- - index : the index bordering the removed pixel // -------------------------------------------------------------------------- void U_update_neighbors_split(int label1, int label2); // -- 4. Modularized Move // -- 4.0 Change of Energy // -------------------------------------------------------------------------- // -- link_cost // -- calculates the energy of linking SP_arr[ko] (old) to SP_arr[kn] (new) // -- // -- parameters: // -- - ko : the old k // -- - kn : the new k // -------------------------------------------------------------------------- double link_cost(int ko, int kn); double move_local_calc_delta_MM(int index, int new_k, double& max_prob, int& max_k); // -------------------------------------------------------------------------- // -- move_local_calc_neigbor // -- calculates the probability of assigning the pixel at index to the // -- cluster of nindex (neighbor index). Updates the max_prob and max_k if // -- the new_app value is greater than the old one // -- // -- parameters: // -- - index : the new point to add // -- - new_k : the neighbor to add this point to // -- - max_prob : the maximum probability of all neighbors // -- - max_k : the super pixel index of the maximum probability // -------------------------------------------------------------------------- double move_local_calc_delta(int index, int new_k, bool add, double& max_prob, int& max_k); double move_switch_calc_delta(SP* &oldSP, SP* &newSP); // -------------------------------------------------------------------------- // -- move_merge_calc_delta // -- calculates the probability of assigning the pixel at index to the // -- cluster of nindex (neighbor index). // -- // -- parameters: // -- - index : the new point to add // -- - nindex : the neighbor to add this point to // -------------------------------------------------------------------------- double move_merge_calc_delta(int k, int merge_k); // -------------------------------------------------------------------------- // -- move_split_calc_delta // -- calculates the change in energy for // -- (k1 U new_k1) && (k2 U new_k2) - (k1 U new_k1 U new_k) && (k2) // -- // -- parameters: // -- - SP1 : the SP that originates the splitting // -- - SP2 : the SP to split to // -- - new_SP1 : temporary SP that contains pixels that will go in k1 // -- - new_SP2 : temporary SP that contains pixels that will go in k2 // -- - SP1_old : indicates if SP1 is an old SP // -- - SP2_old : indicates if SP2 is an old SP // -------------------------------------------------------------------------- double move_split_calc_delta(SP* SP1, SP* SP2, SP* new_SP1, SP* new_SP2, bool SP1_old, bool SP2_old); // -- 4.1 move local // need to be done int move_local_SP_region(int k,linkedList<int> &check_labels); int move_local_SP(int k); // need to be done int move_local_pix(int index); //-- 4.2 move merge void move_merge_SP_propose(int k,arr(bool) neighbors,double &max_E,int &max_k); void move_merge_SP_propose_region(int k,arr(bool) neighbors, linkedList<int> &check_labels,double &max_E,int &max_k); void move_merge_SP(int k,arr(bool) neighbors); // -- 4.3 move split void move_split_SP(int k); bool U_Kmeans_plusplus(int k, int *bbox, int num_SP, int numiter, int index2=-1); void U_connect_newSP(int *bbox, int num_SP); double U_dist(int index1 , double* center); double U_dist(int index1 , int index2); void move_split_SP_propose(int index, int num_SP, int option, double &max_E,int &ksplit,int* new_ks); }; #endif
// // Licensed to Green Energy Corp (www.greenenergycorp.com) under one or // more contributor license agreements. See the NOTICE file distributed // with this work for additional information regarding copyright ownership. // Green Energy Corp licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // This file was forked on 01/01/2013 by Automatak, LLC and modifications // have been made to this file. Automatak, LLC licenses these modifications to // you under the terms of the License. // #include "PhysicalLayerAsyncBaseTCP.h" #include <string> #include <functional> #include <boost/asio.hpp> #include <boost/asio/ip/tcp.hpp> #include <opendnp3/Exception.h> #include <opendnp3/Logger.h> #include "IHandlerAsync.h" #include "LoggableMacros.h" using namespace boost; using namespace boost::asio; using namespace boost::system; using namespace std; namespace opendnp3 { PhysicalLayerAsyncBaseTCP::PhysicalLayerAsyncBaseTCP(Logger* apLogger, boost::asio::io_service* apIOService) : PhysicalLayerAsyncASIO(apLogger, apIOService), mSocket(*apIOService) { //mSocket.set_option(ip::tcp::no_delay(true)); } /* Implement the actions */ void PhysicalLayerAsyncBaseTCP::DoClose() { this->ShutdownSocket(); this->CloseSocket(); } void PhysicalLayerAsyncBaseTCP::DoAsyncRead(uint8_t* apBuffer, size_t aMaxBytes) { mSocket.async_read_some(buffer(apBuffer, aMaxBytes), mStrand.wrap( std::bind(&PhysicalLayerAsyncBaseTCP::OnReadCallback, this, std::placeholders::_1, apBuffer, std::placeholders::_2) )); } void PhysicalLayerAsyncBaseTCP::DoAsyncWrite(const uint8_t* apBuffer, size_t aNumBytes) { async_write(mSocket, buffer(apBuffer, aNumBytes), mStrand.wrap( std::bind(&PhysicalLayerAsyncBaseTCP::OnWriteCallback, this, std::placeholders::_1, aNumBytes) )); } void PhysicalLayerAsyncBaseTCP::DoOpenFailure() { LOG_BLOCK(LEV_DEBUG, "Failed socket open, closing socket"); this->CloseSocket(); } void PhysicalLayerAsyncBaseTCP::CloseSocket() { boost::system::error_code ec; mSocket.close(ec); if(ec) LOG_BLOCK(LEV_WARNING, "Error while closing socket: " << ec.message()); } void PhysicalLayerAsyncBaseTCP::ShutdownSocket() { boost::system::error_code ec; mSocket.shutdown(ip::tcp::socket::shutdown_both, ec); if(ec) LOG_BLOCK(LEV_WARNING, "Error while shutting down socket: " << ec.message()); } } /* vim: set ts=4 sw=4: */
From RecordUpdate Require Import RecordSet. From Perennial.program_proof Require Import disk_lib. From Perennial.program_proof Require Import wal.invariant. Section goose_lang. Context `{!heapGS Σ}. Context `{!walG Σ}. Implicit Types (γ: wal_names). Context (P: log_state.t -> iProp Σ). Hint Unfold slidingM.wf : word. Hint Unfold slidingM.numMutable : word. Lemma logIndex_set_mutable f σ pos : slidingM.logIndex (set slidingM.mutable f σ) pos = slidingM.logIndex σ pos. Proof. rewrite /slidingM.logIndex //=. Qed. Lemma stable_alloc_end γ txns mutable nextDiskEnd_txn_id endpos : ( memLog_linv_nextDiskEnd_txn_id γ mutable nextDiskEnd_txn_id ∗ nextDiskEnd_inv γ txns ∗ txns_ctx γ txns ∗ txn_pos γ (length txns - 1) endpos ) ==∗ ( memLog_linv_nextDiskEnd_txn_id γ endpos (length txns - 1) ∗ nextDiskEnd_inv γ txns ∗ txns_ctx γ txns ∗ (length txns - 1)%nat [[γ.(stable_txn_ids_name)]]↦ro tt ). Proof. iIntros "(H0 & H1 & Htxns_ctx & #Hend)". iNamed "H1". iNamed "H0". iDestruct (txn_pos_valid_general with "Htxns_ctx HnextDiskEnd_txn") as "%HnextDiskEnd_txn". eapply is_txn_bound in HnextDiskEnd_txn as HnextDiskEnd_bound. iDestruct (map_ctx_agree with "HownStableSet Hstablectx") as %->. iCombine "HownStableSet Hstablectx" as "Hstablectx". destruct (stable_txns !! (length txns - 1)%nat) eqn:He. { iDestruct (big_sepM_lookup with "Hstablero") as "#Hstable"; eauto. iModIntro. iDestruct "Hstablectx" as "[Hstablectx HownStableSet]". iFrame "Htxns_ctx Hstable". iSplitL "HownStableSet". { iExists _. iFrame. iFrame "# %". iPureIntro. intros. eapply HnextDiskEnd_max_stable. lia. } iExists _. iFrame. iFrame "%". } iMod (map_alloc_ro with "Hstablectx") as "[Hstablectx #Hstable]"; eauto. iDestruct (big_sepM_insert with "[$Hstablero $Hstable]") as "Hstablero"; eauto. iModIntro. iDestruct "Hstablectx" as "[Hstablectx HownStableSet]". iFrame "Htxns_ctx Hstable". iSplitL "HownStableSet". { iExists _. iFrame. iFrame "# %". iPureIntro. intros. rewrite lookup_insert_ne; try lia. eapply HnextDiskEnd_max_stable. lia. } iExists _. iFrame. iPureIntro. rewrite /stable_sound. intros. destruct (decide (txn_id = (length txns - 1)%nat)); subst. { eapply is_txn_bound in H2. lia. } rewrite lookup_insert_ne in H0; eauto. Qed. Theorem wp_sliding__clearMutable_wal l st γ dinit σ : {{{ is_wal P l γ dinit ∗ wal_linv_core st γ σ }}} sliding__clearMutable (struct.loadF WalogState "memLog" #st) {{{ σ', RET #(); wal_linv_core st γ σ' ∗ ⌜length σ.(memLog).(slidingM.log) = length σ'.(memLog).(slidingM.log)⌝ }}}. Proof. iIntros (Φ) "(#Hwal & Hlkinv) HΦ". iNamed "Hlkinv". iNamed "Hfields". iNamed "Hfield_ptsto". rewrite -wp_ncfupd. iDestruct (is_sliding_wf with "His_memLog") as %Hsliding_wf. wp_loadField. wp_apply (wp_sliding__clearMutable with "His_memLog"). iIntros "His_memLog". wp_pures. iApply ("HΦ" $! (set memLog (λ _, (set slidingM.mutable (λ _ : u64, slidingM.endPos σ.(memLog)) σ.(memLog))) σ )). iNamed "HmemLog_linv". iNamed "Hlinv_pers". iDestruct "HmemStart_txn" as "#HmemStart_txn". iDestruct "HmemEnd_txn" as "#HmemEnd_txn". iMod (txn_pos_valid_locked with "Hwal HmemEnd_txn Howntxns") as "(%HmemEnd_is_txn & Howntxns)". iAssert (txn_pos γ nextDiskEnd_txn_id σ.(memLog).(slidingM.mutable)) as "#HnextDiskEnd_txn0". { iNamed "HnextDiskEnd". iFrame "#". } iMod (txn_pos_valid_locked with "Hwal HnextDiskEnd_txn0 Howntxns") as "(%HnextDiskEnd_is_txn0 & Howntxns)". iDestruct "Hwal" as "[Hinv Hcirc]". iInv "Hinv" as (σs) "[Hinner Hp]" "Hclose". iDestruct "Hinner" as "(>%Hwf & Hmem & >Htxns_ctx & >γtxns & >HnextDiskEnd_inv & >Hdisk)". iDestruct (ghost_var_agree with "Howntxns γtxns") as %->. iMod (stable_alloc_end with "[$HnextDiskEnd $HnextDiskEnd_inv $Htxns_ctx $HmemEnd_txn]") as "H". iDestruct "H" as "(HnextDiskEnd & HnextDiskEnd_inv & Htxns_ctx & #Hstable)". iMod ("Hclose" with "[γtxns Hmem HnextDiskEnd_inv Hdisk Htxns_ctx Hp]"). { iModIntro. iExists _. iFrame. done. } iModIntro. iDestruct (is_sliding_wf with "His_memLog") as %Hsliding_wf'. simpl. iSplitL; last by trivial. iFrame "# ∗". iSplitR "Howntxns HownLoggerPos_linv HownLoggerTxn_linv HnextDiskEnd HownInstallerPosMem_linv HownInstallerTxnMem_linv HownInstalledTxnMem_linv". { iExists _; iFrame. iPureIntro. split_and!; simpl; auto; try word. rewrite /slidingM.endPos. unfold locked_wf, slidingM.wf in Hlocked_wf. word. } eapply is_txn_bound in HdiskEnd_txn as HdiskEnd_txn_bound. eapply is_txn_bound in HnextDiskEnd_is_txn0 as HnextDiskEnd_txn0_bound. destruct (decide (int.Z σ.(memLog).(slidingM.mutable) ≤ int.Z (slidingM.endPos σ.(memLog)))). 2: { epose proof (wal_wf_txns_mono_pos Hwf HmemEnd_is_txn HnextDiskEnd_is_txn0). lia. } iExists installed_txn_id_mem, (length σs.(log_state.txns) - 1)%nat, σs.(log_state.txns), _, _, _, _; simpl. iFrame "Howntxns HownLoggerPos_linv HownLoggerTxn_linv". iFrame "HmemStart_txn HmemEnd_txn". iFrame "HownInstallerPosMem_linv HownInstallerTxnMem_linv HownInstalledTxnMem_linv". iFrame "% HinstalledTxn_lb". iSplit. 2: { iNamed "HnextDiskEnd". iExists _. iFrame. iFrame "#". iFrame "%". } iSplit. { iPureIntro. lia. } iSplit. { iPureIntro. lia. } iSplit. 2: { iPureIntro. rewrite /slidingM.endPos. word. } iPureIntro. rewrite /memLog_linv_txns !logIndex_set_mutable /slidingM.endPos /mwrb.logend /slidingM.logIndex /=. rewrite /memLog_linv_txns /mwrb.logend /slidingM.logIndex in Htxns. replace (S (_ - 1))%nat with (length σs.(log_state.txns)); last by lia. eapply (is_memLog_boundaries_move _ _ _ mwrb_us) in Htxns; last by reflexivity. simpl in Htxns. replace (int.nat (word.add _ _) - int.nat _)%nat with (length σ.(memLog).(slidingM.log)) by word. assumption. Qed. Theorem wp_endGroupTxn st γ : {{{ wal_linv st γ }}} WalogState__endGroupTxn #st {{{ RET #(); wal_linv st γ }}}. Proof. iIntros (Φ) "Hlkinv HΦ". iNamed "Hlkinv". iNamed "Hfields". iNamed "Hfield_ptsto". iNamed "His_memLog". iNamed "Hinv". iNamed "needFlush". wp_call. wp_loadField. wp_storeField. iApply "HΦ". iModIntro. iExists _. iFrame. iExists _. iFrame (Hlocked_wf Hwf) "∗". iExists _, _. iFrame "∗ #". iExists _. iFrame. Qed. Lemma is_txn_mid σ (a b c : nat) pos : wal_wf σ -> is_txn σ.(log_state.txns) a pos -> is_txn σ.(log_state.txns) c pos -> a ≤ b ≤ c -> is_txn σ.(log_state.txns) b pos. Proof. rewrite /is_txn /wal_wf; intros Hwf Ha Hc Hle. destruct Hwf as [_ [Hwf _]]. destruct (decide (a < b)). 2: { assert (a = b) by lia; subst; eauto. } destruct (decide (b < c)). 2: { assert (b = c) by lia; subst; eauto. } assert (is_Some (σ.(log_state.txns) !! b)). { eapply lookup_lt_is_Some_2. etransitivity. 2: { eapply lookup_lt_is_Some_1. eapply fmap_is_Some. eauto. } lia. } destruct H as [tb Hb']. assert (fst <$> σ.(log_state.txns) !! b = Some (fst tb)) as Hb. { rewrite Hb'. reflexivity. } rewrite -list_lookup_fmap in Ha. rewrite -list_lookup_fmap in Hb. rewrite -list_lookup_fmap in Hc. rewrite -list_lookup_fmap. eapply Hwf in Ha as Hab'. 1: eapply Hab' in Hb as Hab. 2: lia. eapply Hwf in Hb as Hbc'. 1: eapply Hbc' in Hc as Hbc. 2: lia. rewrite Hb. f_equal. word. Qed. Lemma subslice_stable_nils γ σ (txn_id txn_id' : nat) pos : wal_wf σ -> txn_id ≤ txn_id' -> is_txn σ.(log_state.txns) txn_id pos -> is_txn σ.(log_state.txns) txn_id' pos -> ( nextDiskEnd_inv γ σ.(log_state.txns) ∗ txn_id [[γ.(stable_txn_ids_name)]]↦ro () ) -∗ ⌜Forall (λ x, snd x = nil) (subslice (S txn_id) (S txn_id') σ.(log_state.txns))⌝. Proof. intros. iIntros "[Hinv Hstable]". iNamed "Hinv". iDestruct (map_ro_valid with "Hstablectx Hstable") as "%Hvalid". iPureIntro. apply Forall_lookup_2; intros. apply subslice_lookup_some in H3 as H3'. assert (snd <$> σ.(log_state.txns) !! (S txn_id + i)%nat = Some x.2). { rewrite H3'. eauto. } erewrite HafterNextDiskEnd in H4; simplify_eq/=; eauto. { lia. } eapply is_txn_mid; [ done | apply H1 | apply H2 |]. apply subslice_lookup_bound' in H3. lia. Qed. Lemma subslice_stable_nils2 γ σ (txn_id txn_id' : nat) pos : wal_wf σ -> is_txn σ.(log_state.txns) txn_id pos -> is_txn σ.(log_state.txns) txn_id' pos -> ( nextDiskEnd_inv γ σ.(log_state.txns) ∗ txn_id [[γ.(stable_txn_ids_name)]]↦ro () ) -∗ ⌜Forall (λ x, snd x = nil) (subslice (S txn_id) (S txn_id') σ.(log_state.txns))⌝. Proof. intros. iIntros "[Hinv Hstable]". destruct (decide (txn_id ≤ txn_id')). { iApply subslice_stable_nils; eauto. } iPureIntro. rewrite /subslice. rewrite drop_ge; eauto. etransitivity; first by apply firstn_le_length. lia. Qed. Lemma stable_sound_alloc txns stable_txns (txn_id txn_id' : nat) (pos : u64) : stable_txns !! txn_id = Some () -> txn_id ≤ txn_id' -> is_txn txns txn_id pos -> is_txn txns txn_id' pos -> stable_sound txns stable_txns -> stable_sound txns (<[txn_id':=()]> stable_txns). Proof. rewrite /stable_sound. intros. destruct (decide (txn_id' = txn_id0)). { subst. eapply (H3 txn_id txn_id'0 pos); try eassumption. 1: lia. pose proof (is_txn_pos_unique _ _ _ _ H2 H6); subst. eauto. } eapply H3; try eassumption. rewrite lookup_insert_ne in H5; eauto. Qed. Lemma stable_sound_nils σ stable_txns txn_id txn_id' pos : wal_wf σ -> stable_txns !! txn_id = Some () -> is_txn σ.(log_state.txns) txn_id pos -> is_txn σ.(log_state.txns) txn_id' pos -> stable_sound σ.(log_state.txns) stable_txns -> Forall (λ x, x.2 = []) (subslice (S txn_id) (S txn_id') σ.(log_state.txns)). Proof. intros. apply Forall_lookup_2; intros. apply subslice_lookup_some in H4 as H4'. assert (snd <$> σ.(log_state.txns) !! (S txn_id + i)%nat = Some x.2). { rewrite H4'. eauto. } erewrite H3 in H5; simplify_eq/=; eauto. { lia. } eapply is_txn_mid; [ done | apply H1 | apply H2 | ]. eapply subslice_lookup_bound' in H4 as Hbound. lia. Qed. Theorem stable_txn_id_advance γ mutable txn_id txn_id' pos nextDiskEnd_txn_id σ : wal_wf σ -> is_txn σ.(log_state.txns) txn_id pos -> is_txn σ.(log_state.txns) txn_id' pos -> txn_id ≤ txn_id' -> memLog_linv_nextDiskEnd_txn_id γ mutable nextDiskEnd_txn_id -∗ nextDiskEnd_inv γ σ.(log_state.txns) -∗ txn_id [[γ.(stable_txn_ids_name)]]↦ro () -∗ txns_ctx γ σ.(log_state.txns) ==∗ ( txn_id' [[γ.(stable_txn_ids_name)]]↦ro () ∗ nextDiskEnd_inv γ σ.(log_state.txns) ∗ txns_ctx γ σ.(log_state.txns) ∗ ∃ nextDiskEnd_txn_id', memLog_linv_nextDiskEnd_txn_id γ mutable nextDiskEnd_txn_id' ∗ ⌜nextDiskEnd_txn_id ≤ nextDiskEnd_txn_id' < length σ.(log_state.txns)⌝ ∗ ⌜Forall (λ x, x.2 = []) (subslice (S nextDiskEnd_txn_id) (S nextDiskEnd_txn_id') σ.(log_state.txns))⌝ ). Proof. clear P. iIntros (Hwf Histxn Histxn' Hle) "H0 H1 #Hstable Htxns_ctx". iNamed "H0". iNamed "H1". iDestruct (map_ctx_agree with "HownStableSet Hstablectx") as "%Heq". subst. iDestruct (map_valid with "HownStableSet Hstable") as "%Hstable". iDestruct (map_valid with "Hstablectx HnextDiskEnd_stable") as "%HnextDiskEnd_stable". iDestruct (txn_pos_valid_general with "Htxns_ctx HnextDiskEnd_txn") as "%HnextDiskEnd_txn". destruct (stable_txns0 !! txn_id') eqn:He. { iDestruct (big_sepM_lookup with "Hstablero") as "#Hstable'"; eauto. iModIntro. iFrame "Hstable' Htxns_ctx". iSplitL "Hstablectx Hstablero". { iExists _. iFrame. iFrame "%". } iExists nextDiskEnd_txn_id. iSplitL "HownStableSet". { iExists _. iFrame. iFrame "#". iFrame "%". } rewrite subslice_zero_length. eapply is_txn_bound in HnextDiskEnd_txn. iPureIntro. intuition eauto; lia. } iCombine "HownStableSet Hstablectx" as "Hctx". iMod (map_alloc_ro with "Hctx") as "[Hctx #Hstable']"; eauto. iDestruct (big_sepM_insert with "[$Hstablero Hstable']") as "Hstablero"; eauto. iFrame "Hstable'". iModIntro. iDestruct "Hctx" as "[HownStableSet Hstablectx]". iSplitL "Hstablectx Hstablero". { iExists _. iFrame "Hstablectx". iFrame. iPureIntro. eapply stable_sound_alloc. 1: apply Hstable. all: eauto. } destruct (decide (txn_id' ≤ nextDiskEnd_txn_id)). { iFrame "Htxns_ctx". iExists nextDiskEnd_txn_id. iSplitL "HownStableSet". { iExists _. iFrame. iFrame "#". iPureIntro. intros. destruct (decide (txn_id0 = txn_id')); try lia. rewrite lookup_insert_ne; eauto. } iPureIntro. rewrite subslice_zero_length. eapply is_txn_bound in HnextDiskEnd_txn. intuition eauto; lia. } destruct (decide (nextDiskEnd_txn_id < txn_id)). { rewrite HnextDiskEnd_max_stable in Hstable; try lia. congruence. } assert (is_txn σ.(log_state.txns) nextDiskEnd_txn_id pos) as Hnextpos. { eapply (is_txn_mid _ txn_id _ txn_id'); eauto. word. } pose proof (is_txn_pos_unique _ _ _ _ HnextDiskEnd_txn Hnextpos); subst. iDestruct (txns_ctx_txn_pos _ _ txn_id' with "Htxns_ctx") as "#Htxn_id'_pos"; eauto. iFrame. iExists txn_id'. iSplit. { iExists _. iFrame. iFrame "Hstable'". iFrame "Htxn_id'_pos". iPureIntro. intros. rewrite lookup_insert_ne; last by lia. eapply HnextDiskEnd_max_stable. lia. } eapply is_txn_bound in Histxn' as Histxn'_bound. iPureIntro. intuition try lia. eapply stable_sound_nils; eauto. Qed. End goose_lang.
Require Import CS Contractive ContractiveFacts Equiv NonEquiv Shape ShapeFacts Sty StyInd Subst SubstFacts Tac TL TLFacts Wf WfFacts. Lemma cs_shape : forall S, Contractive S -> shape (cs S) = unitS \/ shape (cs S) = sendS \/ shape (cs S) = recvS \/ shape (cs S) = ichoiceS \/ shape (cs S) = echoiceS \/ shape (cs S) = varS. Proof. induction S using (well_founded_ind lt_Sty_mu_prefix_wf); intros; destruct S; cs_simpl; eauto 10 with contractive subst. Qed. Lemma cs_mu_absurd : forall S X S', Contractive S -> cs S <> mu X S'. Proof. introv Hok H. eapply cs_shape in Hok. decompose_or_auto; shape_inv_auto; discriminate. Qed. Hint Extern 1 => let step S X S' := (exfalso; apply (cs_mu_absurd S X S')) in match goal with | H : cs ?S = mu ?X ?S' |- _ => step S X S' | H : mu ?X ?S' = cs ?S |- _ => symmetry in H; step S X S' end : subst. Lemma cs_preserves_Sequiv : forall S S', Contractive S -> Contractive S' -> Sequiv S S' -> Sequiv (cs S) (cs S'). Proof. apply ( Sty_ind_mu_prefix2 (fun S S' => Contractive S -> Contractive S' -> Sequiv S S' -> Sequiv (cs S) (cs S')) ). introv IH Hcontr Hcontr' Heq. inverts2 Heq; cs_simpl; eauto 10 with contractive subst. Qed. Hint Resolve cs_preserves_Sequiv : subst. Lemma uncs_preserves_Sequiv_l : forall S S', Contractive S -> Sequiv (cs S) S' -> Sequiv S S'. Proof. induction S using (well_founded_ind lt_Sty_mu_prefix_wf); intros; destruct S; cs_simpl; eauto 10 with contractive subst. Qed. Lemma uncs_preserves_Sequiv_r : forall S S', Contractive S' -> Sequiv S (cs S') -> Sequiv S S'. Proof. induction S' using (well_founded_ind lt_Sty_mu_prefix_wf); intros; destruct S'; cs_simpl; eauto 10 with contractive subst. Qed. Lemma uncs_preserves_Sequiv : forall S S', Contractive S -> Contractive S' -> Sequiv (cs S) (cs S') -> Sequiv S S'. Proof. intros. eapply uncs_preserves_Sequiv_l; eauto. eapply uncs_preserves_Sequiv_r; eauto. Qed. Lemma cs_preserves_Sequiv_l : forall S S', Contractive S -> Contractive S' -> Sequiv S S' -> Sequiv (cs S) S'. Proof. intros. eapply uncs_preserves_Sequiv_r; eauto. eapply cs_preserves_Sequiv; eauto. Qed. Lemma cs_preserves_Sequiv_r : forall S S', Contractive S -> Contractive S' -> Sequiv S S' -> Sequiv S (cs S'). Proof. intros. eapply uncs_preserves_Sequiv_l; eauto. eapply cs_preserves_Sequiv; eauto. Qed. Lemma cs_preserves_not_Sequiv : forall S S', Contractive S -> Contractive S' -> ~ Sequiv S S' -> ~ Sequiv (cs S) (cs S'). Proof. introv Hok Hok' H contra. apply H. eapply uncs_preserves_Sequiv; eauto. Qed. Lemma uncs_preserves_not_Sequiv : forall S S', Contractive S -> Contractive S' -> ~ Sequiv (cs S) (cs S') -> ~ Sequiv S S'. Proof. introv Hok Hok' H contra. apply H. eapply cs_preserves_Sequiv; eauto. Qed. Lemma cs_preserves_NSequiv : forall S S', Contractive S -> Contractive S' -> NSequiv S S' -> NSequiv (cs S) (cs S'). Proof. apply (Sty_ind_mu_prefix2 (fun S S' => Contractive S -> Contractive S' -> NSequiv S S' -> NSequiv (cs S) (cs S') )). introv IH Hok Hok' Hneq. inverts Hneq; try cs_simpl; eauto 10 with contractive subst nsequiv. - destruct S; destruct S'; cs_simpl; auto with nsequiv; false. Qed. Lemma uncs_preserves_NSequiv : forall S S', Contractive S -> Contractive S' -> NSequiv (cs S) (cs S') -> NSequiv S S'. Proof. apply (Sty_ind_mu_prefix2 (fun S S' => Contractive S -> Contractive S' -> NSequiv (cs S) (cs S') -> NSequiv S S' )). introv IH Hok Hok' Hneq. destruct S; destruct S'; solve [ cs_simpl; auto | constructor; apply IH; eauto with contractive subst; cs_simpl; auto with nsequiv ]. Qed. Lemma cs_preserves_Contractive : forall S, Contractive S -> Contractive (cs S). Proof. induction S using (well_founded_ind lt_Sty_mu_prefix_wf); introv Hcontr; destruct S; cs_simpl; auto with contractive subst. Qed. Hint Resolve cs_preserves_Contractive : subst. Lemma cs_preserves_Wf : forall S, Wf S -> Wf (cs S). Proof. induction S using (well_founded_ind lt_Sty_mu_prefix_wf); introv Hwf; destruct S; cs_simpl; auto with subst wf. Qed. Hint Resolve cs_preserves_Wf : subst wf. Lemma tl_eq : forall eta S S' c c', S = S' -> tl eta S c = tl eta S' c'. Proof. introv Heq. gen c c'. rewrite Heq. apply tl_contractive_irrelevant. Qed. Lemma cs_preserves_tl : forall S eta c c', Wf S -> tl eta S c = tl eta (cs S) c'. Proof. intros S eta. induction S using (well_founded_ind lt_Sty_mu_prefix_wf); introv Hwf; destruct S; try solve [apply tl_eq; cs_simpl; reflexivity]. - erewrite tl_mu_subst. erewrite H with (y := subst v (mu v S) S). apply tl_eq. cs_simpl. reflexivity. all: auto 10 with subst wf. Unshelve. all: auto with contractive subst. Qed. Hint Resolve cs_preserves_tl : subst.
#!/usr/bin/env python # coding: utf8 """ Unit testing for Separator class. """ __email__ = '[email protected]' __author__ = 'Deezer Research' __license__ = 'MIT License' import json import os from os import makedirs from os.path import join from tempfile import TemporaryDirectory import numpy as np import pandas as pd from spleeter.audio.adapter import AudioAdapter from spleeter.__main__ import spleeter from typer.testing import CliRunner TRAIN_CONFIG = { 'mix_name': 'mix', 'instrument_list': ['vocals', 'other'], 'sample_rate': 44100, 'frame_length': 4096, 'frame_step': 1024, 'T': 128, 'F': 128, 'n_channels': 2, 'chunk_duration': 4, 'n_chunks_per_song': 1, 'separation_exponent': 2, 'mask_extension': 'zeros', 'learning_rate': 1e-4, 'batch_size': 2, 'train_max_steps': 10, 'throttle_secs': 20, 'save_checkpoints_steps': 100, 'save_summary_steps': 5, 'random_seed': 0, 'model': { 'type': 'unet.unet', 'params': { 'conv_activation': 'ELU', 'deconv_activation': 'ELU' } } } def generate_fake_training_dataset(path, instrument_list=['vocals', 'other'], n_channels=2, n_songs = 2, fs = 44100, duration = 6, ): """ generates a fake training dataset in path: - generates audio files - generates a csv file describing the dataset """ aa = AudioAdapter.default() rng = np.random.RandomState(seed=0) dataset_df = pd.DataFrame( columns=['mix_path'] + [ f'{instr}_path' for instr in instrument_list] + ['duration']) for song in range(n_songs): song_path = join(path, 'train', f'song{song}') makedirs(song_path, exist_ok=True) dataset_df.loc[song, f'duration'] = duration for instr in instrument_list+['mix']: filename = join(song_path, f'{instr}.wav') data = rng.rand(duration*fs, n_channels)-0.5 aa.save(filename, data, fs) dataset_df.loc[song, f'{instr}_path'] = join( 'train', f'song{song}', f'{instr}.wav') dataset_df.to_csv(join(path, 'train', 'train.csv'), index=False) def test_train(): with TemporaryDirectory() as path: # generate training dataset for n_channels in [1,2]: TRAIN_CONFIG["n_channels"] = n_channels generate_fake_training_dataset(path, n_channels=n_channels, fs=TRAIN_CONFIG["sample_rate"] ) # set training command arguments runner = CliRunner() model_dir = join(path, f'model_{n_channels}') train_dir = join(path, f'train') cache_dir = join(path, f'cache_{n_channels}') TRAIN_CONFIG['train_csv'] = join(train_dir, 'train.csv') TRAIN_CONFIG['validation_csv'] = join(train_dir, 'train.csv') TRAIN_CONFIG['model_dir'] = model_dir TRAIN_CONFIG['training_cache'] = join(cache_dir, 'training') TRAIN_CONFIG['validation_cache'] = join(cache_dir, 'validation') with open('useless_config.json', 'w') as stream: json.dump(TRAIN_CONFIG, stream) # execute training result = runner.invoke(spleeter, [ 'train', '-p', 'useless_config.json', '-d', path, "--verbose" ]) # assert that model checkpoint was created. assert os.path.exists(join(model_dir, 'model.ckpt-10.index')) assert os.path.exists(join(model_dir, 'checkpoint')) assert os.path.exists(join(model_dir, 'model.ckpt-0.meta')) assert result.exit_code == 0
# -*- coding: utf-8 -*- # import numpy import pytest import colorio @pytest.mark.parametrize('vals', [ numpy.random.rand(3), numpy.random.rand(3, 7), numpy.random.rand(3, 4, 5), ]) def test_conversion(vals): cs = colorio.Rec2020() out = cs.to_xyz100(cs.from_xyz100(vals)) assert numpy.all(abs(vals - out) < 1.0e-14) out = cs.to_gamma(cs.from_gamma(vals)) assert numpy.all(abs(vals - out) < 1.0e-14) return
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) // (C) Copyright 2005-2007 Jonathan Turkanis // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) // See http://www.boost.org/libs/iostreams for documentation. #include <cassert> #include <iterator> // back_inserter #include <string> #include <boost/iostreams/filtering_stream.hpp> namespace io = boost::iostreams; int main() { using namespace std; string result; io::filtering_ostream out(std::back_inserter(result)); out << "Hello World!"; out.flush(); assert(result == "Hello World!"); }
[STATEMENT] lemma reachable_SKIP [simp]: "reachable SKIP = UNIV" [PROOF STATE] proof (prove) goal (1 subgoal): 1. reachable \<bottom> = UNIV [PROOF STEP] by (force elim: reachable.induct intro: reachable.intros)
/- Copyright (c) 2022 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Heather Macbeth ! This file was ported from Lean 3 source module ring_theory.witt_vector.mul_coeff ! leanprover-community/mathlib commit 43a289b563d533cfb00f58b812d222371f6f6fac ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.RingTheory.WittVector.Truncated import Mathbin.Data.MvPolynomial.Supported /-! # Leading terms of Witt vector multiplication The goal of this file is to study the leading terms of the formula for the `n+1`st coefficient of a product of Witt vectors `x` and `y` over a ring of characteristic `p`. We aim to isolate the `n+1`st coefficients of `x` and `y`, and express the rest of the product in terms of a function of the lower coefficients. For most of this file we work with terms of type `mv_polynomial (fin 2 × ℕ) ℤ`. We will eventually evaluate them in `k`, but first we must take care of a calculation that needs to happen in characteristic 0. ## Main declarations * `witt_vector.nth_mul_coeff`: expresses the coefficient of a product of Witt vectors in terms of the previous coefficients of the multiplicands. -/ noncomputable section namespace WittVector variable (p : ℕ) [hp : Fact p.Prime] variable {k : Type _} [CommRing k] -- mathport name: expr𝕎 local notation "𝕎" => WittVector p open Finset MvPolynomial open BigOperators /-- ``` (∑ i in range n, (y.coeff i)^(p^(n-i)) * p^i.val) * (∑ i in range n, (y.coeff i)^(p^(n-i)) * p^i.val) ``` -/ def wittPolyProd (n : ℕ) : MvPolynomial (Fin 2 × ℕ) ℤ := rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ n) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ n) #align witt_vector.witt_poly_prod WittVector.wittPolyProd include hp /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/ theorem wittPolyProd_vars (n : ℕ) : (wittPolyProd p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [witt_poly_prod] apply subset.trans (vars_mul _ _) apply union_subset <;> · apply subset.trans (vars_rename _ _) simp [wittPolynomial_vars, image_subset_iff] #align witt_vector.witt_poly_prod_vars WittVector.wittPolyProd_vars /-- The "remainder term" of `witt_vector.witt_poly_prod`. See `mul_poly_of_interest_aux2`. -/ def wittPolyProdRemainder (n : ℕ) : MvPolynomial (Fin 2 × ℕ) ℤ := ∑ i in range n, p ^ i * wittMul p i ^ p ^ (n - i) #align witt_vector.witt_poly_prod_remainder WittVector.wittPolyProdRemainder /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/ theorem wittPolyProdRemainder_vars (n : ℕ) : (wittPolyProdRemainder p n).vars ⊆ univ ×ˢ range n := by rw [witt_poly_prod_remainder] apply subset.trans (vars_sum_subset _ _) rw [bUnion_subset] intro x hx apply subset.trans (vars_mul _ _) apply union_subset · apply subset.trans (vars_pow _ _) have : (p : MvPolynomial (Fin 2 × ℕ) ℤ) = C (p : ℤ) := by simp only [Int.cast_ofNat, eq_intCast] rw [this, vars_C] apply empty_subset · apply subset.trans (vars_pow _ _) apply subset.trans (witt_mul_vars _ _) apply product_subset_product (subset.refl _) simp only [mem_range, range_subset] at hx⊢ exact hx #align witt_vector.witt_poly_prod_remainder_vars WittVector.wittPolyProdRemainder_vars omit hp /-- `remainder p n` represents the remainder term from `mul_poly_of_interest_aux3`. `witt_poly_prod p (n+1)` will have variables up to `n+1`, but `remainder` will only have variables up to `n`. -/ def remainder (n : ℕ) : MvPolynomial (Fin 2 × ℕ) ℤ := (∑ x : ℕ in range (n + 1), (rename (Prod.mk 0)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) (↑p ^ x))) * ∑ x : ℕ in range (n + 1), (rename (Prod.mk 1)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) (↑p ^ x)) #align witt_vector.remainder WittVector.remainder include hp /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/ theorem remainder_vars (n : ℕ) : (remainder p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [remainder] apply subset.trans (vars_mul _ _) apply union_subset <;> · apply subset.trans (vars_sum_subset _ _) rw [bUnion_subset] intro x hx rw [rename_monomial, vars_monomial, Finsupp.mapDomain_single] · apply subset.trans Finsupp.support_single_subset simp [hx] · apply pow_ne_zero exact_mod_cast hp.out.ne_zero #align witt_vector.remainder_vars WittVector.remainder_vars /-- This is the polynomial whose degree we want to get a handle on. -/ def polyOfInterest (n : ℕ) : MvPolynomial (Fin 2 × ℕ) ℤ := wittMul p (n + 1) + p ^ (n + 1) * X (0, n + 1) * X (1, n + 1) - X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) - X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) #align witt_vector.poly_of_interest WittVector.polyOfInterest theorem mul_poly_of_interest_aux1 (n : ℕ) : (∑ i in range (n + 1), p ^ i * wittMul p i ^ p ^ (n - i) : MvPolynomial (Fin 2 × ℕ) ℤ) = wittPolyProd p n := by simp only [witt_poly_prod] convert wittStructureInt_prop p (X (0 : Fin 2) * X 1) n using 1 · simp only [wittPolynomial, witt_mul] rw [AlgHom.map_sum] congr 1 with i congr 1 have hsupp : (Finsupp.single i (p ^ (n - i))).support = {i} := by rw [Finsupp.support_eq_singleton] simp only [and_true_iff, Finsupp.single_eq_same, eq_self_iff_true, Ne.def] exact pow_ne_zero _ hp.out.ne_zero simp only [bind₁_monomial, hsupp, Int.cast_ofNat, prod_singleton, eq_intCast, Finsupp.single_eq_same, C_pow, mul_eq_mul_left_iff, true_or_iff, eq_self_iff_true] · simp only [map_mul, bind₁_X_right] #align witt_vector.mul_poly_of_interest_aux1 WittVector.mul_poly_of_interest_aux1 theorem mul_poly_of_interest_aux2 (n : ℕ) : (p ^ n * wittMul p n : MvPolynomial (Fin 2 × ℕ) ℤ) + wittPolyProdRemainder p n = wittPolyProd p n := by convert mul_poly_of_interest_aux1 p n rw [sum_range_succ, add_comm, Nat.sub_self, pow_zero, pow_one] rfl #align witt_vector.mul_poly_of_interest_aux2 WittVector.mul_poly_of_interest_aux2 omit hp theorem mul_poly_of_interest_aux3 (n : ℕ) : wittPolyProd p (n + 1) = -(p ^ (n + 1) * X (0, n + 1)) * (p ^ (n + 1) * X (1, n + 1)) + p ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + p ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + remainder p n := by -- a useful auxiliary fact have mvpz : (p ^ (n + 1) : MvPolynomial (Fin 2 × ℕ) ℤ) = MvPolynomial.C (↑p ^ (n + 1)) := by simp only [Int.cast_ofNat, eq_intCast, C_pow, eq_self_iff_true] -- unfold definitions and peel off the last entries of the sums. rw [witt_poly_prod, wittPolynomial, AlgHom.map_sum, AlgHom.map_sum, sum_range_succ] -- these are sums up to `n+2`, so be careful to only unfold to `n+1`. conv_lhs => congr skip rw [sum_range_succ] simp only [add_mul, mul_add, tsub_self, pow_zero, AlgHom.map_sum] -- rearrange so that the first summand on rhs and lhs is `remainder`, and peel off conv_rhs => rw [add_comm] simp only [add_assoc] apply congr_arg (Add.add _) conv_rhs => rw [sum_range_succ] -- the rest is equal with proper unfolding and `ring` simp only [rename_monomial, ← C_mul_X_pow_eq_monomial, map_mul, rename_C, pow_one, rename_X] simp only [mvpz, Int.cast_ofNat, map_pow, eq_intCast, rename_X, pow_one, tsub_self, pow_zero] ring1 #align witt_vector.mul_poly_of_interest_aux3 WittVector.mul_poly_of_interest_aux3 include hp theorem mul_poly_of_interest_aux4 (n : ℕ) : (p ^ (n + 1) * wittMul p (n + 1) : MvPolynomial (Fin 2 × ℕ) ℤ) = -(p ^ (n + 1) * X (0, n + 1)) * (p ^ (n + 1) * X (1, n + 1)) + p ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + p ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + (remainder p n - wittPolyProdRemainder p (n + 1)) := by rw [← add_sub_assoc, eq_sub_iff_add_eq, mul_poly_of_interest_aux2] exact mul_poly_of_interest_aux3 _ _ #align witt_vector.mul_poly_of_interest_aux4 WittVector.mul_poly_of_interest_aux4 theorem mul_polyOfInterest_aux5 (n : ℕ) : (p ^ (n + 1) : MvPolynomial (Fin 2 × ℕ) ℤ) * polyOfInterest p n = remainder p n - wittPolyProdRemainder p (n + 1) := by simp only [poly_of_interest, mul_sub, mul_add, sub_eq_iff_eq_add'] rw [mul_poly_of_interest_aux4 p n] ring #align witt_vector.mul_poly_of_interest_aux5 WittVector.mul_polyOfInterest_aux5 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/ theorem mul_polyOfInterest_vars (n : ℕ) : ((p ^ (n + 1) : MvPolynomial (Fin 2 × ℕ) ℤ) * polyOfInterest p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [mul_poly_of_interest_aux5] apply subset.trans (vars_sub_subset _ _) apply union_subset · apply remainder_vars · apply witt_poly_prod_remainder_vars #align witt_vector.mul_poly_of_interest_vars WittVector.mul_polyOfInterest_vars theorem polyOfInterest_vars_eq (n : ℕ) : (polyOfInterest p n).vars = ((p ^ (n + 1) : MvPolynomial (Fin 2 × ℕ) ℤ) * (wittMul p (n + 1) + p ^ (n + 1) * X (0, n + 1) * X (1, n + 1) - X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) - X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)))).vars := by have : (p ^ (n + 1) : MvPolynomial (Fin 2 × ℕ) ℤ) = C (p ^ (n + 1) : ℤ) := by simp only [Int.cast_ofNat, eq_intCast, C_pow, eq_self_iff_true] rw [poly_of_interest, this, vars_C_mul] apply pow_ne_zero exact_mod_cast hp.out.ne_zero #align witt_vector.poly_of_interest_vars_eq WittVector.polyOfInterest_vars_eq /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/ theorem polyOfInterest_vars (n : ℕ) : (polyOfInterest p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [poly_of_interest_vars_eq] <;> apply mul_poly_of_interest_vars #align witt_vector.poly_of_interest_vars WittVector.polyOfInterest_vars theorem peval_polyOfInterest (n : ℕ) (x y : 𝕎 k) : peval (polyOfInterest p n) ![fun i => x.coeff i, fun i => y.coeff i] = ((x * y).coeff (n + 1) + p ^ (n + 1) * x.coeff (n + 1) * y.coeff (n + 1) - y.coeff (n + 1) * ∑ i in range (n + 1 + 1), p ^ i * x.coeff i ^ p ^ (n + 1 - i)) - x.coeff (n + 1) * ∑ i in range (n + 1 + 1), p ^ i * y.coeff i ^ p ^ (n + 1 - i) := by simp only [poly_of_interest, peval, map_natCast, Matrix.head_cons, map_pow, Function.uncurry_apply_pair, aeval_X, Matrix.cons_val_one, map_mul, Matrix.cons_val_zero, map_sub] rw [sub_sub, add_comm (_ * _), ← sub_sub] have mvpz : (p : MvPolynomial ℕ ℤ) = MvPolynomial.C ↑p := by rw [eq_intCast, Int.cast_ofNat] have : ∀ (f : ℤ →+* k) (g : ℕ → k), eval₂ f g p = f p := by intros rw [mvpz, MvPolynomial.eval₂_C] simp [wittPolynomial_eq_sum_c_mul_x_pow, aeval, eval₂_rename, this, mul_coeff, peval, map_natCast, map_add, map_pow, map_mul] #align witt_vector.peval_poly_of_interest WittVector.peval_polyOfInterest variable [CharP k p] /-- The characteristic `p` version of `peval_poly_of_interest` -/ theorem peval_poly_of_interest' (n : ℕ) (x y : 𝕎 k) : peval (polyOfInterest p n) ![fun i => x.coeff i, fun i => y.coeff i] = (x * y).coeff (n + 1) - y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) - x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) := by rw [peval_poly_of_interest] have : (p : k) = 0 := CharP.cast_eq_zero k p simp only [this, add_zero, MulZeroClass.zero_mul, Nat.succ_ne_zero, Ne.def, not_false_iff, zero_pow'] have sum_zero_pow_mul_pow_p : ∀ y : 𝕎 k, (∑ x : ℕ in range (n + 1 + 1), 0 ^ x * y.coeff x ^ p ^ (n + 1 - x)) = y.coeff 0 ^ p ^ (n + 1) := by intro y rw [Finset.sum_eq_single_of_mem 0] · simp · simp · intro j _ hj simp [zero_pow (zero_lt_iff.mpr hj)] congr <;> apply sum_zero_pow_mul_pow_p #align witt_vector.peval_poly_of_interest' WittVector.peval_poly_of_interest' variable (k) theorem nth_mul_coeff' (n : ℕ) : ∃ f : TruncatedWittVector p (n + 1) k → TruncatedWittVector p (n + 1) k → k, ∀ x y : 𝕎 k, f (truncateFun (n + 1) x) (truncateFun (n + 1) y) = (x * y).coeff (n + 1) - y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) - x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) := by simp only [← peval_poly_of_interest'] obtain ⟨f₀, hf₀⟩ := exists_restrict_to_vars k (poly_of_interest_vars p n) let f : TruncatedWittVector p (n + 1) k → TruncatedWittVector p (n + 1) k → k := by intro x y apply f₀ rintro ⟨a, ha⟩ apply Function.uncurry ![x, y] simp only [true_and_iff, Multiset.mem_cons, range_val, product_val, Multiset.mem_range, Multiset.mem_product, Multiset.range_succ, mem_univ_val] at ha refine' ⟨a.fst, ⟨a.snd, _⟩⟩ cases' ha with ha ha <;> linarith only [ha] use f intro x y dsimp [peval] rw [← hf₀] simp only [f, Function.uncurry_apply_pair] congr ext a cases' a with a ha cases' a with i m simp only [true_and_iff, Multiset.mem_cons, range_val, product_val, Multiset.mem_range, Multiset.mem_product, Multiset.range_succ, mem_univ_val] at ha have ha' : m < n + 1 := by cases' ha with ha ha <;> linarith only [ha] fin_cases i <;>-- surely this case split is not necessary · simpa only using x.coeff_truncate_fun ⟨m, ha'⟩ #align witt_vector.nth_mul_coeff' WittVector.nth_mul_coeff' theorem nth_mul_coeff (n : ℕ) : ∃ f : TruncatedWittVector p (n + 1) k → TruncatedWittVector p (n + 1) k → k, ∀ x y : 𝕎 k, (x * y).coeff (n + 1) = x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) + y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) + f (truncateFun (n + 1) x) (truncateFun (n + 1) y) := by obtain ⟨f, hf⟩ := nth_mul_coeff' p k n use f intro x y rw [hf x y] ring #align witt_vector.nth_mul_coeff WittVector.nth_mul_coeff variable {k} /-- Produces the "remainder function" of the `n+1`st coefficient, which does not depend on the `n+1`st coefficients of the inputs. -/ def nthRemainder (n : ℕ) : (Fin (n + 1) → k) → (Fin (n + 1) → k) → k := Classical.choose (nth_mul_coeff p k n) #align witt_vector.nth_remainder WittVector.nthRemainder theorem nthRemainder_spec (n : ℕ) (x y : 𝕎 k) : (x * y).coeff (n + 1) = x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) + y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) + nthRemainder p n (truncateFun (n + 1) x) (truncateFun (n + 1) y) := Classical.choose_spec (nth_mul_coeff p k n) _ _ #align witt_vector.nth_remainder_spec WittVector.nthRemainder_spec end WittVector
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel ! This file was ported from Lean 3 source module measure_theory.covering.besicovitch_vector_space ! leanprover-community/mathlib commit 92ca63f0fb391a9ca5f22d2409a6080e786d99f7 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.MeasureTheory.Measure.HaarLebesgue import Mathbin.MeasureTheory.Covering.Besicovitch /-! # Satellite configurations for Besicovitch covering lemma in vector spaces The Besicovitch covering theorem ensures that, in a nice metric space, there exists a number `N` such that, from any family of balls with bounded radii, one can extract `N` families, each made of disjoint balls, covering together all the centers of the initial family. A key tool in the proof of this theorem is the notion of a satellite configuration, i.e., a family of `N + 1` balls, where the first `N` balls all intersect the last one, but none of them contains the center of another one and their radii are controlled. This is a technical notion, but it shows up naturally in the proof of the Besicovitch theorem (which goes through a greedy algorithm): to ensure that in the end one needs at most `N` families of balls, the crucial property of the underlying metric space is that there should be no satellite configuration of `N + 1` points. This file is devoted to the study of this property in vector spaces: we prove the main result of [Füredi and Loeb, On the best constant for the Besicovitch covering theorem][furedi-loeb1994], which shows that the optimal such `N` in a vector space coincides with the maximal number of points one can put inside the unit ball of radius `2` under the condition that their distances are bounded below by `1`. In particular, this number is bounded by `5 ^ dim` by a straightforward measure argument. ## Main definitions and results * `multiplicity E` is the maximal number of points one can put inside the unit ball of radius `2` in the vector space `E`, under the condition that their distances are bounded below by `1`. * `multiplicity_le E` shows that `multiplicity E ≤ 5 ^ (dim E)`. * `good_τ E` is a constant `> 1`, but close enough to `1` that satellite configurations with this parameter `τ` are not worst than for `τ = 1`. * `is_empty_satellite_config_multiplicity` is the main theorem, saying that there are no satellite configurations of `(multiplicity E) + 1` points, for the parameter `good_τ E`. -/ universe u open Metric Set FiniteDimensional MeasureTheory Filter Fin open ENNReal Topology noncomputable section namespace Besicovitch variable {E : Type _} [NormedAddCommGroup E] namespace SatelliteConfig variable [NormedSpace ℝ E] {N : ℕ} {τ : ℝ} (a : SatelliteConfig E N τ) /-- Rescaling a satellite configuration in a vector space, to put the basepoint at `0` and the base radius at `1`. -/ def centerAndRescale : SatelliteConfig E N τ where c i := (a.R (last N))⁻¹ • (a.c i - a.c (last N)) R i := (a.R (last N))⁻¹ * a.R i rpos i := mul_pos (inv_pos.2 (a.rpos _)) (a.rpos _) h i j hij := by rcases a.h i j hij with (H | H) · left constructor · rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_of_nonneg (inv_nonneg.2 (a.rpos _).le)] refine' mul_le_mul_of_nonneg_left _ (inv_nonneg.2 (a.rpos _).le) rw [dist_eq_norm] at H convert H.1 using 2 abel · rw [← mul_assoc, mul_comm τ, mul_assoc] refine' mul_le_mul_of_nonneg_left _ (inv_nonneg.2 (a.rpos _).le) exact H.2 · right constructor · rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_of_nonneg (inv_nonneg.2 (a.rpos _).le)] refine' mul_le_mul_of_nonneg_left _ (inv_nonneg.2 (a.rpos _).le) rw [dist_eq_norm] at H convert H.1 using 2 abel · rw [← mul_assoc, mul_comm τ, mul_assoc] refine' mul_le_mul_of_nonneg_left _ (inv_nonneg.2 (a.rpos _).le) exact H.2 hlast i hi := by have H := a.hlast i hi constructor · rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_of_nonneg (inv_nonneg.2 (a.rpos _).le)] refine' mul_le_mul_of_nonneg_left _ (inv_nonneg.2 (a.rpos _).le) rw [dist_eq_norm] at H convert H.1 using 2 abel · rw [← mul_assoc, mul_comm τ, mul_assoc] refine' mul_le_mul_of_nonneg_left _ (inv_nonneg.2 (a.rpos _).le) exact H.2 inter i hi := by have H := a.inter i hi rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_of_nonneg (inv_nonneg.2 (a.rpos _).le), ← mul_add] refine' mul_le_mul_of_nonneg_left _ (inv_nonneg.2 (a.rpos _).le) rw [dist_eq_norm] at H convert H using 2 abel #align besicovitch.satellite_config.center_and_rescale Besicovitch.SatelliteConfig.centerAndRescale theorem centerAndRescale_center : a.centerAndRescale.c (last N) = 0 := by simp [satellite_config.center_and_rescale] #align besicovitch.satellite_config.center_and_rescale_center Besicovitch.SatelliteConfig.centerAndRescale_center theorem centerAndRescale_radius {N : ℕ} {τ : ℝ} (a : SatelliteConfig E N τ) : a.centerAndRescale.R (last N) = 1 := by simp [satellite_config.center_and_rescale, inv_mul_cancel (a.rpos _).ne'] #align besicovitch.satellite_config.center_and_rescale_radius Besicovitch.SatelliteConfig.centerAndRescale_radius end SatelliteConfig /-! ### Disjoint balls of radius close to `1` in the radius `2` ball. -/ /-- The maximum cardinality of a `1`-separated set in the ball of radius `2`. This is also the optimal number of families in the Besicovitch covering theorem. -/ def multiplicity (E : Type _) [NormedAddCommGroup E] := supₛ { N | ∃ s : Finset E, s.card = N ∧ (∀ c ∈ s, ‖c‖ ≤ 2) ∧ ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 ≤ ‖c - d‖ } #align besicovitch.multiplicity Besicovitch.multiplicity section variable [NormedSpace ℝ E] [FiniteDimensional ℝ E] /-- Any `1`-separated set in the ball of radius `2` has cardinality at most `5 ^ dim`. This is useful to show that the supremum in the definition of `besicovitch.multiplicity E` is well behaved. -/ theorem card_le_of_separated (s : Finset E) (hs : ∀ c ∈ s, ‖c‖ ≤ 2) (h : ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 ≤ ‖c - d‖) : s.card ≤ 5 ^ finrank ℝ E := by /- We consider balls of radius `1/2` around the points in `s`. They are disjoint, and all contained in the ball of radius `5/2`. A volume argument gives `s.card * (1/2)^dim ≤ (5/2)^dim`, i.e., `s.card ≤ 5^dim`. -/ borelize E let μ : Measure E := measure.add_haar let δ : ℝ := (1 : ℝ) / 2 let ρ : ℝ := (5 : ℝ) / 2 have ρpos : 0 < ρ := by norm_num [ρ] set A := ⋃ c ∈ s, ball (c : E) δ with hA have D : Set.Pairwise (s : Set E) (Disjoint on fun c => ball (c : E) δ) := by rintro c hc d hd hcd apply ball_disjoint_ball rw [dist_eq_norm] convert h c hc d hd hcd norm_num have A_subset : A ⊆ ball (0 : E) ρ := by refine' Union₂_subset fun x hx => _ apply ball_subset_ball' calc δ + dist x 0 ≤ δ + 2 := by rw [dist_zero_right] exact add_le_add le_rfl (hs x hx) _ = 5 / 2 := by norm_num [δ] have I : (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ finrank ℝ E) * μ (ball 0 1) ≤ ENNReal.ofReal (ρ ^ finrank ℝ E) * μ (ball 0 1) := calc (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ finrank ℝ E) * μ (ball 0 1) = μ A := by rw [hA, measure_bUnion_finset D fun c hc => measurableSet_ball] have I : 0 < δ := by norm_num [δ] simp only [μ.add_haar_ball_of_pos _ I, one_div, one_pow, Finset.sum_const, nsmul_eq_mul, div_pow, mul_assoc] _ ≤ μ (ball (0 : E) ρ) := (measure_mono A_subset) _ = ENNReal.ofReal (ρ ^ finrank ℝ E) * μ (ball 0 1) := by simp only [μ.add_haar_ball_of_pos _ ρpos] have J : (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ finrank ℝ E) ≤ ENNReal.ofReal (ρ ^ finrank ℝ E) := (ENNReal.mul_le_mul_right (measure_ball_pos _ _ zero_lt_one).ne' measure_ball_lt_top.ne).1 I have K : (s.card : ℝ) ≤ (5 : ℝ) ^ finrank ℝ E := by simpa [ENNReal.toReal_mul, div_eq_mul_inv] using ENNReal.toReal_le_of_le_ofReal (pow_nonneg ρpos.le _) J exact_mod_cast K #align besicovitch.card_le_of_separated Besicovitch.card_le_of_separated theorem multiplicity_le : multiplicity E ≤ 5 ^ finrank ℝ E := by apply csupₛ_le · refine' ⟨0, ⟨∅, by simp⟩⟩ · rintro _ ⟨s, ⟨rfl, h⟩⟩ exact Besicovitch.card_le_of_separated s h.1 h.2 #align besicovitch.multiplicity_le Besicovitch.multiplicity_le theorem card_le_multiplicity {s : Finset E} (hs : ∀ c ∈ s, ‖c‖ ≤ 2) (h's : ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 ≤ ‖c - d‖) : s.card ≤ multiplicity E := by apply le_csupₛ · refine' ⟨5 ^ finrank ℝ E, _⟩ rintro _ ⟨s, ⟨rfl, h⟩⟩ exact Besicovitch.card_le_of_separated s h.1 h.2 · simp only [mem_set_of_eq, Ne.def] exact ⟨s, rfl, hs, h's⟩ #align besicovitch.card_le_multiplicity Besicovitch.card_le_multiplicity variable (E) /-- If `δ` is small enough, a `(1-δ)`-separated set in the ball of radius `2` also has cardinality at most `multiplicity E`. -/ theorem exists_good_δ : ∃ δ : ℝ, 0 < δ ∧ δ < 1 ∧ ∀ s : Finset E, (∀ c ∈ s, ‖c‖ ≤ 2) → (∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 - δ ≤ ‖c - d‖) → s.card ≤ multiplicity E := by classical /- This follows from a compactness argument: otherwise, one could extract a converging subsequence, to obtain a `1`-separated set in the ball of radius `2` with cardinality `N = multiplicity E + 1`. To formalize this, we work with functions `fin N → E`. -/ by_contra' h set N := multiplicity E + 1 with hN have : ∀ δ : ℝ, 0 < δ → ∃ f : Fin N → E, (∀ i : Fin N, ‖f i‖ ≤ 2) ∧ ∀ i j, i ≠ j → 1 - δ ≤ ‖f i - f j‖ := by intro δ hδ rcases lt_or_le δ 1 with (hδ' | hδ') · rcases h δ hδ hδ' with ⟨s, hs, h's, s_card⟩ obtain ⟨f, f_inj, hfs⟩ : ∃ f : Fin N → E, Function.Injective f ∧ range f ⊆ ↑s := by have : Fintype.card (Fin N) ≤ s.card := by simp only [Fintype.card_fin] exact s_card rcases Function.Embedding.exists_of_card_le_finset this with ⟨f, hf⟩ exact ⟨f, f.injective, hf⟩ simp only [range_subset_iff, Finset.mem_coe] at hfs refine' ⟨f, fun i => hs _ (hfs i), fun i j hij => h's _ (hfs i) _ (hfs j) (f_inj.ne hij)⟩ · exact ⟨fun i => 0, fun i => by simp, fun i j hij => by simpa only [norm_zero, sub_nonpos, sub_self] ⟩ -- For `δ > 0`, `F δ` is a function from `fin N` to the ball of radius `2` for which two points -- in the image are separated by `1 - δ`. choose! F hF using this -- Choose a converging subsequence when `δ → 0`. have : ∃ f : Fin N → E, (∀ i : Fin N, ‖f i‖ ≤ 2) ∧ ∀ i j, i ≠ j → 1 ≤ ‖f i - f j‖ := by obtain ⟨u, u_mono, zero_lt_u, hu⟩ : ∃ u : ℕ → ℝ, (∀ m n : ℕ, m < n → u n < u m) ∧ (∀ n : ℕ, 0 < u n) ∧ Filter.Tendsto u Filter.atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ) have A : ∀ n, F (u n) ∈ closed_ball (0 : Fin N → E) 2 := by intro n simp only [pi_norm_le_iff_of_nonneg zero_le_two, mem_closed_ball, dist_zero_right, (hF (u n) (zero_lt_u n)).left, forall_const] obtain ⟨f, fmem, φ, φ_mono, hf⟩ : ∃ f ∈ closed_ball (0 : Fin N → E) 2, ∃ φ : ℕ → ℕ, StrictMono φ ∧ tendsto ((F ∘ u) ∘ φ) at_top (𝓝 f) := IsCompact.tendsto_subseq (is_compact_closed_ball _ _) A refine' ⟨f, fun i => _, fun i j hij => _⟩ · simp only [pi_norm_le_iff_of_nonneg zero_le_two, mem_closed_ball, dist_zero_right] at fmem exact fmem i · have A : tendsto (fun n => ‖F (u (φ n)) i - F (u (φ n)) j‖) at_top (𝓝 ‖f i - f j‖) := ((hf.apply i).sub (hf.apply j)).norm have B : tendsto (fun n => 1 - u (φ n)) at_top (𝓝 (1 - 0)) := tendsto_const_nhds.sub (hu.comp φ_mono.tendsto_at_top) rw [sub_zero] at B exact le_of_tendsto_of_tendsto' B A fun n => (hF (u (φ n)) (zero_lt_u _)).2 i j hij rcases this with ⟨f, hf, h'f⟩ -- the range of `f` contradicts the definition of `multiplicity E`. have finj : Function.Injective f := by intro i j hij by_contra have : 1 ≤ ‖f i - f j‖ := h'f i j h simp only [hij, norm_zero, sub_self] at this exact lt_irrefl _ (this.trans_lt zero_lt_one) let s := Finset.image f Finset.univ have s_card : s.card = N := by rw [Finset.card_image_of_injective _ finj] exact Finset.card_fin N have hs : ∀ c ∈ s, ‖c‖ ≤ 2 := by simp only [hf, forall_apply_eq_imp_iff', forall_const, forall_exists_index, Finset.mem_univ, Finset.mem_image] have h's : ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 ≤ ‖c - d‖ := by simp only [s, forall_apply_eq_imp_iff', forall_exists_index, Finset.mem_univ, Finset.mem_image, Ne.def, exists_true_left, forall_apply_eq_imp_iff', forall_true_left] intro i j hij have : i ≠ j := fun h => by rw [h] at hij exact hij rfl exact h'f i j this have : s.card ≤ multiplicity E := card_le_multiplicity hs h's rw [s_card, hN] at this exact lt_irrefl _ ((Nat.lt_succ_self (multiplicity E)).trans_le this) #align besicovitch.exists_good_δ Besicovitch.exists_good_δ /-- A small positive number such that any `1 - δ`-separated set in the ball of radius `2` has cardinality at most `besicovitch.multiplicity E`. -/ def goodδ : ℝ := (exists_good_δ E).some #align besicovitch.good_δ Besicovitch.goodδ theorem goodδ_lt_one : goodδ E < 1 := (exists_good_δ E).choose_spec.2.1 #align besicovitch.good_δ_lt_one Besicovitch.goodδ_lt_one /-- A number `τ > 1`, but chosen close enough to `1` so that the construction in the Besicovitch covering theorem using this parameter `τ` will give the smallest possible number of covering families. -/ def goodτ : ℝ := 1 + goodδ E / 4 #align besicovitch.good_τ Besicovitch.goodτ theorem one_lt_goodτ : 1 < goodτ E := by dsimp [good_τ, good_δ] linarith [(exists_good_δ E).choose_spec.1] #align besicovitch.one_lt_good_τ Besicovitch.one_lt_goodτ variable {E} theorem card_le_multiplicity_of_δ {s : Finset E} (hs : ∀ c ∈ s, ‖c‖ ≤ 2) (h's : ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 - goodδ E ≤ ‖c - d‖) : s.card ≤ multiplicity E := (Classical.choose_spec (exists_good_δ E)).2.2 s hs h's #align besicovitch.card_le_multiplicity_of_δ Besicovitch.card_le_multiplicity_of_δ theorem le_multiplicity_of_δ_of_fin {n : ℕ} (f : Fin n → E) (h : ∀ i, ‖f i‖ ≤ 2) (h' : ∀ i j, i ≠ j → 1 - goodδ E ≤ ‖f i - f j‖) : n ≤ multiplicity E := by classical have finj : Function.Injective f := by intro i j hij by_contra have : 1 - good_δ E ≤ ‖f i - f j‖ := h' i j h simp only [hij, norm_zero, sub_self] at this linarith [good_δ_lt_one E] let s := Finset.image f Finset.univ have s_card : s.card = n := by rw [Finset.card_image_of_injective _ finj] exact Finset.card_fin n have hs : ∀ c ∈ s, ‖c‖ ≤ 2 := by simp only [h, forall_apply_eq_imp_iff', forall_const, forall_exists_index, Finset.mem_univ, Finset.mem_image, imp_true_iff] have h's : ∀ c ∈ s, ∀ d ∈ s, c ≠ d → 1 - good_δ E ≤ ‖c - d‖ := by simp only [s, forall_apply_eq_imp_iff', forall_exists_index, Finset.mem_univ, Finset.mem_image, Ne.def, exists_true_left, forall_apply_eq_imp_iff', forall_true_left] intro i j hij have : i ≠ j := fun h => by rw [h] at hij exact hij rfl exact h' i j this have : s.card ≤ multiplicity E := card_le_multiplicity_of_δ hs h's rwa [s_card] at this #align besicovitch.le_multiplicity_of_δ_of_fin Besicovitch.le_multiplicity_of_δ_of_fin end namespace SatelliteConfig /-! ### Relating satellite configurations to separated points in the ball of radius `2`. We prove that the number of points in a satellite configuration is bounded by the maximal number of `1`-separated points in the ball of radius `2`. For this, start from a satellite congifuration `c`. Without loss of generality, one can assume that the last ball is centered at `0` and of radius `1`. Define `c' i = c i` if `‖c i‖ ≤ 2`, and `c' i = (2/‖c i‖) • c i` if `‖c i‖ > 2`. It turns out that these points are `1 - δ`-separated, where `δ` is arbitrarily small if `τ` is close enough to `1`. The number of such configurations is bounded by `multiplicity E` if `δ` is suitably small. To check that the points `c' i` are `1 - δ`-separated, one treats separately the cases where both `‖c i‖` and `‖c j‖` are `≤ 2`, where one of them is `≤ 2` and the other one is `> 2`, and where both of them are `> 2`. -/ theorem exists_normalized_aux1 {N : ℕ} {τ : ℝ} (a : SatelliteConfig E N τ) (lastr : a.R (last N) = 1) (hτ : 1 ≤ τ) (δ : ℝ) (hδ1 : τ ≤ 1 + δ / 4) (hδ2 : δ ≤ 1) (i j : Fin N.succ) (inej : i ≠ j) : 1 - δ ≤ ‖a.c i - a.c j‖ := by have ah : ∀ i j, i ≠ j → a.r i ≤ ‖a.c i - a.c j‖ ∧ a.r j ≤ τ * a.r i ∨ a.r j ≤ ‖a.c j - a.c i‖ ∧ a.r i ≤ τ * a.r j := by simpa only [dist_eq_norm] using a.h have δnonneg : 0 ≤ δ := by linarith only [hτ, hδ1] have D : 0 ≤ 1 - δ / 4 := by linarith only [hδ2] have τpos : 0 < τ := _root_.zero_lt_one.trans_le hτ have I : (1 - δ / 4) * τ ≤ 1 := calc (1 - δ / 4) * τ ≤ (1 - δ / 4) * (1 + δ / 4) := mul_le_mul_of_nonneg_left hδ1 D _ = 1 - δ ^ 2 / 16 := by ring _ ≤ 1 := by linarith only [sq_nonneg δ] have J : 1 - δ ≤ 1 - δ / 4 := by linarith only [δnonneg] have K : 1 - δ / 4 ≤ τ⁻¹ := by rw [inv_eq_one_div, le_div_iff τpos] exact I suffices L : τ⁻¹ ≤ ‖a.c i - a.c j‖ · linarith only [J, K, L] have hτ' : ∀ k, τ⁻¹ ≤ a.r k := by intro k rw [inv_eq_one_div, div_le_iff τpos, ← lastr, mul_comm] exact a.hlast' k hτ rcases ah i j inej with (H | H) · apply le_trans _ H.1 exact hτ' i · rw [norm_sub_rev] apply le_trans _ H.1 exact hτ' j #align besicovitch.satellite_config.exists_normalized_aux1 Besicovitch.SatelliteConfig.exists_normalized_aux1 variable [NormedSpace ℝ E] theorem exists_normalized_aux2 {N : ℕ} {τ : ℝ} (a : SatelliteConfig E N τ) (lastc : a.c (last N) = 0) (lastr : a.R (last N) = 1) (hτ : 1 ≤ τ) (δ : ℝ) (hδ1 : τ ≤ 1 + δ / 4) (hδ2 : δ ≤ 1) (i j : Fin N.succ) (inej : i ≠ j) (hi : ‖a.c i‖ ≤ 2) (hj : 2 < ‖a.c j‖) : 1 - δ ≤ ‖a.c i - (2 / ‖a.c j‖) • a.c j‖ := by have ah : ∀ i j, i ≠ j → a.r i ≤ ‖a.c i - a.c j‖ ∧ a.r j ≤ τ * a.r i ∨ a.r j ≤ ‖a.c j - a.c i‖ ∧ a.r i ≤ τ * a.r j := by simpa only [dist_eq_norm] using a.h have δnonneg : 0 ≤ δ := by linarith only [hτ, hδ1] have D : 0 ≤ 1 - δ / 4 := by linarith only [hδ2] have τpos : 0 < τ := _root_.zero_lt_one.trans_le hτ have hcrj : ‖a.c j‖ ≤ a.r j + 1 := by simpa only [lastc, lastr, dist_zero_right] using a.inter' j have I : a.r i ≤ 2 := by rcases lt_or_le i (last N) with (H | H) · apply (a.hlast i H).1.trans simpa only [dist_eq_norm, lastc, sub_zero] using hi · have : i = last N := top_le_iff.1 H rw [this, lastr] exact one_le_two have J : (1 - δ / 4) * τ ≤ 1 := calc (1 - δ / 4) * τ ≤ (1 - δ / 4) * (1 + δ / 4) := mul_le_mul_of_nonneg_left hδ1 D _ = 1 - δ ^ 2 / 16 := by ring _ ≤ 1 := by linarith only [sq_nonneg δ] have A : a.r j - δ ≤ ‖a.c i - a.c j‖ := by rcases ah j i inej.symm with (H | H) · rw [norm_sub_rev] linarith [H.1] have C : a.r j ≤ 4 := calc a.r j ≤ τ * a.r i := H.2 _ ≤ τ * 2 := (mul_le_mul_of_nonneg_left I τpos.le) _ ≤ 5 / 4 * 2 := (mul_le_mul_of_nonneg_right (by linarith only [hδ1, hδ2]) zero_le_two) _ ≤ 4 := by norm_num calc a.r j - δ ≤ a.r j - a.r j / 4 * δ := by refine' sub_le_sub le_rfl _ refine' mul_le_of_le_one_left δnonneg _ linarith only [C] _ = (1 - δ / 4) * a.r j := by ring _ ≤ (1 - δ / 4) * (τ * a.r i) := (mul_le_mul_of_nonneg_left H.2 D) _ ≤ 1 * a.r i := by rw [← mul_assoc] apply mul_le_mul_of_nonneg_right J (a.rpos _).le _ ≤ ‖a.c i - a.c j‖ := by rw [one_mul] exact H.1 set d := (2 / ‖a.c j‖) • a.c j with hd have : a.r j - δ ≤ ‖a.c i - d‖ + (a.r j - 1) := calc a.r j - δ ≤ ‖a.c i - a.c j‖ := A _ ≤ ‖a.c i - d‖ + ‖d - a.c j‖ := by simp only [← dist_eq_norm, dist_triangle] _ ≤ ‖a.c i - d‖ + (a.r j - 1) := by apply add_le_add_left have A : 0 ≤ 1 - 2 / ‖a.c j‖ := by simpa [div_le_iff (zero_le_two.trans_lt hj)] using hj.le rw [← one_smul ℝ (a.c j), hd, ← sub_smul, norm_smul, norm_sub_rev, Real.norm_eq_abs, abs_of_nonneg A, sub_mul] field_simp [(zero_le_two.trans_lt hj).ne'] linarith only [hcrj] linarith only [this] #align besicovitch.satellite_config.exists_normalized_aux2 Besicovitch.SatelliteConfig.exists_normalized_aux2 theorem exists_normalized_aux3 {N : ℕ} {τ : ℝ} (a : SatelliteConfig E N τ) (lastc : a.c (last N) = 0) (lastr : a.R (last N) = 1) (hτ : 1 ≤ τ) (δ : ℝ) (hδ1 : τ ≤ 1 + δ / 4) (i j : Fin N.succ) (inej : i ≠ j) (hi : 2 < ‖a.c i‖) (hij : ‖a.c i‖ ≤ ‖a.c j‖) : 1 - δ ≤ ‖(2 / ‖a.c i‖) • a.c i - (2 / ‖a.c j‖) • a.c j‖ := by have ah : ∀ i j, i ≠ j → a.r i ≤ ‖a.c i - a.c j‖ ∧ a.r j ≤ τ * a.r i ∨ a.r j ≤ ‖a.c j - a.c i‖ ∧ a.r i ≤ τ * a.r j := by simpa only [dist_eq_norm] using a.h have δnonneg : 0 ≤ δ := by linarith only [hτ, hδ1] have τpos : 0 < τ := _root_.zero_lt_one.trans_le hτ have hcrj : ‖a.c j‖ ≤ a.r j + 1 := by simpa only [lastc, lastr, dist_zero_right] using a.inter' j have A : a.r i ≤ ‖a.c i‖ := by have : i < last N := by apply lt_top_iff_ne_top.2 intro iN change i = last N at iN rw [iN, lastc, norm_zero] at hi exact lt_irrefl _ (zero_le_two.trans_lt hi) convert(a.hlast i this).1 rw [dist_eq_norm, lastc, sub_zero] have hj : 2 < ‖a.c j‖ := hi.trans_le hij set s := ‖a.c i‖ with hs have spos : 0 < s := zero_lt_two.trans hi set d := (s / ‖a.c j‖) • a.c j with hd have I : ‖a.c j - a.c i‖ ≤ ‖a.c j‖ - s + ‖d - a.c i‖ := calc ‖a.c j - a.c i‖ ≤ ‖a.c j - d‖ + ‖d - a.c i‖ := by simp [← dist_eq_norm, dist_triangle] _ = ‖a.c j‖ - ‖a.c i‖ + ‖d - a.c i‖ := by nth_rw 1 [← one_smul ℝ (a.c j)] rw [add_left_inj, hd, ← sub_smul, norm_smul, Real.norm_eq_abs, abs_of_nonneg, sub_mul, one_mul, div_mul_cancel _ (zero_le_two.trans_lt hj).ne'] rwa [sub_nonneg, div_le_iff (zero_lt_two.trans hj), one_mul] have J : a.r j - ‖a.c j - a.c i‖ ≤ s / 2 * δ := calc a.r j - ‖a.c j - a.c i‖ ≤ s * (τ - 1) := by rcases ah j i inej.symm with (H | H) · calc a.r j - ‖a.c j - a.c i‖ ≤ 0 := sub_nonpos.2 H.1 _ ≤ s * (τ - 1) := mul_nonneg spos.le (sub_nonneg.2 hτ) · rw [norm_sub_rev] at H calc a.r j - ‖a.c j - a.c i‖ ≤ τ * a.r i - a.r i := sub_le_sub H.2 H.1 _ = a.r i * (τ - 1) := by ring _ ≤ s * (τ - 1) := mul_le_mul_of_nonneg_right A (sub_nonneg.2 hτ) _ ≤ s * (δ / 2) := (mul_le_mul_of_nonneg_left (by linarith only [δnonneg, hδ1]) spos.le) _ = s / 2 * δ := by ring have invs_nonneg : 0 ≤ 2 / s := div_nonneg zero_le_two (zero_le_two.trans hi.le) calc 1 - δ = 2 / s * (s / 2 - s / 2 * δ) := by field_simp [spos.ne'] ring _ ≤ 2 / s * ‖d - a.c i‖ := (mul_le_mul_of_nonneg_left (by linarith only [hcrj, I, J, hi]) invs_nonneg) _ = ‖(2 / s) • a.c i - (2 / ‖a.c j‖) • a.c j‖ := by conv_lhs => rw [norm_sub_rev, ← abs_of_nonneg invs_nonneg] rw [← Real.norm_eq_abs, ← norm_smul, smul_sub, hd, smul_smul] congr 3 field_simp [spos.ne'] #align besicovitch.satellite_config.exists_normalized_aux3 Besicovitch.SatelliteConfig.exists_normalized_aux3 theorem exists_normalized {N : ℕ} {τ : ℝ} (a : SatelliteConfig E N τ) (lastc : a.c (last N) = 0) (lastr : a.R (last N) = 1) (hτ : 1 ≤ τ) (δ : ℝ) (hδ1 : τ ≤ 1 + δ / 4) (hδ2 : δ ≤ 1) : ∃ c' : Fin N.succ → E, (∀ n, ‖c' n‖ ≤ 2) ∧ ∀ i j, i ≠ j → 1 - δ ≤ ‖c' i - c' j‖ := by let c' : Fin N.succ → E := fun i => if ‖a.c i‖ ≤ 2 then a.c i else (2 / ‖a.c i‖) • a.c i have norm_c'_le : ∀ i, ‖c' i‖ ≤ 2 := by intro i simp only [c'] split_ifs · exact h by_cases hi : ‖a.c i‖ = 0 <;> field_simp [norm_smul, hi] refine' ⟨c', fun n => norm_c'_le n, fun i j inej => _⟩ -- up to exchanging `i` and `j`, one can assume `∥c i∥ ≤ ∥c j∥`. wlog hij : ‖a.c i‖ ≤ ‖a.c j‖ generalizing i j · rw [norm_sub_rev] exact this j i inej.symm (le_of_not_le hij) rcases le_or_lt ‖a.c j‖ 2 with (Hj | Hj) -- case `∥c j∥ ≤ 2` (and therefore also `∥c i∥ ≤ 2`) · simp_rw [c', Hj, hij.trans Hj, if_true] exact exists_normalized_aux1 a lastr hτ δ hδ1 hδ2 i j inej -- case `2 < ‖c j‖` · have H'j : ‖a.c j‖ ≤ 2 ↔ False := by simpa only [not_le, iff_false_iff] using Hj rcases le_or_lt ‖a.c i‖ 2 with (Hi | Hi) · -- case `‖c i‖ ≤ 2` simp_rw [c', Hi, if_true, H'j, if_false] exact exists_normalized_aux2 a lastc lastr hτ δ hδ1 hδ2 i j inej Hi Hj · -- case `2 < ‖c i‖` have H'i : ‖a.c i‖ ≤ 2 ↔ False := by simpa only [not_le, iff_false_iff] using Hi simp_rw [c', H'i, if_false, H'j, if_false] exact exists_normalized_aux3 a lastc lastr hτ δ hδ1 i j inej Hi hij #align besicovitch.satellite_config.exists_normalized Besicovitch.SatelliteConfig.exists_normalized end SatelliteConfig variable (E) [NormedSpace ℝ E] [FiniteDimensional ℝ E] /-- In a normed vector space `E`, there can be no satellite configuration with `multiplicity E + 1` points and the parameter `good_τ E`. This will ensure that in the inductive construction to get the Besicovitch covering families, there will never be more than `multiplicity E` nonempty families. -/ theorem isEmpty_satelliteConfig_multiplicity : IsEmpty (SatelliteConfig E (multiplicity E) (goodτ E)) := ⟨by intro a let b := a.center_and_rescale rcases b.exists_normalized a.center_and_rescale_center a.center_and_rescale_radius (one_lt_good_τ E).le (good_δ E) le_rfl (good_δ_lt_one E).le with ⟨c', c'_le_two, hc'⟩ exact lt_irrefl _ ((Nat.lt_succ_self _).trans_le (le_multiplicity_of_δ_of_fin c' c'_le_two hc'))⟩ #align besicovitch.is_empty_satellite_config_multiplicity Besicovitch.isEmpty_satelliteConfig_multiplicity instance (priority := 100) : HasBesicovitchCovering E := ⟨⟨multiplicity E, goodτ E, one_lt_goodτ E, isEmpty_satelliteConfig_multiplicity E⟩⟩ end Besicovitch
Formal statement is: lemma complex_cnj_divide [simp]: "cnj (x / y) = cnj x / cnj y" Informal statement is: The complex conjugate of a quotient is the quotient of the complex conjugates.
/- Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov -/ import algebra.big_operators.order import algebra.indicator_function /-! # Finite products and sums over types and sets We define products and sums over types and subsets of types, with no finiteness hypotheses. All infinite products and sums are defined to be junk values (i.e. one or zero). This approach is sometimes easier to use than `finset.sum`, when issues arise with `finset` and `fintype` being data. ## Main definitions We use the following variables: * `α`, `β` - types with no structure; * `s`, `t` - sets * `M`, `N` - additive or multiplicative commutative monoids * `f`, `g` - functions Definitions in this file: * `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite. Zero otherwise. * `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if it's finite. One otherwise. ## Notation * `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f` * `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f` This notation works for functions `f : p → M`, where `p : Prop`, so the following works: * `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : set α` : sum over the set `s`; * `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`; * `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`. ## Implementation notes `finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings where the user is not interested in computability and wants to do reasoning without running into typeclass diamonds caused by the constructive finiteness used in definitions such as `finset` and `fintype`. By sticking solely to `set.finite` we avoid these problems. We are aware that there are other solutions but for beginner mathematicians this approach is easier in practice. Another application is the construction of a partition of unity from a collection of “bump” function. In this case the finite set depends on the point and it's convenient to have a definition that does not mention the set explicitly. The first arguments in all definitions and lemmas is the codomain of the function of the big operator. This is necessary for the heuristic in `@[to_additive]`. See the documentation of `to_additive.attr` for more information. We did not add `is_finite (X : Type) : Prop`, because it is simply `nonempty (fintype X)`. ## Tags finsum, finprod, finite sum, finite product -/ open function set /-! ### Definition and relation to `finset.sum` and `finset.prod` -/ section sort variables {M N : Type*} {α β ι : Sort*} [comm_monoid M] [comm_monoid N] open_locale big_operators section /- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas with `classical.dec` in their statement. -/ open_locale classical /-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero otherwise. -/ @[irreducible] noncomputable def finsum {M α} [add_comm_monoid M] (f : α → M) : M := if h : finite (support (f ∘ plift.down)) then ∑ i in h.to_finset, f i.down else 0 /-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's finite. One otherwise. -/ @[irreducible, to_additive] noncomputable def finprod (f : α → M) : M := if h : finite (mul_support (f ∘ plift.down)) then ∏ i in h.to_finset, f i.down else 1 end localized "notation `∑ᶠ` binders `, ` r:(scoped:67 f, finsum f) := r" in big_operators localized "notation `∏ᶠ` binders `, ` r:(scoped:67 f, finprod f) := r" in big_operators @[to_additive] lemma finprod_eq_prod_plift_of_mul_support_to_finset_subset {f : α → M} (hf : finite (mul_support (f ∘ plift.down))) {s : finset (plift α)} (hs : hf.to_finset ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i.down := begin rw [finprod, dif_pos], refine finset.prod_subset hs (λ x hx hxf, _), rwa [hf.mem_to_finset, nmem_mul_support] at hxf end @[to_additive] lemma finprod_eq_prod_plift_of_mul_support_subset {f : α → M} {s : finset (plift α)} (hs : mul_support (f ∘ plift.down) ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i.down := finprod_eq_prod_plift_of_mul_support_to_finset_subset (s.finite_to_set.subset hs) $ λ x hx, by { rw finite.mem_to_finset at hx, exact hs hx } @[simp, to_additive] lemma finprod_one : ∏ᶠ i : α, (1 : M) = 1 := begin have : mul_support (λ x : plift α, (λ _, 1 : α → M) x.down) ⊆ (∅ : finset (plift α)), from λ x h, h rfl, rw [finprod_eq_prod_plift_of_mul_support_subset this, finset.prod_empty] end @[to_additive] lemma finprod_of_is_empty [is_empty α] (f : α → M) : ∏ᶠ i, f i = 1 := by { rw ← finprod_one, congr } @[simp, to_additive] lemma finprod_false (f : false → M) : ∏ᶠ i, f i = 1 := finprod_of_is_empty _ @[to_additive] lemma finprod_eq_single (f : α → M) (a : α) (ha : ∀ x ≠ a, f x = 1) : ∏ᶠ x, f x = f a := begin have : mul_support (f ∘ plift.down) ⊆ ({plift.up a} : finset (plift α)), { intro x, contrapose, simpa [plift.eq_up_iff_down_eq] using ha x.down }, rw [finprod_eq_prod_plift_of_mul_support_subset this, finset.prod_singleton], end @[to_additive] lemma finprod_unique [unique α] (f : α → M) : ∏ᶠ i, f i = f default := finprod_eq_single f default $ λ x hx, (hx $ unique.eq_default _).elim @[simp, to_additive] lemma finprod_true (f : true → M) : ∏ᶠ i, f i = f trivial := @finprod_unique M true _ ⟨⟨trivial⟩, λ _, rfl⟩ f @[to_additive] lemma finprod_eq_dif {p : Prop} [decidable p] (f : p → M) : ∏ᶠ i, f i = if h : p then f h else 1 := begin split_ifs, { haveI : unique p := ⟨⟨h⟩, λ _, rfl⟩, exact finprod_unique f }, { haveI : is_empty p := ⟨h⟩, exact finprod_of_is_empty f } end @[to_additive] lemma finprod_eq_if {p : Prop} [decidable p] {x : M} : ∏ᶠ i : p, x = if p then x else 1 := finprod_eq_dif (λ _, x) @[to_additive] lemma finprod_congr {f g : α → M} (h : ∀ x, f x = g x) : finprod f = finprod g := congr_arg _ $ funext h @[congr, to_additive] lemma finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q) (hfg : ∀ h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by { subst q, exact finprod_congr hfg } attribute [congr] finsum_congr_Prop /-- To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on multipliers. -/ @[to_additive] lemma finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1) (hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) : p (∏ᶠ i, f i) := begin rw finprod, split_ifs, exacts [finset.prod_induction _ _ hp₁ hp₀ (λ i hi, hp₂ _), hp₀] end /-- To prove a property of a finite sum, it suffices to prove that the property is additive and holds on summands. -/ add_decl_doc finsum_induction lemma finprod_nonneg {R : Type*} [ordered_comm_semiring R] {f : α → R} (hf : ∀ x, 0 ≤ f x) : 0 ≤ ∏ᶠ x, f x := finprod_induction (λ x, 0 ≤ x) zero_le_one (λ x y, mul_nonneg) hf @[to_additive finsum_nonneg] lemma one_le_finprod' {M : Type*} [ordered_comm_monoid M] {f : α → M} (hf : ∀ i, 1 ≤ f i) : 1 ≤ ∏ᶠ i, f i := finprod_induction _ le_rfl (λ _ _, one_le_mul) hf @[to_additive] lemma monoid_hom.map_finprod_plift (f : M →* N) (g : α → M) (h : finite (mul_support $ g ∘ plift.down)) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := begin rw [finprod_eq_prod_plift_of_mul_support_subset h.coe_to_finset.ge, finprod_eq_prod_plift_of_mul_support_subset, f.map_prod], rw [h.coe_to_finset], exact mul_support_comp_subset f.map_one (g ∘ plift.down) end @[to_additive] lemma monoid_hom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := f.map_finprod_plift g (finite.of_fintype _) @[to_additive] lemma monoid_hom.map_finprod_of_preimage_one (f : M →* N) (hf : ∀ x, f x = 1 → x = 1) (g : α → M) : f (∏ᶠ i, g i) = ∏ᶠ i, f (g i) := begin by_cases hg : (mul_support $ g ∘ plift.down).finite, { exact f.map_finprod_plift g hg }, rw [finprod, dif_neg, f.map_one, finprod, dif_neg], exacts [infinite.mono (λ x hx, mt (hf (g x.down)) hx) hg, hg] end @[to_additive] lemma monoid_hom.map_finprod_of_injective (g : M →* N) (hg : injective g) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_of_preimage_one (λ x, (hg.eq_iff' g.map_one).mp) f @[to_additive] lemma mul_equiv.map_finprod (g : M ≃* N) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.to_monoid_hom.map_finprod_of_injective g.injective f lemma finsum_smul {R M : Type*} [ring R] [add_comm_group M] [module R M] [no_zero_smul_divisors R M] (f : ι → R) (x : M) : (∑ᶠ i, f i) • x = (∑ᶠ i, (f i) • x) := begin rcases eq_or_ne x 0 with rfl|hx, { simp }, exact ((smul_add_hom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _ end lemma smul_finsum {R M : Type*} [ring R] [add_comm_group M] [module R M] [no_zero_smul_divisors R M] (c : R) (f : ι → M) : c • (∑ᶠ i, f i) = (∑ᶠ i, c • f i) := begin rcases eq_or_ne c 0 with rfl|hc, { simp }, exact (smul_add_hom R M c).map_finsum_of_injective (smul_right_injective M hc) _ end @[to_additive] lemma finprod_inv_distrib {G : Type*} [comm_group G] (f : α → G) : ∏ᶠ x, (f x)⁻¹ = (∏ᶠ x, f x)⁻¹ := ((mul_equiv.inv G).map_finprod f).symm lemma finprod_inv_distrib₀ {G : Type*} [comm_group_with_zero G] (f : α → G) : ∏ᶠ x, (f x)⁻¹ = (∏ᶠ x, f x)⁻¹ := ((mul_equiv.inv₀ G).map_finprod f).symm end sort section type variables {α β ι M N : Type*} [comm_monoid M] [comm_monoid N] open_locale big_operators @[to_additive] lemma finprod_eq_mul_indicator_apply (s : set α) (f : α → M) (a : α) : ∏ᶠ (h : a ∈ s), f a = mul_indicator s f a := by convert finprod_eq_if @[simp, to_additive] lemma finprod_mem_mul_support (f : α → M) (a : α) : ∏ᶠ (h : f a ≠ 1), f a = f a := by rw [← mem_mul_support, finprod_eq_mul_indicator_apply, mul_indicator_mul_support] @[to_additive] lemma finprod_mem_def (s : set α) (f : α → M) : ∏ᶠ a ∈ s, f a = ∏ᶠ a, mul_indicator s f a := finprod_congr $ finprod_eq_mul_indicator_apply s f @[to_additive] lemma finprod_eq_prod_of_mul_support_subset (f : α → M) {s : finset α} (h : mul_support f ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i := begin have A : mul_support (f ∘ plift.down) = equiv.plift.symm '' mul_support f, { rw mul_support_comp_eq_preimage, exact (equiv.plift.symm.image_eq_preimage _).symm }, have : mul_support (f ∘ plift.down) ⊆ s.map equiv.plift.symm.to_embedding, { rw [A, finset.coe_map], exact image_subset _ h }, rw [finprod_eq_prod_plift_of_mul_support_subset this], simp end @[to_additive] lemma finprod_eq_prod_of_mul_support_to_finset_subset (f : α → M) (hf : finite (mul_support f)) {s : finset α} (h : hf.to_finset ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i := finprod_eq_prod_of_mul_support_subset _ $ λ x hx, h $ hf.mem_to_finset.2 hx @[to_additive] lemma finprod_def (f : α → M) [decidable (mul_support f).finite] : ∏ᶠ i : α, f i = if h : (mul_support f).finite then ∏ i in h.to_finset, f i else 1 := begin split_ifs, { exact finprod_eq_prod_of_mul_support_to_finset_subset _ h (finset.subset.refl _) }, { rw [finprod, dif_neg], rw [mul_support_comp_eq_preimage], exact mt (λ hf, hf.of_preimage equiv.plift.surjective) h} end @[to_additive] lemma finprod_of_infinite_mul_support {f : α → M} (hf : (mul_support f).infinite) : ∏ᶠ i, f i = 1 := by { classical, rw [finprod_def, dif_neg hf] } @[to_additive] lemma finprod_eq_prod (f : α → M) (hf : (mul_support f).finite) : ∏ᶠ i : α, f i = ∏ i in hf.to_finset, f i := by { classical, rw [finprod_def, dif_pos hf] } @[to_additive] lemma finprod_eq_prod_of_fintype [fintype α] (f : α → M) : ∏ᶠ i : α, f i = ∏ i, f i := finprod_eq_prod_of_mul_support_to_finset_subset _ (finite.of_fintype _) $ finset.subset_univ _ @[to_additive] lemma finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : finset α} (h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) : ∏ᶠ i (hi : p i), f i = ∏ i in t, f i := begin set s := {x | p x}, have : mul_support (s.mul_indicator f) ⊆ t, { rw [set.mul_support_mul_indicator], intros x hx, exact (h hx.2).1 hx.1 }, erw [finprod_mem_def, finprod_eq_prod_of_mul_support_subset _ this], refine finset.prod_congr rfl (λ x hx, mul_indicator_apply_eq_self.2 $ λ hxs, _), contrapose! hxs, exact (h hxs).2 hx end @[to_additive] lemma finprod_cond_ne (f : α → M) (a : α) [decidable_eq α] (hf : finite (mul_support f)) : (∏ᶠ i ≠ a, f i) = ∏ i in hf.to_finset.erase a, f i := begin apply finprod_cond_eq_prod_of_cond_iff, intros x hx, rw [finset.mem_erase, finite.mem_to_finset, mem_mul_support], exact ⟨λ h, and.intro h hx, λ h, h.1⟩ end @[to_additive] lemma finprod_mem_eq_prod_of_inter_mul_support_eq (f : α → M) {s : set α} {t : finset α} (h : s ∩ mul_support f = t ∩ mul_support f) : ∏ᶠ i ∈ s, f i = ∏ i in t, f i := finprod_cond_eq_prod_of_cond_iff _ $ by simpa [set.ext_iff] using h @[to_additive] lemma finprod_mem_eq_prod_of_subset (f : α → M) {s : set α} {t : finset α} (h₁ : s ∩ mul_support f ⊆ t) (h₂ : ↑t ⊆ s) : ∏ᶠ i ∈ s, f i = ∏ i in t, f i := finprod_cond_eq_prod_of_cond_iff _ $ λ x hx, ⟨λ h, h₁ ⟨h, hx⟩, λ h, h₂ h⟩ @[to_additive] lemma finprod_mem_eq_prod (f : α → M) {s : set α} (hf : (s ∩ mul_support f).finite) : ∏ᶠ i ∈ s, f i = ∏ i in hf.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_assoc] @[to_additive] lemma finprod_mem_eq_prod_filter (f : α → M) (s : set α) [decidable_pred (∈ s)] (hf : (mul_support f).finite) : ∏ᶠ i ∈ s, f i = ∏ i in finset.filter (∈ s) hf.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_comm, inter_left_comm] @[to_additive] lemma finprod_mem_eq_to_finset_prod (f : α → M) (s : set α) [fintype s] : ∏ᶠ i ∈ s, f i = ∏ i in s.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [coe_to_finset] @[to_additive] lemma finprod_mem_eq_finite_to_finset_prod (f : α → M) {s : set α} (hs : s.finite) : ∏ᶠ i ∈ s, f i = ∏ i in hs.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [hs.coe_to_finset] @[to_additive] lemma finprod_mem_finset_eq_prod (f : α → M) (s : finset α) : ∏ᶠ i ∈ s, f i = ∏ i in s, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl @[to_additive] lemma finprod_mem_coe_finset (f : α → M) (s : finset α) : ∏ᶠ i ∈ (s : set α), f i = ∏ i in s, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl @[to_additive] lemma finprod_mem_eq_one_of_infinite {f : α → M} {s : set α} (hs : (s ∩ mul_support f).infinite) : ∏ᶠ i ∈ s, f i = 1 := begin rw finprod_mem_def, apply finprod_of_infinite_mul_support, rwa [← mul_support_mul_indicator] at hs end @[to_additive] lemma finprod_mem_eq_one_of_forall_eq_one {f : α → M} {s : set α} (h : ∀ x ∈ s, f x = 1) : ∏ᶠ i ∈ s, f i = 1 := by simp [h] {contextual := tt} @[to_additive] lemma finprod_mem_inter_mul_support (f : α → M) (s : set α) : ∏ᶠ i ∈ (s ∩ mul_support f), f i = ∏ᶠ i ∈ s, f i := by rw [finprod_mem_def, finprod_mem_def, mul_indicator_inter_mul_support] @[to_additive] lemma finprod_mem_inter_mul_support_eq (f : α → M) (s t : set α) (h : s ∩ mul_support f = t ∩ mul_support f) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_support, h, finprod_mem_inter_mul_support] @[to_additive] lemma finprod_mem_inter_mul_support_eq' (f : α → M) (s t : set α) (h : ∀ x ∈ mul_support f, x ∈ s ↔ x ∈ t) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := begin apply finprod_mem_inter_mul_support_eq, ext x, exact and_congr_left (h x) end @[to_additive] lemma finprod_mem_univ (f : α → M) : ∏ᶠ i ∈ @set.univ α, f i = ∏ᶠ i : α, f i := finprod_congr $ λ i, finprod_true _ variables {f g : α → M} {a b : α} {s t : set α} @[to_additive] lemma finprod_mem_congr (h₀ : s = t) (h₁ : ∀ x ∈ t, f x = g x) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, g i := h₀.symm ▸ (finprod_congr $ λ i, finprod_congr_Prop rfl (h₁ i)) @[to_additive] lemma finprod_eq_one_of_forall_eq_one {f : α → M} (h : ∀ x, f x = 1) : ∏ᶠ i, f i = 1 := by simp [h] {contextual := tt} /-! ### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication -/ /-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals the product of `f i` multiplied by the product over `g i`. -/ @[to_additive] lemma finprod_mul_distrib (hf : (mul_support f).finite) (hg : (mul_support g).finite) : ∏ᶠ i, (f i * g i) = (∏ᶠ i, f i) * ∏ᶠ i, g i := begin classical, rw [finprod_eq_prod_of_mul_support_to_finset_subset _ hf (finset.subset_union_left _ _), finprod_eq_prod_of_mul_support_to_finset_subset _ hg (finset.subset_union_right _ _), ← finset.prod_mul_distrib], refine finprod_eq_prod_of_mul_support_subset _ _, simp [mul_support_mul] end /-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i / g i` equals the product of `f i` divided by the product over `g i`. -/ @[to_additive] lemma finprod_div_distrib {G : Type*} [comm_group G] {f g : α → G} (hf : (mul_support f).finite) (hg : (mul_support g).finite) : ∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i := by simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mul_support_inv g).symm.rec hg), finprod_inv_distrib] lemma finprod_div_distrib₀ {G : Type*} [comm_group_with_zero G] {f g : α → G} (hf : (mul_support f).finite) (hg : (mul_support g).finite) : ∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i := by simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mul_support_inv₀ g).symm.rec hg), finprod_inv_distrib₀] /-- A more general version of `finprod_mem_mul_distrib` that requires `s ∩ mul_support f` and `s ∩ mul_support g` instead of `s` to be finite. -/ @[to_additive] lemma finprod_mem_mul_distrib' (hf : (s ∩ mul_support f).finite) (hg : (s ∩ mul_support g).finite) : ∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := begin rw [← mul_support_mul_indicator] at hf hg, simp only [finprod_mem_def, mul_indicator_mul, finprod_mul_distrib hf hg] end /-- The product of constant one over any set equals one. -/ @[to_additive] lemma finprod_mem_one (s : set α) : ∏ᶠ i ∈ s, (1 : M) = 1 := by simp /-- If a function `f` equals one on a set `s`, then the product of `f i` over `i ∈ s` equals one. -/ @[to_additive] lemma finprod_mem_of_eq_on_one (hf : eq_on f 1 s) : ∏ᶠ i ∈ s, f i = 1 := by { rw ← finprod_mem_one s, exact finprod_mem_congr rfl hf } /-- If the product of `f i` over `i ∈ s` is not equal to one, then there is some `x ∈ s` such that `f x ≠ 1`. -/ @[to_additive] lemma exists_ne_one_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : ∃ x ∈ s, f x ≠ 1 := begin by_contra' h', exact h (finprod_mem_of_eq_on_one h') end /-- Given a finite set `s`, the product of `f i * g i` over `i ∈ s` equals the product of `f i` over `i ∈ s` times the product of `g i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_mul_distrib (hs : s.finite) : ∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := finprod_mem_mul_distrib' (hs.inter_of_left _) (hs.inter_of_left _) @[to_additive] lemma monoid_hom.map_finprod {f : α → M} (g : M →* N) (hf : (mul_support f).finite) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_plift f $ hf.preimage $ equiv.plift.injective.inj_on _ /-- A more general version of `monoid_hom.map_finprod_mem` that requires `s ∩ mul_support f` and instead of `s` to be finite. -/ @[to_additive] lemma monoid_hom.map_finprod_mem' {f : α → M} (g : M →* N) (h₀ : (s ∩ mul_support f).finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, (g (f i)) := begin rw [g.map_finprod], { simp only [g.map_finprod_Prop] }, { simpa only [finprod_eq_mul_indicator_apply, mul_support_mul_indicator] } end /-- Given a monoid homomorphism `g : M →* N`, and a function `f : α → M`, the value of `g` at the product of `f i` over `i ∈ s` equals the product of `(g ∘ f) i` over `s`. -/ @[to_additive] lemma monoid_hom.map_finprod_mem (f : α → M) (g : M →* N) (hs : s.finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, g (f i) := g.map_finprod_mem' (hs.inter_of_left _) @[to_additive] lemma mul_equiv.map_finprod_mem (g : M ≃* N) (f : α → M) {s : set α} (hs : s.finite) : g (∏ᶠ i ∈ s, f i) = ∏ᶠ i ∈ s, g (f i) := g.to_monoid_hom.map_finprod_mem f hs @[to_additive] lemma finprod_mem_inv_distrib {G : Type*} [comm_group G] (f : α → G) (hs : s.finite) : ∏ᶠ x ∈ s, (f x)⁻¹ = (∏ᶠ x ∈ s, f x)⁻¹ := ((mul_equiv.inv G).map_finprod_mem f hs).symm lemma finprod_mem_inv_distrib₀ {G : Type*} [comm_group_with_zero G] (f : α → G) (hs : s.finite) : ∏ᶠ x ∈ s, (f x)⁻¹ = (∏ᶠ x ∈ s, f x)⁻¹ := ((mul_equiv.inv₀ G).map_finprod_mem f hs).symm /-- Given a finite set `s`, the product of `f i / g i` over `i ∈ s` equals the product of `f i` over `i ∈ s` divided by the product of `g i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_div_distrib {G : Type*} [comm_group G] (f g : α → G) (hs : s.finite) : ∏ᶠ i ∈ s, f i / g i = (∏ᶠ i ∈ s, f i) / ∏ᶠ i ∈ s, g i := by simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib g hs] lemma finprod_mem_div_distrib₀ {G : Type*} [comm_group_with_zero G] (f g : α → G) (hs : s.finite) : ∏ᶠ i ∈ s, f i / g i = (∏ᶠ i ∈ s, f i) / ∏ᶠ i ∈ s, g i := by simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib₀ g hs] /-! ### `∏ᶠ x ∈ s, f x` and set operations -/ /-- The product of any function over an empty set is one. -/ @[to_additive] lemma finprod_mem_empty : ∏ᶠ i ∈ (∅ : set α), f i = 1 := by simp /-- A set `s` is not empty if the product of some function over `s` is not equal to one. -/ @[to_additive] lemma nonempty_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : s.nonempty := ne_empty_iff_nonempty.1 $ λ h', h $ h'.symm ▸ finprod_mem_empty /-- Given finite sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` times the product of `f i` over `i ∈ s ∩ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive] lemma finprod_mem_union_inter (hs : s.finite) (ht : t.finite) : (∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := begin lift s to finset α using hs, lift t to finset α using ht, classical, rw [← finset.coe_union, ← finset.coe_inter], simp only [finprod_mem_coe_finset, finset.prod_union_inter] end /-- A more general version of `finprod_mem_union_inter` that requires `s ∩ mul_support f` and `t ∩ mul_support f` instead of `s` and `t` to be finite. -/ @[to_additive] lemma finprod_mem_union_inter' (hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) : (∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := begin rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t, ← finprod_mem_union_inter hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support, ← finprod_mem_inter_mul_support f (s ∩ t)], congr' 2, rw [inter_left_comm, inter_assoc, inter_assoc, inter_self, inter_left_comm] end /-- A more general version of `finprod_mem_union` that requires `s ∩ mul_support f` and `t ∩ mul_support f` instead of `s` and `t` to be finite. -/ @[to_additive] lemma finprod_mem_union' (hst : disjoint s t) (hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_union_inter' hs ht, disjoint_iff_inter_eq_empty.1 hst, finprod_mem_empty, mul_one] /-- Given two finite disjoint sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive] lemma finprod_mem_union (hst : disjoint s t) (hs : s.finite) (ht : t.finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := finprod_mem_union' hst (hs.inter_of_left _) (ht.inter_of_left _) /-- A more general version of `finprod_mem_union'` that requires `s ∩ mul_support f` and `t ∩ mul_support f` instead of `s` and `t` to be disjoint -/ @[to_additive] lemma finprod_mem_union'' (hst : disjoint (s ∩ mul_support f) (t ∩ mul_support f)) (hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t, ← finprod_mem_union hst hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support] /-- The product of `f i` over `i ∈ {a}` equals `f a`. -/ @[to_additive] lemma finprod_mem_singleton : ∏ᶠ i ∈ ({a} : set α), f i = f a := by rw [← finset.coe_singleton, finprod_mem_coe_finset, finset.prod_singleton] @[simp, to_additive] lemma finprod_cond_eq_left : ∏ᶠ i = a, f i = f a := finprod_mem_singleton @[simp, to_additive] lemma finprod_cond_eq_right : ∏ᶠ i (hi : a = i), f i = f a := by simp [@eq_comm _ a] /-- A more general version of `finprod_mem_insert` that requires `s ∩ mul_support f` instead of `s` to be finite. -/ @[to_additive] lemma finprod_mem_insert' (f : α → M) (h : a ∉ s) (hs : (s ∩ mul_support f).finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := begin rw [insert_eq, finprod_mem_union' _ _ hs, finprod_mem_singleton], { rwa disjoint_singleton_left }, { exact (finite_singleton a).inter_of_left _ } end /-- Given a finite set `s` and an element `a ∉ s`, the product of `f i` over `i ∈ insert a s` equals `f a` times the product of `f i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_insert (f : α → M) (h : a ∉ s) (hs : s.finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := finprod_mem_insert' f h $ hs.inter_of_left _ /-- If `f a = 1` for all `a ∉ s`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_insert_of_eq_one_if_not_mem (h : a ∉ s → f a = 1) : ∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i := begin refine finprod_mem_inter_mul_support_eq' _ _ _ (λ x hx, ⟨_, or.inr⟩), rintro (rfl|hxs), exacts [not_imp_comm.1 h hx, hxs] end /-- If `f a = 1`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_insert_one (h : f a = 1) : ∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i := finprod_mem_insert_of_eq_one_if_not_mem (λ _, h) /-- If the multiplicative support of `f` is finite, then for every `x` in the domain of `f`, `f x` divides `finprod f`. -/ lemma finprod_mem_dvd {f : α → N} (a : α) (hf : finite (mul_support f)) : f a ∣ finprod f := begin by_cases ha : a ∈ mul_support f, { rw finprod_eq_prod_of_mul_support_to_finset_subset f hf (set.subset.refl _), exact finset.dvd_prod_of_mem f ((finite.mem_to_finset hf).mpr ha) }, { rw nmem_mul_support.mp ha, exact one_dvd (finprod f) } end /-- The product of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a * f b`. -/ @[to_additive] lemma finprod_mem_pair (h : a ≠ b) : ∏ᶠ i ∈ ({a, b} : set α), f i = f a * f b := by { rw [finprod_mem_insert, finprod_mem_singleton], exacts [h, finite_singleton b] } /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s ∩ mul_support (f ∘ g)`. -/ @[to_additive] lemma finprod_mem_image' {s : set β} {g : β → α} (hg : set.inj_on g (s ∩ mul_support (f ∘ g))) : ∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) := begin classical, by_cases hs : finite (s ∩ mul_support (f ∘ g)), { have hg : ∀ (x ∈ hs.to_finset) (y ∈ hs.to_finset), g x = g y → x = y, by simpa only [hs.mem_to_finset], rw [finprod_mem_eq_prod _ hs, ← finset.prod_image hg], refine finprod_mem_eq_prod_of_inter_mul_support_eq f _, rw [finset.coe_image, hs.coe_to_finset, ← image_inter_mul_support_eq, inter_assoc, inter_self] }, { rw [finprod_mem_eq_one_of_infinite hs, finprod_mem_eq_one_of_infinite], rwa [image_inter_mul_support_eq, infinite_image_iff hg] } end /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s`. -/ @[to_additive] lemma finprod_mem_image {β} {s : set β} {g : β → α} (hg : set.inj_on g s) : ∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) := finprod_mem_image' $ hg.mono $ inter_subset_left _ _ /-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective on `mul_support (f ∘ g)`. -/ @[to_additive] lemma finprod_mem_range' {g : β → α} (hg : set.inj_on g (mul_support (f ∘ g))) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := begin rw [← image_univ, finprod_mem_image', finprod_mem_univ], rwa univ_inter end /-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective. -/ @[to_additive] lemma finprod_mem_range {g : β → α} (hg : injective g) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := finprod_mem_range' (hg.inj_on _) /-- The product of `f i` over `s : set α` is equal to the product of `g j` over `t : set β` if there exists a function `e : α → β` such that `e` is bijective from `s` to `t` and for all `x` in `s` we have `f x = g (e x)`. See also `finset.prod_bij`. -/ @[to_additive] lemma finprod_mem_eq_of_bij_on {s : set α} {t : set β} {f : α → M} {g : β → M} (e : α → β) (he₀ : set.bij_on e s t) (he₁ : ∀ x ∈ s, f x = g (e x)) : ∏ᶠ i ∈ s, f i = ∏ᶠ j ∈ t, g j := begin rw [← set.bij_on.image_eq he₀, finprod_mem_image he₀.2.1], exact finprod_mem_congr rfl he₁ end /-- The product of `f i` is equal to the product of `g j` if there exists a bijective function `e : α → β` such that for all `x` we have `f x = g (e x)`. See `finprod_comp`, `fintype.prod_bijective` and `finset.prod_bij` -/ @[to_additive] lemma finprod_eq_of_bijective {f : α → M} {g : β → M} (e : α → β) (he₀ : function.bijective e) (he₁ : ∀ x, f x = g (e x)) : ∏ᶠ i, f i = ∏ᶠ j, g j := begin rw [← finprod_mem_univ f, ← finprod_mem_univ g], exact finprod_mem_eq_of_bij_on _ (bijective_iff_bij_on_univ.mp he₀) (λ x _, he₁ x), end /-- Given a bijective function `e` the product of `g i` is equal to the product of `g (e i)`. See also `finprod_eq_of_bijective`, `fintype.prod_bijective` and `finset.prod_bij` -/ @[to_additive] lemma finprod_comp {g : β → M} (e : α → β) (he₀ : function.bijective e) : ∏ᶠ i, g (e i) = ∏ᶠ j, g j := finprod_eq_of_bijective e he₀ (λ x, rfl) @[to_additive] lemma finprod_set_coe_eq_finprod_mem (s : set α) : ∏ᶠ j : s, f j = ∏ᶠ i ∈ s, f i := begin rw [← finprod_mem_range, subtype.range_coe], exact subtype.coe_injective end @[to_additive] lemma finprod_subtype_eq_finprod_cond (p : α → Prop) : ∏ᶠ j : subtype p, f j = ∏ᶠ i (hi : p i), f i := finprod_set_coe_eq_finprod_mem {i | p i} @[to_additive] lemma finprod_mem_inter_mul_diff' (t : set α) (h : (s ∩ mul_support f).finite) : (∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i := begin rw [← finprod_mem_union', inter_union_diff], exacts [λ x hx, hx.2.2 hx.1.2, h.subset (λ x hx, ⟨hx.1.1, hx.2⟩), h.subset (λ x hx, ⟨hx.1.1, hx.2⟩)], end @[to_additive] lemma finprod_mem_inter_mul_diff (t : set α) (h : s.finite) : (∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i := finprod_mem_inter_mul_diff' _ $ h.inter_of_left _ /-- A more general version of `finprod_mem_mul_diff` that requires `t ∩ mul_support f` instead of `t` to be finite. -/ @[to_additive] lemma finprod_mem_mul_diff' (hst : s ⊆ t) (ht : (t ∩ mul_support f).finite) : (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_diff' _ ht, inter_eq_self_of_subset_right hst] /-- Given a finite set `t` and a subset `s` of `t`, the product of `f i` over `i ∈ s` times the product of `f i` over `t \ s` equals the product of `f i` over `i ∈ t`. -/ @[to_additive] lemma finprod_mem_mul_diff (hst : s ⊆ t) (ht : t.finite) : (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i := finprod_mem_mul_diff' hst (ht.inter_of_left _) /-- Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the product of `f a` over the union `⋃ i, t i` is equal to the product over all indexes `i` of the products of `f a` over `a ∈ t i`. -/ @[to_additive] lemma finprod_mem_Union [fintype ι] {t : ι → set α} (h : pairwise (disjoint on t)) (ht : ∀ i, (t i).finite) : ∏ᶠ a ∈ (⋃ i : ι, t i), f a = ∏ᶠ i, (∏ᶠ a ∈ t i, f a) := begin lift t to ι → finset α using ht, classical, rw [← bUnion_univ, ← finset.coe_univ, ← finset.coe_bUnion, finprod_mem_coe_finset, finset.prod_bUnion], { simp only [finprod_mem_coe_finset, finprod_eq_prod_of_fintype] }, { exact λ x _ y _ hxy, finset.disjoint_iff_disjoint_coe.2 (h x y hxy) } end /-- Given a family of sets `t : ι → set α`, a finite set `I` in the index type such that all sets `t i`, `i ∈ I`, are finite, if all `t i`, `i ∈ I`, are pairwise disjoint, then the product of `f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the product over `i ∈ I` of the products of `f a` over `a ∈ t i`. -/ @[to_additive] lemma finprod_mem_bUnion {I : set ι} {t : ι → set α} (h : I.pairwise_disjoint t) (hI : I.finite) (ht : ∀ i ∈ I, (t i).finite) : ∏ᶠ a ∈ ⋃ x ∈ I, t x, f a = ∏ᶠ i ∈ I, ∏ᶠ j ∈ t i, f j := begin haveI := hI.fintype, rw [bUnion_eq_Union, finprod_mem_Union, ← finprod_set_coe_eq_finprod_mem], exacts [λ x y hxy, h x.2 y.2 (subtype.coe_injective.ne hxy), λ b, ht b b.2] end /-- If `t` is a finite set of pairwise disjoint finite sets, then the product of `f a` over `a ∈ ⋃₀ t` is the product over `s ∈ t` of the products of `f a` over `a ∈ s`. -/ @[to_additive] lemma finprod_mem_sUnion {t : set (set α)} (h : t.pairwise_disjoint id) (ht₀ : t.finite) (ht₁ : ∀ x ∈ t, set.finite x) : ∏ᶠ a ∈ ⋃₀ t, f a = ∏ᶠ s ∈ t, ∏ᶠ a ∈ s, f a := by { rw set.sUnion_eq_bUnion, exact finprod_mem_bUnion h ht₀ ht₁ } @[to_additive] lemma mul_finprod_cond_ne (a : α) (hf : finite (mul_support f)) : f a * (∏ᶠ i ≠ a, f i) = ∏ᶠ i, f i := begin classical, rw [finprod_eq_prod _ hf], have h : ∀ x : α, f x ≠ 1 → (x ≠ a ↔ x ∈ hf.to_finset \ {a}), { intros x hx, rw [finset.mem_sdiff, finset.mem_singleton, finite.mem_to_finset, mem_mul_support], exact ⟨λ h, and.intro hx h, λ h, h.2⟩,}, rw [finprod_cond_eq_prod_of_cond_iff f h, finset.sdiff_singleton_eq_erase], by_cases ha : a ∈ mul_support f, { apply finset.mul_prod_erase _ _ ((finite.mem_to_finset _ ).mpr ha), }, { rw [mem_mul_support, not_not] at ha, rw [ha, one_mul], apply finset.prod_erase _ ha, } end /-- If `s : set α` and `t : set β` are finite sets, then the product over `s` commutes with the product over `t`. -/ @[to_additive] lemma finprod_mem_comm {s : set α} {t : set β} (f : α → β → M) (hs : s.finite) (ht : t.finite) : ∏ᶠ i ∈ s, ∏ᶠ j ∈ t, f i j = ∏ᶠ j ∈ t, ∏ᶠ i ∈ s, f i j := begin lift s to finset α using hs, lift t to finset β using ht, simp only [finprod_mem_coe_finset], exact finset.prod_comm end /-- To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on multipliers. -/ @[to_additive] lemma finprod_mem_induction (p : M → Prop) (hp₀ : p 1) (hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ x ∈ s, p $ f x) : p (∏ᶠ i ∈ s, f i) := finprod_induction _ hp₀ hp₁ $ λ x, finprod_induction _ hp₀ hp₁ $ hp₂ x lemma finprod_cond_nonneg {R : Type*} [ordered_comm_semiring R] {p : α → Prop} {f : α → R} (hf : ∀ x, p x → 0 ≤ f x) : 0 ≤ ∏ᶠ x (h : p x), f x := finprod_nonneg $ λ x, finprod_nonneg $ hf x @[to_additive] lemma single_le_finprod {M : Type*} [ordered_comm_monoid M] (i : α) {f : α → M} (hf : finite (mul_support f)) (h : ∀ j, 1 ≤ f j) : f i ≤ ∏ᶠ j, f j := by classical; calc f i ≤ ∏ j in insert i hf.to_finset, f j : finset.single_le_prod' (λ j hj, h j) (finset.mem_insert_self _ _) ... = ∏ᶠ j, f j : (finprod_eq_prod_of_mul_support_to_finset_subset _ hf (finset.subset_insert _ _)).symm lemma finprod_eq_zero {M₀ : Type*} [comm_monoid_with_zero M₀] (f : α → M₀) (x : α) (hx : f x = 0) (hf : finite (mul_support f)) : ∏ᶠ x, f x = 0 := begin nontriviality, rw [finprod_eq_prod f hf], refine finset.prod_eq_zero (hf.mem_to_finset.2 _) hx, simp [hx] end @[to_additive] lemma finprod_prod_comm (s : finset β) (f : α → β → M) (h : ∀ b ∈ s, (mul_support (λ a, f a b)).finite) : ∏ᶠ a : α, ∏ b in s, f a b = ∏ b in s, ∏ᶠ a : α, f a b := begin have hU : mul_support (λ a, ∏ b in s, f a b) ⊆ (s.finite_to_set.bUnion (λ b hb, h b (finset.mem_coe.1 hb))).to_finset, { rw finite.coe_to_finset, intros x hx, simp only [exists_prop, mem_Union, ne.def, mem_mul_support, finset.mem_coe], contrapose! hx, rw [mem_mul_support, not_not, finset.prod_congr rfl hx, finset.prod_const_one] }, rw [finprod_eq_prod_of_mul_support_subset _ hU, finset.prod_comm], refine finset.prod_congr rfl (λ b hb, (finprod_eq_prod_of_mul_support_subset _ _).symm), intros a ha, simp only [finite.coe_to_finset, mem_Union], exact ⟨b, hb, ha⟩ end @[to_additive] lemma prod_finprod_comm (s : finset α) (f : α → β → M) (h : ∀ a ∈ s, (mul_support (f a)).finite) : ∏ a in s, ∏ᶠ b : β, f a b = ∏ᶠ b : β, ∏ a in s, f a b := (finprod_prod_comm s (λ b a, f a b) h).symm lemma mul_finsum {R : Type*} [semiring R] (f : α → R) (r : R) (h : (function.support f).finite) : r * ∑ᶠ a : α, f a = ∑ᶠ a : α, r * f a := (add_monoid_hom.mul_left r).map_finsum h lemma finsum_mul {R : Type*} [semiring R] (f : α → R) (r : R) (h : (function.support f).finite) : (∑ᶠ a : α, f a) * r = ∑ᶠ a : α, f a * r := (add_monoid_hom.mul_right r).map_finsum h @[to_additive] lemma finset.mul_support_of_fiberwise_prod_subset_image [decidable_eq β] (s : finset α) (f : α → M) (g : α → β) : mul_support (λ b, (s.filter (λ a, g a = b)).prod f) ⊆ s.image g := begin simp only [finset.coe_image, set.mem_image, finset.mem_coe, function.support_subset_iff], intros b h, suffices : (s.filter (λ (a : α), g a = b)).nonempty, { simpa only [s.fiber_nonempty_iff_mem_image g b, finset.mem_image, exists_prop], }, exact finset.nonempty_of_prod_ne_one h, end /-- Note that `b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd` iff `(a, b) ∈ s` so we can simplify the right hand side of this lemma. However the form stated here is more useful for iterating this lemma, e.g., if we have `f : α × β × γ → M`. -/ @[to_additive] lemma finprod_mem_finset_product' [decidable_eq α] [decidable_eq β] (s : finset (α × β)) (f : α × β → M) : ∏ᶠ ab (h : ab ∈ s), f ab = ∏ᶠ a b (h : b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd), f (a, b) := begin have : ∀ a, ∏ (i : β) in (s.filter (λ ab, prod.fst ab = a)).image prod.snd, f (a, i) = (finset.filter (λ ab, prod.fst ab = a) s).prod f, { refine (λ a, finset.prod_bij (λ b _, (a, b)) _ _ _ _); -- `finish` closes these goals try { simp, done }, suffices : ∀ a' b, (a', b) ∈ s → a' = a → (a, b) ∈ s ∧ a' = a, by simpa, rintros a' b hp rfl, exact ⟨hp, rfl⟩ }, rw finprod_mem_finset_eq_prod, simp_rw [finprod_mem_finset_eq_prod, this], rw [finprod_eq_prod_of_mul_support_subset _ (s.mul_support_of_fiberwise_prod_subset_image f prod.fst), ← finset.prod_fiberwise_of_maps_to _ f], -- `finish` could close the goal here simp only [finset.mem_image, prod.mk.eta], exact λ x hx, ⟨x, hx, rfl⟩, end /-- See also `finprod_mem_finset_product'`. -/ @[to_additive] lemma finprod_mem_finset_product (s : finset (α × β)) (f : α × β → M) : ∏ᶠ ab (h : ab ∈ s), f ab = ∏ᶠ a b (h : (a, b) ∈ s), f (a, b) := by { classical, rw finprod_mem_finset_product', simp, } @[to_additive] lemma finprod_mem_finset_product₃ {γ : Type*} (s : finset (α × β × γ)) (f : α × β × γ → M) : ∏ᶠ abc (h : abc ∈ s), f abc = ∏ᶠ a b c (h : (a, b, c) ∈ s), f (a, b, c) := by { classical, rw finprod_mem_finset_product', simp_rw finprod_mem_finset_product', simp, } @[to_additive] lemma finprod_curry (f : α × β → M) (hf : (mul_support f).finite) : ∏ᶠ ab, f ab = ∏ᶠ a b, f (a, b) := begin have h₁ : ∀ a, ∏ᶠ (h : a ∈ hf.to_finset), f a = f a, { simp, }, have h₂ : ∏ᶠ a, f a = ∏ᶠ a (h : a ∈ hf.to_finset), f a, { simp, }, simp_rw [h₂, finprod_mem_finset_product, h₁], end @[to_additive] lemma finprod_curry₃ {γ : Type*} (f : α × β × γ → M) (h : (mul_support f).finite) : ∏ᶠ abc, f abc = ∏ᶠ a b c, f (a, b, c) := by { rw finprod_curry f h, congr, ext a, rw finprod_curry, simp [h], } @[to_additive] lemma finprod_dmem {s : set α} [decidable_pred (∈ s)] (f : (Π (a : α), a ∈ s → M)) : ∏ᶠ (a : α) (h : a ∈ s), f a h = ∏ᶠ (a : α) (h : a ∈ s), if h' : a ∈ s then f a h' else 1 := finprod_congr (λ a, finprod_congr (λ ha, (dif_pos ha).symm)) @[to_additive] lemma finprod_emb_domain' {f : α → β} (hf : function.injective f) [decidable_pred (∈ set.range f)] (g : α → M) : ∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a := begin simp_rw [← finprod_eq_dif], rw [finprod_dmem, finprod_mem_range hf, finprod_congr (λ a, _)], rw [dif_pos (set.mem_range_self a), hf (classical.some_spec (set.mem_range_self a))] end @[to_additive] lemma finprod_emb_domain (f : α ↪ β) [decidable_pred (∈ set.range f)] (g : α → M) : ∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a := finprod_emb_domain' f.injective g end type
type Test a::Int b::Int showTest::Function function Test() self = new() self.a = 1 self.b = 2 self.showTest = function() self.a, self.b end return self end end t1 = Test() println(t1.showTest())
subroutine readmatrix(filename, colptr, rowind, nzvals) character*120 filename integer n, nnz integer colptr(*), rowind(*) real*8 nzvals(*) integer funit funit = 22 open(unit=funit,file=filename,form='unformatted') read(funit) n, nnz read(funit) (colptr(i), i = 1, n+1) read(funit) (rowind(i), i = 1, nnz) read(funit) (nzvals(i), i = 1, nnz) close(unit=funit) end subroutine
Formal statement is: lemma is_interval_cball_1[intro, simp]: "is_interval (cball a b)" for a b::real Informal statement is: The closed ball is an interval.
State Before: p : ℕ w : 1 < p ⊢ LucasLehmerTest p → Nat.Prime (mersenne p) State After: p : ℕ w : 1 < p p' : ℕ := p - 2 ⊢ LucasLehmerTest p → Nat.Prime (mersenne p) Tactic: let p' := p - 2 State Before: p : ℕ w : 1 < p p' : ℕ := p - 2 ⊢ LucasLehmerTest p → Nat.Prime (mersenne p) State After: p : ℕ w : 1 < p p' : ℕ := p - 2 z : p = p' + 2 ⊢ LucasLehmerTest p → Nat.Prime (mersenne p) Tactic: have z : p = p' + 2 := (tsub_eq_iff_eq_add_of_le w.nat_succ_le).mp rfl State Before: p : ℕ w : 1 < p p' : ℕ := p - 2 z : p = p' + 2 ⊢ LucasLehmerTest p → Nat.Prime (mersenne p) State After: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 ⊢ LucasLehmerTest p → Nat.Prime (mersenne p) Tactic: have w : 1 < p' + 2 := Nat.lt_of_sub_eq_succ rfl State Before: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 ⊢ LucasLehmerTest p → Nat.Prime (mersenne p) State After: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 ⊢ ¬Nat.Prime (mersenne p) → ¬LucasLehmerTest p Tactic: contrapose State Before: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 ⊢ ¬Nat.Prime (mersenne p) → ¬LucasLehmerTest p State After: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne p) t : LucasLehmerTest p ⊢ False Tactic: intro a t State Before: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne p) t : LucasLehmerTest p ⊢ False State After: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest p ⊢ False Tactic: rw [z] at a State Before: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest p ⊢ False State After: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest (p' + 2) ⊢ False Tactic: rw [z] at t State Before: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest (p' + 2) ⊢ False State After: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest (p' + 2) h₁ : 2 ^ (p' + 2) < ↑(q (p' + 2)) ^ 2 ⊢ False Tactic: have h₁ := order_ineq p' t State Before: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest (p' + 2) h₁ : 2 ^ (p' + 2) < ↑(q (p' + 2)) ^ 2 ⊢ False State After: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest (p' + 2) h₁ : 2 ^ (p' + 2) < ↑(q (p' + 2)) ^ 2 h₂ : Nat.minFac (mersenne (p' + 2)) ^ 2 ≤ mersenne (p' + 2) ⊢ False Tactic: have h₂ := Nat.minFac_sq_le_self (mersenne_pos (Nat.lt_of_succ_lt w)) a State Before: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest (p' + 2) h₁ : 2 ^ (p' + 2) < ↑(q (p' + 2)) ^ 2 h₂ : Nat.minFac (mersenne (p' + 2)) ^ 2 ≤ mersenne (p' + 2) ⊢ False State After: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest (p' + 2) h₁ : 2 ^ (p' + 2) < ↑(q (p' + 2)) ^ 2 h₂ : Nat.minFac (mersenne (p' + 2)) ^ 2 ≤ mersenne (p' + 2) h : 2 ^ (p' + 2) < mersenne (p' + 2) ⊢ False Tactic: have h := lt_of_lt_of_le h₁ h₂ State Before: p : ℕ w✝ : 1 < p p' : ℕ := p - 2 z : p = p' + 2 w : 1 < p' + 2 a : ¬Nat.Prime (mersenne (p' + 2)) t : LucasLehmerTest (p' + 2) h₁ : 2 ^ (p' + 2) < ↑(q (p' + 2)) ^ 2 h₂ : Nat.minFac (mersenne (p' + 2)) ^ 2 ≤ mersenne (p' + 2) h : 2 ^ (p' + 2) < mersenne (p' + 2) ⊢ False State After: no goals Tactic: exact not_lt_of_ge (Nat.sub_le _ _) h
module _ {T : Type{ℓₒ}} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where instance PredSet-setLike : SetLike{C = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_) SetLike._⊆_ PredSet-setLike = _⊆_ SetLike._≡_ PredSet-setLike = _≡_ SetLike.[⊆]-membership PredSet-setLike = [↔]-intro intro _⊆_.proof SetLike.[≡]-membership PredSet-setLike = [↔]-intro intro _≡_.proof instance PredSet-emptySet : SetLike.EmptySet{C = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_) SetLike.EmptySet.∅ PredSet-emptySet = ∅ SetLike.EmptySet.membership PredSet-emptySet () instance PredSet-universalSet : SetLike.UniversalSet{C = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_) SetLike.UniversalSet.𝐔 PredSet-universalSet = 𝐔 SetLike.UniversalSet.membership PredSet-universalSet = record {} instance PredSet-unionOperator : SetLike.UnionOperator{C = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_) SetLike.UnionOperator._∪_ PredSet-unionOperator = _∪_ SetLike.UnionOperator.membership PredSet-unionOperator = [↔]-intro id id instance PredSet-intersectionOperator : SetLike.IntersectionOperator{C = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_) SetLike.IntersectionOperator._∩_ PredSet-intersectionOperator = _∩_ SetLike.IntersectionOperator.membership PredSet-intersectionOperator = [↔]-intro id id instance PredSet-complementOperator : SetLike.ComplementOperator{C = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_) SetLike.ComplementOperator.∁ PredSet-complementOperator = ∁_ SetLike.ComplementOperator.membership PredSet-complementOperator = [↔]-intro id id module _ {T : Type{ℓ}} ⦃ equiv : Equiv{ℓ}(T) ⦄ where -- TODO: Levels in SetLike instance PredSet-mapFunction : SetLike.MapFunction{C₁ = PredSet{ℓ}(T) ⦃ equiv ⦄}{C₂ = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_)(_∈_) SetLike.MapFunction.map PredSet-mapFunction f = map f SetLike.MapFunction.membership PredSet-mapFunction = [↔]-intro id id instance PredSet-unmapFunction : SetLike.UnmapFunction{C₁ = PredSet{ℓ}(T) ⦃ equiv ⦄}{C₂ = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_)(_∈_) SetLike.UnmapFunction.unmap PredSet-unmapFunction = unmap SetLike.UnmapFunction.membership PredSet-unmapFunction = [↔]-intro id id instance PredSet-unapplyFunction : SetLike.UnapplyFunction{C = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_) {O = T} SetLike.UnapplyFunction.unapply PredSet-unapplyFunction = unapply SetLike.UnapplyFunction.membership PredSet-unapplyFunction = [↔]-intro id id instance PredSet-filterFunction : SetLike.FilterFunction{C = PredSet{ℓ}(T) ⦃ equiv ⦄} (_∈_) {ℓ}{ℓ} SetLike.FilterFunction.filter PredSet-filterFunction = filter SetLike.FilterFunction.membership PredSet-filterFunction = [↔]-intro id id {- TODO: SetLike is not general enough module _ {T : Type{ℓ}} ⦃ equiv : Equiv{ℓ}(T) ⦄ where instance -- PredSet-bigUnionOperator : SetLike.BigUnionOperator{Cₒ = PredSet(PredSet(T) ⦃ {!!} ⦄) ⦃ {!!} ⦄} {Cᵢ = PredSet(T) ⦃ {!!} ⦄} (_∈_)(_∈_) SetLike.BigUnionOperator.⋃ PredSet-bigUnionOperator = {!⋃!} SetLike.BigUnionOperator.membership PredSet-bigUnionOperator = {!!} -}
G05KFJ Example Program Results 0.6364 0.1065 0.7460 0.7983 0.1046
[GOAL] A : Mon_ (Type u) x y z : A.X ⊢ x * y * z = x * (y * z) [PROOFSTEP] convert congr_fun A.mul_assoc ((x, y), z) [GOAL] A : Mon_ (Type u) x : A.X ⊢ 1 * x = x [PROOFSTEP] convert congr_fun A.one_mul (PUnit.unit, x) [GOAL] A : Mon_ (Type u) x : A.X ⊢ x * 1 = x [PROOFSTEP] convert congr_fun A.mul_one (x, PUnit.unit) [GOAL] A : MonCat ⊢ (MonoidalCategory.tensorHom (fun x => 1) (𝟙 ↑A) ≫ fun p => p.fst * p.snd) = (MonoidalCategory.leftUnitor ↑A).hom [PROOFSTEP] ext ⟨_, _⟩ [GOAL] case h.mk A : MonCat fst✝ : MonoidalCategory.tensorUnit (Type u) snd✝ : ↑A ⊢ (MonoidalCategory.tensorHom (fun x => 1) (𝟙 ↑A) ≫ fun p => p.fst * p.snd) (fst✝, snd✝) = (MonoidalCategory.leftUnitor ↑A).hom (fst✝, snd✝) [PROOFSTEP] dsimp [GOAL] case h.mk A : MonCat fst✝ : MonoidalCategory.tensorUnit (Type u) snd✝ : ↑A ⊢ 1 * snd✝ = snd✝ [PROOFSTEP] simp [GOAL] A : MonCat ⊢ ((MonoidalCategory.tensorHom (𝟙 ↑A) fun x => 1) ≫ fun p => p.fst * p.snd) = (MonoidalCategory.rightUnitor ↑A).hom [PROOFSTEP] ext ⟨_, _⟩ [GOAL] case h.mk A : MonCat fst✝ : ↑A snd✝ : MonoidalCategory.tensorUnit (Type u) ⊢ ((MonoidalCategory.tensorHom (𝟙 ↑A) fun x => 1) ≫ fun p => p.fst * p.snd) (fst✝, snd✝) = (MonoidalCategory.rightUnitor ↑A).hom (fst✝, snd✝) [PROOFSTEP] dsimp [GOAL] case h.mk A : MonCat fst✝ : ↑A snd✝ : MonoidalCategory.tensorUnit (Type u) ⊢ fst✝ * 1 = fst✝ [PROOFSTEP] simp [GOAL] A : MonCat ⊢ (MonoidalCategory.tensorHom (fun p => p.fst * p.snd) (𝟙 ↑A) ≫ fun p => p.fst * p.snd) = (MonoidalCategory.associator ↑A ↑A ↑A).hom ≫ (MonoidalCategory.tensorHom (𝟙 ↑A) fun p => p.fst * p.snd) ≫ fun p => p.fst * p.snd [PROOFSTEP] ext ⟨⟨x, y⟩, z⟩ [GOAL] case h.mk.mk A : MonCat z x y : ↑A ⊢ (MonoidalCategory.tensorHom (fun p => p.fst * p.snd) (𝟙 ↑A) ≫ fun p => p.fst * p.snd) ((x, y), z) = ((MonoidalCategory.associator ↑A ↑A ↑A).hom ≫ (MonoidalCategory.tensorHom (𝟙 ↑A) fun p => p.fst * p.snd) ≫ fun p => p.fst * p.snd) ((x, y), z) [PROOFSTEP] simp [mul_assoc] [GOAL] ⊢ ∀ {X Y : Mon_ (Type u)} (f : X ⟶ Y), (𝟭 (Mon_ (Type u))).map f ≫ ((fun A => Iso.mk (Mon_.Hom.mk (𝟙 ((𝟭 (Mon_ (Type u))).obj A).X)) (Mon_.Hom.mk (𝟙 ((functor ⋙ inverse).obj A).X))) Y).hom = ((fun A => Iso.mk (Mon_.Hom.mk (𝟙 ((𝟭 (Mon_ (Type u))).obj A).X)) (Mon_.Hom.mk (𝟙 ((functor ⋙ inverse).obj A).X))) X).hom ≫ (functor ⋙ inverse).map f [PROOFSTEP] aesop_cat [GOAL] ⊢ ∀ {X Y : MonCat} (f : X ⟶ Y), (inverse ⋙ functor).map f ≫ ((fun A => Iso.mk { toOneHom := { toFun := id, map_one' := (_ : id 1 = id 1) }, map_mul' := (_ : ∀ (x y : ↑((inverse ⋙ functor).obj A)), OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y) = OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y)) } { toOneHom := { toFun := id, map_one' := (_ : id 1 = id 1) }, map_mul' := (_ : ∀ (x y : ↑((𝟭 MonCat).obj A)), OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y) = OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y)) }) Y).hom = ((fun A => Iso.mk { toOneHom := { toFun := id, map_one' := (_ : id 1 = id 1) }, map_mul' := (_ : ∀ (x y : ↑((inverse ⋙ functor).obj A)), OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y) = OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y)) } { toOneHom := { toFun := id, map_one' := (_ : id 1 = id 1) }, map_mul' := (_ : ∀ (x y : ↑((𝟭 MonCat).obj A)), OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y) = OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y)) }) X).hom ≫ (𝟭 MonCat).map f [PROOFSTEP] aesop_cat [GOAL] ⊢ ∀ {X Y : Mon_ (Type u)} (f : X ⟶ Y), (functor ⋙ forget MonCat).map f ≫ ((fun A => Iso.refl ((functor ⋙ forget MonCat).obj A)) Y).hom = ((fun A => Iso.refl ((functor ⋙ forget MonCat).obj A)) X).hom ≫ (Mon_.forget (Type u)).map f [PROOFSTEP] aesop_cat [GOAL] A : CommMon_ (Type u) src✝ : Monoid A.X := monMonoid A.toMon_ x y : A.X ⊢ x * y = y * x [PROOFSTEP] convert congr_fun A.mul_comm (y, x) [GOAL] A : CommMonCat src✝ : Mon_ (Type u) := MonTypeEquivalenceMon.inverse.obj ((forget₂ CommMonCat MonCat).obj A) ⊢ (β_ (Mon_.mk src✝.X src✝.one src✝.mul).X (Mon_.mk src✝.X src✝.one src✝.mul).X).hom ≫ (Mon_.mk src✝.X src✝.one src✝.mul).mul = (Mon_.mk src✝.X src✝.one src✝.mul).mul [PROOFSTEP] ext ⟨x : A, y : A⟩ [GOAL] case h.mk A : CommMonCat src✝ : Mon_ (Type u) := MonTypeEquivalenceMon.inverse.obj ((forget₂ CommMonCat MonCat).obj A) x y : ↑A ⊢ ((β_ (Mon_.mk src✝.X src✝.one src✝.mul).X (Mon_.mk src✝.X src✝.one src✝.mul).X).hom ≫ (Mon_.mk src✝.X src✝.one src✝.mul).mul) (x, y) = Mon_.mul (Mon_.mk src✝.X src✝.one src✝.mul) (x, y) [PROOFSTEP] exact CommMonoid.mul_comm y x [GOAL] ⊢ ∀ {X Y : CommMon_ (Type u)} (f : X ⟶ Y), (𝟭 (CommMon_ (Type u))).map f ≫ ((fun A => Iso.mk (Mon_.Hom.mk (𝟙 ((𝟭 (CommMon_ (Type u))).obj A).X)) (Mon_.Hom.mk (𝟙 ((CommMonTypeEquivalenceCommMon.functor ⋙ CommMonTypeEquivalenceCommMon.inverse).obj A).X))) Y).hom = ((fun A => Iso.mk (Mon_.Hom.mk (𝟙 ((𝟭 (CommMon_ (Type u))).obj A).X)) (Mon_.Hom.mk (𝟙 ((CommMonTypeEquivalenceCommMon.functor ⋙ CommMonTypeEquivalenceCommMon.inverse).obj A).X))) X).hom ≫ (CommMonTypeEquivalenceCommMon.functor ⋙ CommMonTypeEquivalenceCommMon.inverse).map f [PROOFSTEP] aesop_cat [GOAL] ⊢ ∀ {X Y : CommMonCat} (f : X ⟶ Y), (CommMonTypeEquivalenceCommMon.inverse ⋙ CommMonTypeEquivalenceCommMon.functor).map f ≫ ((fun A => Iso.mk { toOneHom := { toFun := id, map_one' := (_ : id 1 = id 1) }, map_mul' := (_ : ∀ (x y : ↑((CommMonTypeEquivalenceCommMon.inverse ⋙ CommMonTypeEquivalenceCommMon.functor).obj A)), OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y) = OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y)) } { toOneHom := { toFun := id, map_one' := (_ : id 1 = id 1) }, map_mul' := (_ : ∀ (x y : ↑((𝟭 CommMonCat).obj A)), OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y) = OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y)) }) Y).hom = ((fun A => Iso.mk { toOneHom := { toFun := id, map_one' := (_ : id 1 = id 1) }, map_mul' := (_ : ∀ (x y : ↑((CommMonTypeEquivalenceCommMon.inverse ⋙ CommMonTypeEquivalenceCommMon.functor).obj A)), OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y) = OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y)) } { toOneHom := { toFun := id, map_one' := (_ : id 1 = id 1) }, map_mul' := (_ : ∀ (x y : ↑((𝟭 CommMonCat).obj A)), OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y) = OneHom.toFun { toFun := id, map_one' := (_ : id 1 = id 1) } (x * y)) }) X).hom ≫ (𝟭 CommMonCat).map f [PROOFSTEP] aesop_cat [GOAL] ⊢ ∀ {X Y : CommMon_ (Type u)} (f : X ⟶ Y), (CommMonTypeEquivalenceCommMon.functor ⋙ forget₂ CommMonCat MonCat).map f ≫ ((fun A => Iso.refl ((CommMonTypeEquivalenceCommMon.functor ⋙ forget₂ CommMonCat MonCat).obj A)) Y).hom = ((fun A => Iso.refl ((CommMonTypeEquivalenceCommMon.functor ⋙ forget₂ CommMonCat MonCat).obj A)) X).hom ≫ (CommMon_.forget₂Mon_ (Type u) ⋙ MonTypeEquivalenceMon.functor).map f [PROOFSTEP] aesop_cat
State Before: ι : Type ?u.228451 α : Type u β : Type v γ : Type w δ : Type x l₁ l₂ : List α f g : α → β → α a : α l : List β H : ∀ (a : α) (b : β), b ∈ l → f a b = g a b ⊢ foldl f a l = foldl g a l State After: no goals Tactic: induction l generalizing a with | nil => rfl | cons hd tl ih => unfold foldl rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd (mem_cons_self _ _)] State Before: case nil ι : Type ?u.228451 α : Type u β : Type v γ : Type w δ : Type x l₁ l₂ : List α f g : α → β → α a : α H : ∀ (a : α) (b : β), b ∈ [] → f a b = g a b ⊢ foldl f a [] = foldl g a [] State After: no goals Tactic: rfl State Before: case cons ι : Type ?u.228451 α : Type u β : Type v γ : Type w δ : Type x l₁ l₂ : List α f g : α → β → α hd : β tl : List β ih : ∀ (a : α), (∀ (a : α) (b : β), b ∈ tl → f a b = g a b) → foldl f a tl = foldl g a tl a : α H : ∀ (a : α) (b : β), b ∈ hd :: tl → f a b = g a b ⊢ foldl f a (hd :: tl) = foldl g a (hd :: tl) State After: case cons ι : Type ?u.228451 α : Type u β : Type v γ : Type w δ : Type x l₁ l₂ : List α f g : α → β → α hd : β tl : List β ih : ∀ (a : α), (∀ (a : α) (b : β), b ∈ tl → f a b = g a b) → foldl f a tl = foldl g a tl a : α H : ∀ (a : α) (b : β), b ∈ hd :: tl → f a b = g a b ⊢ foldl f (f a hd) tl = foldl g (g a hd) tl Tactic: unfold foldl State Before: case cons ι : Type ?u.228451 α : Type u β : Type v γ : Type w δ : Type x l₁ l₂ : List α f g : α → β → α hd : β tl : List β ih : ∀ (a : α), (∀ (a : α) (b : β), b ∈ tl → f a b = g a b) → foldl f a tl = foldl g a tl a : α H : ∀ (a : α) (b : β), b ∈ hd :: tl → f a b = g a b ⊢ foldl f (f a hd) tl = foldl g (g a hd) tl State After: no goals Tactic: rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd (mem_cons_self _ _)]
State Before: ι : Type u_1 inst✝ : Fintype ι a b : ι → ℝ h : a ≤ b ⊢ ENNReal.toReal (↑↑volume (Set.pi univ fun i => Ioc (a i) (b i))) = ∏ i : ι, (b i - a i) State After: no goals Tactic: simp only [volume_pi_Ioc, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))]
# Euler1 in R #Set recursion limit options(expressions = 10000) myInt <- function(n) ifelse (n%%3 == 0 || n%%5 == 0, n, 0) euler <- function(n, acc) { ifelse (n == 0, acc, euler(n-1, myInt(n)+acc)) } euler1 <- function(n) euler(n, 0) euler1(999)
\documentclass{beamer} \usepackage{beamerthemevictor,comment,verbatim,graphicx,amssymb} \input{tutmacs} \input{slidemacs} \input idxmacs \begin{document} \title{Dynamic Programming} \author{Victor Eijkhout} \date{Notes for CS 594 -- Fall 2004} \frame{\titlepage} \section{Introduction} \frame[containsverbatim]{ \frametitle{What is dynamic programming?} \begin{itemize} \item Solution technique for minization problems \item Often lower complexity than naive techniques \item Sometimes equivalent to analytical techniques \end{itemize} } \frame[containsverbatim]{ \frametitle{What is it \emph{not}?} \begin{itemize} \item Black box that will solve your problem \item Way of finding lowest complexity \end{itemize} } \frame[containsverbatim]{ \frametitle{When dynamic programming?} \begin{itemize} \item Minimization problems \item constraints; especially integer \item sequence of decisions \end{itemize} } \section{Examples} \subsectionframe{Decision timing} \frame[containsverbatim]{ \frametitle{Description} \begin{itemize} \item Occasions for deciding yes/no \item items with attractiveness $\in[0,1]$ \item Finite set \item no reconsidering \item Question: at any given step, do you choose or pass? \item Objective: maximize expectation \end{itemize} } \frame{ \frametitle{crucial idea} \begin{itemize} \item start from the end: \item step $N$: no choice left \item expected yield: $.5$ \item<2-> in step $N-1$: pick if better than $.5$ \end{itemize} } \frame{ \frametitle{yield from $N-1$} \begin{itemize} \item pick if $>.5$: done in $.5$ of the cases \item<2-> expected yield $.75$ \item<3-> go on in $.5$ of the cases \item<4-> expected yield then $.5$ \item<5-> total expected yield: $.5\times.75+.5\times.5=.625$ \end{itemize} } \frame{ \frametitle{at $N-2$} \begin{itemize} \item pick if better than $.625$ \item<2-> happens in $.375$ of the cases, \item<3-> yield in that case $1.625/2$ \item<4-> otherwise, $.625$ yield from later choice \item<4-> et cetera \end{itemize} } \frame[containsverbatim]{ \frametitle{Essential features} \begin{itemize} \item Stages: more or less independent decisions \item Global minimization; solving by subproblems \item Principle of optimality: sub part of total solution is optimal solution of sub problem \end{itemize} } \subsectionframe{Manufacturing problem} \frame{ \frametitle{Statement} \begin{itemize} \item Total to be produced in given time, variable cost in each time period \item wanted: scheduling \item \[ \min_{\sum p_k=S}\sum w_kp_k^2.\] \end{itemize} } \frame[containsverbatim]{ \frametitle{define concepts} \begin{itemize} \item amount of work to produce~$s$ in $n$~steps: \[ v(s|n)=\min_{\sum_{k>N-n} p_k=s}\sum w_kp_k^2 \] \item optimal amount $p(s|n)$ at $n$~months from the end \end{itemize} } \frame[containsverbatim]{ \frametitle{principle of optimality} \begin{eqnarray*} v(s|n)&=&\min_{p_n\leq s}\left\{w_np_n^2 +\sum_{{k>N-n+1\atop\sum p_k=s-p_n}}w_kp_k^2\right\} \\ &=&\min_{p_n\leq s}\left\{ w_np_n^2+v(s-p_n|n-1)\right\} \end{eqnarray*} } \frame{ \frametitle{start from the end} \begin{itemize} \item In the last period: $p(s|1)=s$, and $v(s|1)=w_1s^2$ \item<2-> period before: \[ v(s|2)=\min_{p_2}\{w_2p_2^2+v(s-p_2|1)\}=\min_{p_2}c(s,p_2) \] where $c(s,p_2)=w_2p_2^2+w_1(s-p_2)^2$. \item<3-> Minimize: $\delta c(s,p_2)/\delta p_2=0$, \item<3-> then $p(s|2)=w_1s/(w_1+w_2)$ and $v(s|2)=w_1w_2s^2/(w_1+w_2)$. \end{itemize} } \frame{ \frametitle{general form} \begin{itemize} \item Inductively \[ p(s|n)={1/w_n\over \sum_{i=1}^n 1/w_i}s,\qquad v(s|n)=s^2\sum_{i=1}^n1/w_i.\] \item<2-> Variational approach: \[ \sum_kw_kp_k^2+\lambda(\sum_kp_k-S) \] Constrained minimization \item<3-> Solve by setting derivatives to $p_n$ and~$\lambda$ to zero. \end{itemize} } \frame{ \frametitle{characteristics} \begin{itemize} \item Stages: time periods \item State: amount of good left to be produced \item Principle of optimality \item<2-> Can be solved analytically \item<3-> Analytical approach can not deal with integer constraints \end{itemize} } \subsectionframe{Stagecoach problem} \frame[containsverbatim]{ \frametitle{Statement} Several routes from beginning to end\\ Cost of travel insurance: \convertMPtoPDF{stages.1}{1}{1} Objective: minimize cost } \frame[containsverbatim]{ \frametitle{data in python} \begin{verbatim} table = [ [0, 5, 4, 0, 0, 0, 0, 0, 0], # first stage: 0 [0, 0, 0, 1, 3, 4, 0, 0, 0], # second: 1 & #2 [0, 0, 0, 4, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 5, 1, 0], # third: 3, #4, #5 [0, 0, 0, 0, 0, 0, 2, 4, 0], [0, 0, 0, 0, 0, 0, 4, 3, 0], [0, 0, 0, 0, 0, 0, 0, 0, 5], # fourth: 6 & #7 [0, 0, 0, 0, 0, 0, 0, 0, 2] ] final = len(table); \end{verbatim} } \frame{ \frametitle{recursive formulation} \begin{itemize} \item In the final city, the cost is zero; \item Otherwise minimum over all cities reachable\\ of the cost of the next leg plus the minimum cost from that city.\\ (principle of optimality) \item<2-> wrong to code it recursively \end{itemize} } \frame[containsverbatim]{ \frametitle{recursive solution in python} \footnotesize \hypertarget{rec-coach}{} \begin{verbatim} def cost_from(n): # if you're at the end, it's free if n==final: return 0 # otherwise range over cities you can reach # and keep minimum value val = 0 for m in range(n+1,final+1): local_cost = table[n][m] if local_cost>0: # if there is a connection from here, # compute the minimum cost local_cost += cost_from(m) if val==0 or local_cost<val: val = local_cost return val print "recursive minimum cost is",cost_from(0) \end{verbatim} \hyperlink{back-coach}{\beamerbutton{backward}} } \frame[containsverbatim]{ \frametitle{characteristic} \begin{itemize} \item Overlapping subproblems\\ \convertMPtoPDF{123.1}{1}{1} \item \n{cost_from(1)} computed twice \item Cost: $N$~cities, $S$~stages of $L$~each: $O(L^S)$ \end{itemize} } \frame[containsverbatim]{ \frametitle{dynamic programming} \begin{itemize} \item Compute minimum cost $f_n(x_n)$\\ of traveling from step~$n$, starting in $x_n$ (state variable) \item Formally, $f_k(s)$ minimum cost for traveling from stage~$k$\\ starting in city~$s$. Then \[ f_{k-1}(s)=\min_t\{ c_{st}+f_k(t) \] where $c_{st}$ cost of traveling from city~$s$ to~$t$. \end{itemize} } \frame[containsverbatim]{ \frametitle{backward dynamic solution in python} \footnotesize \hypertarget{back-coach}{} \begin{verbatim} cost = (final+1)*[0] # initialization # compute cost backwards for t in range(final-1,-1,-1): # computing cost from t for i in range(final+1): local_cost = table[t][i] if local_cost==0: continue local_cost += cost[i] if cost[t]==0 or local_cost<cost[t]: cost[t] = local_cost print "minimum cost:",cost[0] \end{verbatim} \hyperlink{rec-coach}{\beamerbutton{recursive}} \hyperlink{forw-coach}{\beamerbutton{forward}} } \frame[containsverbatim]{ \frametitle{analysis} \begin{itemize} \item Running time $O(N\cdot L)$ or~$O(L^2S)$ \item compare $L^S$ for recursive \end{itemize} } \frame{ \frametitle{Forward solution} \begin{itemize} \item Backward: $f_n(x)$ cost from $x$ in $n$ steps to the end \item Forward: $f_n(x)$ cost in $n$ steps to $x$ \[ f_n(t) =\min_{s<t}\{c_{st}+f_{n-1}(s)\} \] \item sometimes more appropriate \item same complexity \end{itemize} } \frame[containsverbatim]{ \frametitle{forward dynamic solution in python} \footnotesize \hypertarget{forw-coach}{} \begin{verbatim} cost = (final+1)*[0] for t in range(final): for i in range(final+1): local_cost = table[t][i] if local_cost == 0: continue cost_to_here = cost[t] newcost = cost_to_here+local_cost if cost[i]==0 or newcost<cost[i]: cost[i] = newcost print "cost",cost[final] \end{verbatim} \hyperlink{back-coach}{\beamerbutton{backward}} } \subsectionframe{Traveling salesman} \frame{ \frametitle{Problem statement} \begin{itemize} \item Cities as stages? \item<2-> No ordering \item<3-> Stage $n$ : having $n$ cities left \item<4-> State: combination of cities to visit plus current city \item<4-> Cost formula to~0 (both start/end) \begin{eqnarray*} C(\{\,\},f)&=&a_{f0}\quad\hbox{for $f=1,2,3,\ldots$}\\ C(S,f)&=&\min_{m\in S}a_{fm}+\left[C(S-m,m)]\right] \end{eqnarray*} \end{itemize} } \frame[containsverbatim]{ \frametitle{backward implementation} \footnotesize \begin{verbatim} def shortest_path(start,through,lev): if len(through)==0: return table[start][0] l = 0 for dest in through: left = through[:]; left.remove(dest) ll = table[start][dest]+shortest_path(dest,left,lev+1) if l==0 or ll<l: l = ll return l to_visit = range(1,ntowns); s = shortest_path(0,to_visit,0) \end{verbatim} (recursive; need to be improved) } \sectionframe{Discussion} \frame[containsverbatim]{ \frametitle{Characteristics} \begin{description} \item[Stages] sequence of choices \item[Stepwise solution] solution by successive subproblems \item[State] cost function has a state parameter,\\ description of work left~\&c \item[Overlapping subproblems] \item[Principle of optimality] This is the property that the restriction of a global solution to a subset of the stages is also an optimal solution for that subproblem. \end{description} } \frame[containsverbatim]{ \frametitle{Principle of optimality} \begin{quote} An optimal policy has the property that whatever the initial state and initial decision are, the remaining decisions must be an optimal policy with regard to the state resulting from the first decision. \end{quote} } \frame[containsverbatim]{ \frametitle{derivation} Maximize~$\sum^N_ig_i(x_i)$ under~$\sum_ix_i=\nobreak X$, $x_i\geq0$\\ Call this~$f_N(X)$, then \begin{eqnarray*} f_N(X)&=&\max_{\sum_i^Nx_i=X}\sum_i^Ng_i(x_i)\\ &=&\max_{x_N<X}\left\{g_N(x_N)+\max_{\sum_i^{N-1}x_i=X-x_N}\sum_i^{N-1}g_i(x_i)\right\}\\ &=&\max_{x_N<X}\left\{g_N(x_N)+f_{N-1}(X-x_N)\right\} \end{eqnarray*} } \end{document}
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import geometry.euclidean.angle.sphere import geometry.euclidean.sphere.second_inter /-! # IMO 2019 Q2 In triangle `ABC`, point `A₁` lies on side `BC` and point `B₁` lies on side `AC`. Let `P` and `Q` be points on segments `AA₁` and `BB₁`, respectively, such that `PQ` is parallel to `AB`. Let `P₁` be a point on line `PB₁`, such that `B₁` lies strictly between `P` and `P₁`, and `∠PP₁C = ∠BAC`. Similarly, let `Q₁` be a point on line `QA₁`, such that `A₁` lies strictly between `Q` and `Q₁`, and `∠CQ₁Q = ∠CBA`. Prove that points `P`, `Q`, `P₁`, and `Q₁` are concyclic. We follow Solution 1 from the [official solutions](https://www.imo2019.uk/wp-content/uploads/2018/07/solutions-r856.pdf). Letting the rays `AA₁` and `BB₁` intersect the circumcircle of `ABC` at `A₂` and `B₂` respectively, we show with an angle chase that `P`, `Q`, `A₂`, `B₂` are concyclic and let `ω` be the circle through those points. We then show that `C`, `Q₁`, `A₂`, `A₁` are concyclic, and then that `Q₁` lies on `ω`, and similarly that `P₁` lies on `ω`, so the required four points are concyclic. Note that most of the formal proof is actually proving nondegeneracy conditions needed for that angle chase / concyclicity argument, where an informal solution doesn't discuss those conditions at all. Also note that (as described in `geometry.euclidean.angle.oriented.basic`) the oriented angles used are modulo `2 * π`, so parts of the angle chase that are only valid for angles modulo `π` (as used in the informal solution) are represented as equalities of twice angles, which we write as `(2 : ℤ) • ∡ _ _ _ = (2 : ℤ) • _ _ _`. -/ /-- We apply the following conventions for formalizing IMO geometry problems. A problem is assumed to take place in the plane unless that is clearly not intended, so it is not required to prove that the points are coplanar (whether or not that in fact follows from the other conditions). Angles in problem statements are taken to be unoriented. A reference to an angle `∠XYZ` is taken to imply that `X` and `Z` are not equal to `Y`, since choices of junk values play no role in informal mathematics, and those implications are included as hypotheses for the problem whether or not they follow from the other hypotheses. Similar, a reference to `XY` as a line is taken to imply that `X` does not equal `Y` and that is included as a hypothesis, and a reference to `XY` being parallel to something is considered a reference to it as a line. However, such an implicit hypothesis about two points being different is included only once for any given two points (even if it follows from more than one reference to a line or an angle), if `X ≠ Y` is included then `Y ≠ X` is not included separately, and such hypotheses are not included in the case where there is also a reference in the problem to a triangle including those two points, or to strict betweenness of three points including those two. If betweenness is stated, it is taken to be strict betweenness. However, segments and sides are taken to include their endpoints (unless this makes a problem false), although those degenerate cases might not necessarily have been considered when the problem was formulated and contestants might not have been expected to deal with them. A reference to a point being on a side or a segment is expressed directly with `wbtw` rather than more literally with `affine_segment`. -/ library_note "IMO geometry formalization conventions" noncomputable theory open affine affine.simplex euclidean_geometry finite_dimensional open_locale affine euclidean_geometry real local attribute [instance] fact_finite_dimensional_of_finrank_eq_succ variables (V : Type*) (Pt : Type*) variables [normed_add_comm_group V] [inner_product_space ℝ V] [metric_space Pt] variables [normed_add_torsor V Pt] [hd2 : fact (finrank ℝ V = 2)] include hd2 /-- A configuration satisfying the conditions of the problem. We define this structure to avoid passing many hypotheses around as we build up information about the configuration; the final result for a statement of the problem not using this structure is then deduced from one in terms of this structure. -/ @[nolint has_nonempty_instance] structure imo2019q2_cfg := (A B C A₁ B₁ P Q P₁ Q₁ : Pt) (affine_independent_ABC : affine_independent ℝ ![A, B, C]) (wbtw_B_A₁_C : wbtw ℝ B A₁ C) (wbtw_A_B₁_C : wbtw ℝ A B₁ C) (wbtw_A_P_A₁ : wbtw ℝ A P A₁) (wbtw_B_Q_B₁ : wbtw ℝ B Q B₁) (PQ_parallel_AB : line[ℝ, P, Q] ∥ line[ℝ, A, B]) -- A hypothesis implicit in the named line. (P_ne_Q : P ≠ Q) (sbtw_P_B₁_P₁ : sbtw ℝ P B₁ P₁) (angle_PP₁C_eq_angle_BAC : ∠ P P₁ C = ∠ B A C) -- A hypothesis implicit in the first named angle. (C_ne_P₁ : C ≠ P₁) (sbtw_Q_A₁_Q₁ : sbtw ℝ Q A₁ Q₁) (angle_CQ₁Q_eq_angle_CBA : ∠ C Q₁ Q = ∠ C B A) -- A hypothesis implicit in the first named angle. (C_ne_Q₁ : C ≠ Q₁) /-- A default choice of orientation, for lemmas that need to pick one. -/ def some_orientation : module.oriented ℝ V (fin 2) := ⟨basis.orientation (fin_basis_of_finrank_eq _ _ hd2.out)⟩ variables {V Pt} namespace imo2019q2_cfg variables (cfg : imo2019q2_cfg V Pt) /-- The configuration has symmetry, allowing results proved for one point to be applied for another (where the informal solution says "similarly"). -/ def symm : imo2019q2_cfg V Pt := { A := cfg.B, B := cfg.A, C := cfg.C, A₁ := cfg.B₁, B₁ := cfg.A₁, P := cfg.Q, Q := cfg.P, P₁ := cfg.Q₁, Q₁ := cfg.P₁, affine_independent_ABC := begin rw ←affine_independent_equiv (equiv.swap (0 : fin 3) 1), convert cfg.affine_independent_ABC using 1, ext x, fin_cases x; refl end, wbtw_B_A₁_C := cfg.wbtw_A_B₁_C, wbtw_A_B₁_C := cfg.wbtw_B_A₁_C, wbtw_A_P_A₁ := cfg.wbtw_B_Q_B₁, wbtw_B_Q_B₁ := cfg.wbtw_A_P_A₁, PQ_parallel_AB := set.pair_comm cfg.P cfg.Q ▸ set.pair_comm cfg.A cfg.B ▸ cfg.PQ_parallel_AB, P_ne_Q := cfg.P_ne_Q.symm, sbtw_P_B₁_P₁ := cfg.sbtw_Q_A₁_Q₁, angle_PP₁C_eq_angle_BAC := angle_comm cfg.C cfg.Q₁ cfg.Q ▸ angle_comm cfg.C cfg.B cfg.A ▸ cfg.angle_CQ₁Q_eq_angle_CBA, C_ne_P₁ := cfg.C_ne_Q₁, sbtw_Q_A₁_Q₁ := cfg.sbtw_P_B₁_P₁, angle_CQ₁Q_eq_angle_CBA := angle_comm cfg.P cfg.P₁ cfg.C ▸ angle_comm cfg.B cfg.A cfg.C ▸ cfg.angle_PP₁C_eq_angle_BAC, C_ne_Q₁ := cfg.C_ne_P₁ } /-! ### Configuration properties that are obvious from the diagram, and construction of the points `A₂` and `B₂` -/ lemma A_ne_B : cfg.A ≠ cfg.B := cfg.affine_independent_ABC.injective.ne (dec_trivial : (0 : fin 3) ≠ 1) lemma A_ne_C : cfg.A ≠ cfg.C := cfg.affine_independent_ABC.injective.ne (dec_trivial : (0 : fin 3) ≠ 2) lemma B_ne_C : cfg.B ≠ cfg.C := cfg.affine_independent_ABC.injective.ne (dec_trivial : (1 : fin 3) ≠ 2) lemma not_collinear_ABC : ¬collinear ℝ ({cfg.A, cfg.B, cfg.C} : set Pt) := affine_independent_iff_not_collinear_set.1 cfg.affine_independent_ABC /-- `ABC` as a `triangle`. -/ def triangle_ABC : triangle ℝ Pt := ⟨_, cfg.affine_independent_ABC⟩ lemma A_mem_circumsphere : cfg.A ∈ cfg.triangle_ABC.circumsphere := cfg.triangle_ABC.mem_circumsphere 0 lemma B_mem_circumsphere : cfg.B ∈ cfg.triangle_ABC.circumsphere := cfg.triangle_ABC.mem_circumsphere 1 lemma C_mem_circumsphere : cfg.C ∈ cfg.triangle_ABC.circumsphere := cfg.triangle_ABC.mem_circumsphere 2 lemma symm_triangle_ABC : cfg.symm.triangle_ABC = cfg.triangle_ABC.reindex (equiv.swap 0 1) := by { ext i, fin_cases i; refl } lemma symm_triangle_ABC_circumsphere : cfg.symm.triangle_ABC.circumsphere = cfg.triangle_ABC.circumsphere := by rw [symm_triangle_ABC, affine.simplex.circumsphere_reindex] /-- `A₂` is the second point of intersection of the ray `AA₁` with the circumcircle of `ABC`. -/ def A₂ : Pt := cfg.triangle_ABC.circumsphere.second_inter cfg.A (cfg.A₁ -ᵥ cfg.A) /-- `B₂` is the second point of intersection of the ray `BB₁` with the circumcircle of `ABC`. -/ def B₂ : Pt := cfg.triangle_ABC.circumsphere.second_inter cfg.B (cfg.B₁ -ᵥ cfg.B) lemma A₂_mem_circumsphere : cfg.A₂ ∈ cfg.triangle_ABC.circumsphere := (sphere.second_inter_mem _).2 cfg.A_mem_circumsphere lemma B₂_mem_circumsphere : cfg.B₂ ∈ cfg.triangle_ABC.circumsphere := (sphere.second_inter_mem _).2 cfg.B_mem_circumsphere lemma symm_A₂ : cfg.symm.A₂ = cfg.B₂ := by { simp_rw [A₂, B₂, symm_triangle_ABC_circumsphere], refl } lemma QP_parallel_BA : line[ℝ, cfg.Q, cfg.P] ∥ line[ℝ, cfg.B, cfg.A] := by { rw [set.pair_comm cfg.Q, set.pair_comm cfg.B], exact cfg.PQ_parallel_AB } lemma A_ne_A₁ : cfg.A ≠ cfg.A₁ := begin intro h, have h' := cfg.not_collinear_ABC, rw [h, set.insert_comm] at h', exact h' cfg.wbtw_B_A₁_C.collinear end lemma collinear_PAA₁A₂ : collinear ℝ ({cfg.P, cfg.A, cfg.A₁, cfg.A₂} : set Pt) := begin rw [A₂, (cfg.triangle_ABC.circumsphere.second_inter_collinear cfg.A cfg.A₁).collinear_insert_iff_of_ne (set.mem_insert _ _) (set.mem_insert_of_mem _ (set.mem_insert _ _)) cfg.A_ne_A₁, set.insert_comm], exact cfg.wbtw_A_P_A₁.collinear end lemma A₁_ne_C : cfg.A₁ ≠ cfg.C := begin intro h, have hsbtw := cfg.sbtw_Q_A₁_Q₁, rw h at hsbtw, have ha := hsbtw.angle₂₃₁_eq_zero, rw [angle_CQ₁Q_eq_angle_CBA, angle_comm] at ha, exact (angle_ne_zero_of_not_collinear cfg.not_collinear_ABC) ha end lemma B₁_ne_C : cfg.B₁ ≠ cfg.C := cfg.symm.A₁_ne_C lemma Q_not_mem_CB : cfg.Q ∉ line[ℝ, cfg.C, cfg.B] := begin intro hQ, have hQA₁ : line[ℝ, cfg.Q, cfg.A₁] ≤ line[ℝ, cfg.C, cfg.B] := affine_span_pair_le_of_mem_of_mem hQ cfg.wbtw_B_A₁_C.symm.mem_affine_span, have hQ₁ : cfg.Q₁ ∈ line[ℝ, cfg.C, cfg.B], { rw affine_subspace.le_def' at hQA₁, exact hQA₁ _ cfg.sbtw_Q_A₁_Q₁.right_mem_affine_span }, have hc : collinear ℝ ({cfg.C, cfg.Q₁, cfg.Q} : set Pt), { have hc' : collinear ℝ ({cfg.B, cfg.C, cfg.Q₁, cfg.Q} : set Pt), { rw [set.insert_comm cfg.B, set.insert_comm cfg.B, set.pair_comm, set.insert_comm cfg.C, set.insert_comm cfg.C], exact collinear_insert_insert_of_mem_affine_span_pair hQ₁ hQ }, exact hc'.subset (set.subset_insert _ _) }, rw [collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi, cfg.angle_CQ₁Q_eq_angle_CBA, or_iff_right cfg.C_ne_Q₁, or_iff_right cfg.sbtw_Q_A₁_Q₁.left_ne_right, angle_comm] at hc, exact cfg.not_collinear_ABC (hc.elim collinear_of_angle_eq_zero collinear_of_angle_eq_pi) end lemma Q_ne_B : cfg.Q ≠ cfg.B := begin intro h, have h' := cfg.Q_not_mem_CB, rw h at h', exact h' (right_mem_affine_span_pair _ _ _) end lemma s_opp_side_CB_Q_Q₁ : line[ℝ, cfg.C, cfg.B].s_opp_side cfg.Q cfg.Q₁ := cfg.sbtw_Q_A₁_Q₁.s_opp_side_of_not_mem_of_mem cfg.Q_not_mem_CB cfg.wbtw_B_A₁_C.symm.mem_affine_span /-! ### Relate the orientations of different angles in the configuration -/ section oriented variables [module.oriented ℝ V (fin 2)] lemma oangle_CQ₁Q_sign_eq_oangle_CBA_sign : (∡ cfg.C cfg.Q₁ cfg.Q).sign = (∡ cfg.C cfg.B cfg.A).sign := by rw [←cfg.sbtw_Q_A₁_Q₁.symm.oangle_eq_right, cfg.s_opp_side_CB_Q_Q₁.oangle_sign_eq_neg (left_mem_affine_span_pair ℝ cfg.C cfg.B) cfg.wbtw_B_A₁_C.symm.mem_affine_span, ←real.angle.sign_neg, ←oangle_rev, cfg.wbtw_B_A₁_C.oangle_sign_eq_of_ne_right cfg.Q cfg.A₁_ne_C, oangle_rotate_sign, cfg.wbtw_B_Q_B₁.oangle_eq_right cfg.Q_ne_B, cfg.wbtw_A_B₁_C.symm.oangle_sign_eq_of_ne_left cfg.B cfg.B₁_ne_C.symm] lemma oangle_CQ₁Q_eq_oangle_CBA : ∡ cfg.C cfg.Q₁ cfg.Q = ∡ cfg.C cfg.B cfg.A := oangle_eq_of_angle_eq_of_sign_eq cfg.angle_CQ₁Q_eq_angle_CBA cfg.oangle_CQ₁Q_sign_eq_oangle_CBA_sign end oriented /-! ### More obvious configuration properties -/ lemma A₁_ne_B : cfg.A₁ ≠ cfg.B := begin intro h, have hwbtw := cfg.wbtw_A_P_A₁, rw h at hwbtw, have hPQ : line[ℝ, cfg.P, cfg.Q] = line[ℝ, cfg.A, cfg.B], { rw affine_subspace.eq_iff_direction_eq_of_mem (left_mem_affine_span_pair _ _ _) hwbtw.mem_affine_span, exact cfg.PQ_parallel_AB.direction_eq }, haveI := some_orientation V, have haQ : (2 : ℤ) • ∡ cfg.C cfg.B cfg.Q = (2 : ℤ) • ∡ cfg.C cfg.B cfg.A, { rw [collinear.two_zsmul_oangle_eq_right _ cfg.A_ne_B cfg.Q_ne_B], rw [set.pair_comm, set.insert_comm], refine collinear_insert_of_mem_affine_span_pair _, rw ←hPQ, exact right_mem_affine_span_pair _ _ _ }, have ha : (2 : ℤ) • ∡ cfg.C cfg.B cfg.Q = (2 : ℤ) • ∡ cfg.C cfg.Q₁ cfg.Q, { rw [oangle_CQ₁Q_eq_oangle_CBA, haQ] }, have hn : ¬collinear ℝ ({cfg.C, cfg.B, cfg.Q} : set Pt), { rw [collinear_iff_of_two_zsmul_oangle_eq haQ, set.pair_comm, set.insert_comm, set.pair_comm], exact cfg.not_collinear_ABC }, have hc := cospherical_of_two_zsmul_oangle_eq_of_not_collinear ha hn, have hBQ₁ : cfg.B ≠ cfg.Q₁, { rw [←h], exact cfg.sbtw_Q_A₁_Q₁.ne_right }, have hQQ₁ : cfg.Q ≠ cfg.Q₁ := cfg.sbtw_Q_A₁_Q₁.left_ne_right, have hBQ₁Q : affine_independent ℝ ![cfg.B, cfg.Q₁, cfg.Q] := hc.affine_independent_of_mem_of_ne (set.mem_insert_of_mem _ (set.mem_insert _ _)) (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert _ _))) (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_singleton _)))) hBQ₁ cfg.Q_ne_B.symm hQQ₁.symm, rw affine_independent_iff_not_collinear_set at hBQ₁Q, refine hBQ₁Q _, rw [←h, set.pair_comm, set.insert_comm], exact cfg.sbtw_Q_A₁_Q₁.wbtw.collinear end lemma sbtw_B_A₁_C : sbtw ℝ cfg.B cfg.A₁ cfg.C := ⟨cfg.wbtw_B_A₁_C, cfg.A₁_ne_B, cfg.A₁_ne_C⟩ lemma sbtw_A_B₁_C : sbtw ℝ cfg.A cfg.B₁ cfg.C := cfg.symm.sbtw_B_A₁_C lemma sbtw_A_A₁_A₂ : sbtw ℝ cfg.A cfg.A₁ cfg.A₂ := begin refine sphere.sbtw_second_inter cfg.A_mem_circumsphere _, convert cfg.sbtw_B_A₁_C.dist_lt_max_dist _, change _ = max (dist (cfg.triangle_ABC.points 1) _) (dist (cfg.triangle_ABC.points 2) _), simp_rw [circumsphere_center, circumsphere_radius, dist_circumcenter_eq_circumradius, max_self] end lemma sbtw_B_B₁_B₂ : sbtw ℝ cfg.B cfg.B₁ cfg.B₂ := by { rw ←cfg.symm_A₂, exact cfg.symm.sbtw_A_A₁_A₂ } lemma A₂_ne_A : cfg.A₂ ≠ cfg.A := cfg.sbtw_A_A₁_A₂.left_ne_right.symm lemma A₂_ne_P : cfg.A₂ ≠ cfg.P := (cfg.sbtw_A_A₁_A₂.trans_wbtw_left_ne cfg.wbtw_A_P_A₁).symm lemma A₂_ne_B : cfg.A₂ ≠ cfg.B := begin intro h, have h₁ := cfg.sbtw_A_A₁_A₂, rw h at h₁, refine cfg.not_collinear_ABC _, have hc : collinear ℝ ({cfg.A, cfg.C, cfg.B, cfg.A₁} : set Pt) := collinear_insert_insert_of_mem_affine_span_pair h₁.left_mem_affine_span cfg.sbtw_B_A₁_C.right_mem_affine_span, refine hc.subset _, rw [set.pair_comm _ cfg.A₁, set.insert_comm _ cfg.A₁, set.insert_comm _ cfg.A₁, set.pair_comm], exact set.subset_insert _ _ end lemma A₂_ne_C : cfg.A₂ ≠ cfg.C := begin intro h, have h₁ := cfg.sbtw_A_A₁_A₂, rw h at h₁, refine cfg.not_collinear_ABC _, have hc : collinear ℝ ({cfg.A, cfg.B, cfg.C, cfg.A₁} : set Pt) := collinear_insert_insert_of_mem_affine_span_pair h₁.left_mem_affine_span cfg.sbtw_B_A₁_C.left_mem_affine_span, refine hc.subset (set.insert_subset_insert (set.insert_subset_insert _)), rw set.singleton_subset_iff, exact set.mem_insert _ _ end lemma B₂_ne_B : cfg.B₂ ≠ cfg.B := by { rw ←symm_A₂, exact cfg.symm.A₂_ne_A } lemma B₂_ne_Q : cfg.B₂ ≠ cfg.Q := by { rw ←symm_A₂, exact cfg.symm.A₂_ne_P } lemma B₂_ne_A₂ : cfg.B₂ ≠ cfg.A₂ := begin intro h, have hA : sbtw ℝ (cfg.triangle_ABC.points 1) cfg.A₁ (cfg.triangle_ABC.points 2) := cfg.sbtw_B_A₁_C, have hB : sbtw ℝ (cfg.triangle_ABC.points 0) cfg.B₁ (cfg.triangle_ABC.points 2) := cfg.sbtw_A_B₁_C, have hA' : cfg.A₂ ∈ line[ℝ, cfg.triangle_ABC.points 0, cfg.A₁] := sphere.second_inter_vsub_mem_affine_span _ _ _, have hB' : cfg.A₂ ∈ line[ℝ, cfg.triangle_ABC.points 1, cfg.B₁], { rw ←h, exact sphere.second_inter_vsub_mem_affine_span _ _ _ }, exact (sbtw_of_sbtw_of_sbtw_of_mem_affine_span_pair dec_trivial hA hB hA' hB').symm.not_rotate cfg.sbtw_A_A₁_A₂.wbtw end lemma wbtw_B_Q_B₂ : wbtw ℝ cfg.B cfg.Q cfg.B₂ := cfg.sbtw_B_B₁_B₂.wbtw.trans_left cfg.wbtw_B_Q_B₁ /-! ### The first equality in the first angle chase in the solution -/ section oriented variables [module.oriented ℝ V (fin 2)] lemma two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_BAA₂ : (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ = (2 : ℤ) • ∡ cfg.B cfg.A cfg.A₂ := begin refine two_zsmul_oangle_of_parallel cfg.QP_parallel_BA _, convert affine_subspace.parallel.refl _ using 1, rw [cfg.collinear_PAA₁A₂.affine_span_eq_of_ne (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_singleton _)))) (set.mem_insert_of_mem _ (set.mem_insert _ _)) cfg.A₂_ne_A, cfg.collinear_PAA₁A₂.affine_span_eq_of_ne (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_insert_of_mem _ (set.mem_singleton _)))) (set.mem_insert _ _) cfg.A₂_ne_P] end end oriented /-! ### More obvious configuration properties -/ lemma not_collinear_QPA₂ : ¬ collinear ℝ ({cfg.Q, cfg.P, cfg.A₂} : set Pt) := begin haveI := some_orientation V, rw [collinear_iff_of_two_zsmul_oangle_eq cfg.two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_BAA₂, ←affine_independent_iff_not_collinear_set], have h : cospherical ({cfg.B, cfg.A, cfg.A₂} : set Pt), { refine cfg.triangle_ABC.circumsphere.cospherical.subset _, simp [set.insert_subset, cfg.A_mem_circumsphere, cfg.B_mem_circumsphere, cfg.A₂_mem_circumsphere] }, exact h.affine_independent_of_ne cfg.A_ne_B.symm cfg.A₂_ne_B.symm cfg.A₂_ne_A.symm end lemma Q₁_ne_A₂ : cfg.Q₁ ≠ cfg.A₂ := begin intro h, have h₁ := cfg.sbtw_Q_A₁_Q₁, rw h at h₁, refine cfg.not_collinear_QPA₂ _, have hA₂ := cfg.sbtw_A_A₁_A₂.right_mem_affine_span, have hA₂A₁ : line[ℝ, cfg.A₂, cfg.A₁] ≤ line[ℝ, cfg.A, cfg.A₁] := affine_span_pair_le_of_left_mem hA₂, have hQ : cfg.Q ∈ line[ℝ, cfg.A, cfg.A₁], { rw affine_subspace.le_def' at hA₂A₁, exact hA₂A₁ _ h₁.left_mem_affine_span }, exact collinear_triple_of_mem_affine_span_pair hQ cfg.wbtw_A_P_A₁.mem_affine_span hA₂ end lemma affine_independent_QPA₂ : affine_independent ℝ ![cfg.Q, cfg.P, cfg.A₂] := affine_independent_iff_not_collinear_set.2 cfg.not_collinear_QPA₂ lemma affine_independent_PQB₂ : affine_independent ℝ ![cfg.P, cfg.Q, cfg.B₂] := by { rw ←symm_A₂, exact cfg.symm.affine_independent_QPA₂ } /-- `QPA₂` as a `triangle`. -/ def triangle_QPA₂ : triangle ℝ Pt := ⟨_, cfg.affine_independent_QPA₂⟩ /-- `PQB₂` as a `triangle`. -/ def triangle_PQB₂ : triangle ℝ Pt := ⟨_, cfg.affine_independent_PQB₂⟩ lemma symm_triangle_QPA₂ : cfg.symm.triangle_QPA₂ = cfg.triangle_PQB₂ := by { simp_rw [triangle_PQB₂, ←symm_A₂], ext i, fin_cases i; refl } /-- `ω` is the circle containing `Q`, `P` and `A₂`, which will be shown also to contain `B₂`, `P₁` and `Q₁`. -/ def ω : sphere Pt := cfg.triangle_QPA₂.circumsphere lemma P_mem_ω : cfg.P ∈ cfg.ω := cfg.triangle_QPA₂.mem_circumsphere 1 lemma Q_mem_ω : cfg.Q ∈ cfg.ω := cfg.triangle_QPA₂.mem_circumsphere 0 /-! ### The rest of the first angle chase in the solution -/ section oriented variables [module.oriented ℝ V (fin 2)] lemma two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_QB₂A₂ : (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ = (2 : ℤ) • ∡ cfg.Q cfg.B₂ cfg.A₂ := calc (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ = (2 : ℤ) • ∡ cfg.B cfg.A cfg.A₂ : cfg.two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_BAA₂ ... = (2 : ℤ) • ∡ cfg.B cfg.B₂ cfg.A₂ : sphere.two_zsmul_oangle_eq cfg.B_mem_circumsphere cfg.A_mem_circumsphere cfg.B₂_mem_circumsphere cfg.A₂_mem_circumsphere cfg.A_ne_B cfg.A₂_ne_A.symm cfg.B₂_ne_B cfg.B₂_ne_A₂ ... = (2 : ℤ) • ∡ cfg.Q cfg.B₂ cfg.A₂ : by rw cfg.wbtw_B_Q_B₂.symm.oangle_eq_left cfg.B₂_ne_Q.symm end oriented /-! ### Conclusions from that first angle chase -/ lemma cospherical_QPB₂A₂ : cospherical ({cfg.Q, cfg.P, cfg.B₂, cfg.A₂} : set Pt) := begin haveI := some_orientation V, exact cospherical_of_two_zsmul_oangle_eq_of_not_collinear cfg.two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_QB₂A₂ cfg.not_collinear_QPA₂ end lemma symm_ω_eq_triangle_PQB₂_circumsphere : cfg.symm.ω = cfg.triangle_PQB₂.circumsphere := by rw [ω, symm_triangle_QPA₂] lemma symm_ω : cfg.symm.ω = cfg.ω := begin rw [symm_ω_eq_triangle_PQB₂_circumsphere, ω], refine circumsphere_eq_of_cospherical hd2.out cfg.cospherical_QPB₂A₂ _ _, { simp only [triangle_PQB₂, matrix.range_cons, matrix.range_empty, set.singleton_union, insert_emptyc_eq], rw set.insert_comm, refine set.insert_subset_insert (set.insert_subset_insert _), simp }, { simp only [triangle_QPA₂, matrix.range_cons, matrix.range_empty, set.singleton_union, insert_emptyc_eq], refine set.insert_subset_insert (set.insert_subset_insert _), simp } end /-! ### The second angle chase in the solution -/ section oriented variables [module.oriented ℝ V (fin 2)] lemma two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CBA : (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A₁ = (2 : ℤ) • ∡ cfg.C cfg.B cfg.A := calc (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A₁ = (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A : by rw cfg.sbtw_A_A₁_A₂.symm.oangle_eq_right ... = (2 : ℤ) • ∡ cfg.C cfg.B cfg.A : sphere.two_zsmul_oangle_eq cfg.C_mem_circumsphere cfg.A₂_mem_circumsphere cfg.B_mem_circumsphere cfg.A_mem_circumsphere cfg.A₂_ne_C cfg.A₂_ne_A cfg.B_ne_C cfg.A_ne_B.symm lemma two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CQ₁A₁ : (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A₁ = (2 : ℤ) • ∡ cfg.C cfg.Q₁ cfg.A₁ := calc (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A₁ = (2 : ℤ) • ∡ cfg.C cfg.B cfg.A : cfg.two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CBA ... = (2 : ℤ) • ∡ cfg.C cfg.Q₁ cfg.Q : by rw oangle_CQ₁Q_eq_oangle_CBA ... = (2 : ℤ) • ∡ cfg.C cfg.Q₁ cfg.A₁ : by rw cfg.sbtw_Q_A₁_Q₁.symm.oangle_eq_right end oriented /-! ### Conclusions from that second angle chase -/ lemma not_collinear_CA₂A₁ : ¬collinear ℝ ({cfg.C, cfg.A₂, cfg.A₁} : set Pt) := begin haveI := some_orientation V, rw [collinear_iff_of_two_zsmul_oangle_eq cfg.two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CBA, set.pair_comm, set.insert_comm, set.pair_comm], exact cfg.not_collinear_ABC end lemma cospherical_A₁Q₁CA₂ : cospherical ({cfg.A₁, cfg.Q₁, cfg.C, cfg.A₂} : set Pt) := begin haveI := some_orientation V, rw [set.insert_comm cfg.Q₁, set.insert_comm cfg.A₁, set.pair_comm, set.insert_comm cfg.A₁, set.pair_comm], exact cospherical_of_two_zsmul_oangle_eq_of_not_collinear cfg.two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CQ₁A₁ cfg.not_collinear_CA₂A₁ end /-! ### The third angle chase in the solution -/ section oriented variables [module.oriented ℝ V (fin 2)] lemma two_zsmul_oangle_QQ₁A₂_eq_two_zsmul_oangle_QPA₂ : (2 : ℤ) • ∡ cfg.Q cfg.Q₁ cfg.A₂ = (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ := calc (2 : ℤ) • ∡ cfg.Q cfg.Q₁ cfg.A₂ = (2 : ℤ) • ∡ cfg.A₁ cfg.Q₁ cfg.A₂ : by rw cfg.sbtw_Q_A₁_Q₁.symm.oangle_eq_left ... = (2 : ℤ) • ∡ cfg.A₁ cfg.C cfg.A₂ : cfg.cospherical_A₁Q₁CA₂.two_zsmul_oangle_eq cfg.sbtw_Q_A₁_Q₁.right_ne cfg.Q₁_ne_A₂ cfg.A₁_ne_C.symm cfg.A₂_ne_C.symm ... = (2 : ℤ) • ∡ cfg.B cfg.C cfg.A₂ : by rw cfg.sbtw_B_A₁_C.symm.oangle_eq_left ... = (2 : ℤ) • ∡ cfg.B cfg.A cfg.A₂ : sphere.two_zsmul_oangle_eq cfg.B_mem_circumsphere cfg.C_mem_circumsphere cfg.A_mem_circumsphere cfg.A₂_mem_circumsphere cfg.B_ne_C.symm cfg.A₂_ne_C.symm cfg.A_ne_B cfg.A₂_ne_A.symm ... = (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ : cfg.two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_BAA₂.symm end oriented /-! ### Conclusions from that third angle chase -/ lemma Q₁_mem_ω : cfg.Q₁ ∈ cfg.ω := begin haveI := some_orientation V, exact affine.triangle.mem_circumsphere_of_two_zsmul_oangle_eq (dec_trivial : (0 : fin 3) ≠ 1) (dec_trivial : (0 : fin 3) ≠ 2) dec_trivial cfg.two_zsmul_oangle_QQ₁A₂_eq_two_zsmul_oangle_QPA₂ end lemma P₁_mem_ω : cfg.P₁ ∈ cfg.ω := by { rw ←symm_ω, exact cfg.symm.Q₁_mem_ω } theorem result : concyclic ({cfg.P, cfg.Q, cfg.P₁, cfg.Q₁} : set Pt) := begin refine ⟨_, coplanar_of_fact_finrank_eq_two _⟩, rw cospherical_iff_exists_sphere, refine ⟨cfg.ω, _⟩, simp only [set.insert_subset, set.singleton_subset_iff], exact ⟨cfg.P_mem_ω, cfg.Q_mem_ω, cfg.P₁_mem_ω, cfg.Q₁_mem_ω⟩ end end imo2019q2_cfg theorem imo2019_q2 (A B C A₁ B₁ P Q P₁ Q₁ : Pt) (affine_independent_ABC : affine_independent ℝ ![A, B, C]) (wbtw_B_A₁_C : wbtw ℝ B A₁ C) (wbtw_A_B₁_C : wbtw ℝ A B₁ C) (wbtw_A_P_A₁ : wbtw ℝ A P A₁) (wbtw_B_Q_B₁ : wbtw ℝ B Q B₁) (PQ_parallel_AB : line[ℝ, P, Q] ∥ line[ℝ, A, B]) (P_ne_Q : P ≠ Q) (sbtw_P_B₁_P₁ : sbtw ℝ P B₁ P₁) (angle_PP₁C_eq_angle_BAC : ∠ P P₁ C = ∠ B A C) (C_ne_P₁ : C ≠ P₁) (sbtw_Q_A₁_Q₁ : sbtw ℝ Q A₁ Q₁) (angle_CQ₁Q_eq_angle_CBA : ∠ C Q₁ Q = ∠ C B A) (C_ne_Q₁ : C ≠ Q₁) : concyclic ({P, Q, P₁, Q₁} : set Pt) := (⟨A, B, C, A₁, B₁, P, Q, P₁, Q₁, affine_independent_ABC, wbtw_B_A₁_C, wbtw_A_B₁_C, wbtw_A_P_A₁, wbtw_B_Q_B₁, PQ_parallel_AB, P_ne_Q, sbtw_P_B₁_P₁, angle_PP₁C_eq_angle_BAC, C_ne_P₁, sbtw_Q_A₁_Q₁, angle_CQ₁Q_eq_angle_CBA, C_ne_Q₁⟩ : imo2019q2_cfg V Pt).result
[STATEMENT] lemma isCont_ln_Gamma_complex [continuous_intros]: fixes f :: "'a::t2_space \<Rightarrow> complex" shows "isCont f z \<Longrightarrow> f z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> isCont (\<lambda>z. ln_Gamma (f z)) z" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>isCont f z; f z \<notin> \<real>\<^sub>\<le>\<^sub>0\<rbrakk> \<Longrightarrow> isCont (\<lambda>z. ln_Gamma (f z)) z [PROOF STEP] by (rule isCont_o2[OF _ DERIV_isCont[OF has_field_derivative_ln_Gamma_complex]])
[GOAL] q : ℚ ⊢ sqrt (q * q) = |q| [PROOFSTEP] rw [sqrt, mul_self_num, mul_self_den, Int.sqrt_eq, Nat.sqrt_eq, abs_def, divInt_ofNat] [GOAL] x : ℚ x✝ : ∃ q, q * q = x n : ℚ hn : n * n = x ⊢ sqrt x * sqrt x = x [PROOFSTEP] rw [← hn, sqrt_eq, abs_mul_abs_self]
import mynat.definition import mynat.add import mynat.mul lemma example1 (x y z : mynat) : x * y + z = x * y + z := begin refl, end
module output using DataFrames, DataStructures function to_string(instance) sok_dict, sok_arr = DataStructures.OrderedDict(key=> value.data for (key, value) in instance._sok_dict), [item.data for item in instance._sok_arr] max_lengths = Dict(key => ceil(Int, maximum(insert!([length(string(item)) for item in sok_dict[key]], 1, length(key))) * 1.5) for key in keys(sok_dict)) max_lengths["index"] = maximum([length(string(length(sok_arr))), length("index")]) print_string = string( "[ ", instance.name, " | ", length(sok_dict), " × ", length(sok_arr), " ]\n", "| ", lpad("", max_lengths["index"], " "), " | ", join([string(lpad(key, max_lengths[key], " "), " | ") for key in Base.keys(sok_dict)]), "\n" ) print_arr, arr_string = length(sok_arr) > 20 ? sok_arr[1:20] : sok_arr, "" for i in eachindex(print_arr) arr = print_arr[i] arr_string = string(arr_string, "| ", lpad(i, max_lengths["index"], " "), " |") for key in keys(arr) arr_string = string(arr_string, lpad(arr[key], max_lengths[key] + 1, " "), " | ") end arr_string = string(arr_string, "\n") end print_string = string(print_string, arr_string)[1:end - 1] return print_string end function to_dataframe(instance) return DataFrames.DataFrame(Dict(key=> value.data for (key, value) in instance._sok_dict)) end function to_dict(instance, orientation) sok_dict, sok_arr = DataStructures.OrderedDict(key=> value.data for (key, value) in instance._sok_dict), [item.data for item in instance._sok_arr] if orientation == "Dict" result = sok_dict elseif orientation == "Array" result = sok_arr end return result end function to_csv(instance, csv_path) sok_dict, sok_arr = DataStructures.OrderedDict(key=> value.data for (key, value) in instance._sok_dict), [item.data for item in instance._sok_arr] try open(csv_path, "w") do f_csv csv_string = string(join(keys(sok_dict), ", "), "\n") for sok in sok_arr csv_string = string(csv_string, join(values(sok), ", "), "\n") end write(f_csv, csv_string[1:end - 1]) end result = true catch error result = false end return result end end
State Before: α : Type u β : Type v inst✝ : TopologicalSpace α ⊢ (∀ {x y : α}, NeBot (𝓝 x ⊓ 𝓝 y) → x = y) ↔ ∀ {x y : α} (f : Ultrafilter α), ↑f ≤ 𝓝 x → ↑f ≤ 𝓝 y → x = y State After: no goals Tactic: simp only [← exists_ultrafilter_iff, and_imp, le_inf_iff, exists_imp]
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE Strict #-} module FokkerPlanck.GreensFunction where import Control.DeepSeq import Control.Monad as M import Data.Array.Accelerate.LLVM.PTX import Data.Array.IArray as IA import Data.Array.Repa as R import Data.Binary import Data.Complex import Data.List as L import Data.Vector.Storable as VS import Data.Vector.Unboxed as VU import FokkerPlanck.Analytic import FokkerPlanck.FourierSeriesGPU import FokkerPlanck.Histogram import Foreign.CUDA.Driver as CUDA import FourierMethod.FourierSeries2D import Image.IO import Pinwheel.FourierSeries2D import Pinwheel.Transform import Sparse.Vector import STC.Utils import System.FilePath import Utils.Array import Utils.List import Utils.Parallel import Utils.SimpsonRule import Utils.Time import Text.Printf import Utils.Distribution sampleCartesian :: FilePath -> FilePath -> [PTX] -> Int -> Double -> Double -> Int -> Double -> Double -> Double -> Double -> Double -> Int -> Int -> Int -> Int -> Double -> IO (Histogram (Complex Double)) sampleCartesian filePath folderPath ptxs numPoints period delta oris gamma thetaSigma tau threshold r2Sigma maxPhiFreqs maxRhoFreqs maxThetaFreqs maxRFreqs stdR2 = do let center = div numPoints 2 deltaTheta = 2 * pi / fromIntegral oris origin = R2S1RP 0 0 0 gamma idx = L.filter (\(R2S1RP c r _ g) -> (sqrt (c ^ 2 + r ^ 2) > 0) && g > 0) [ R2S1RP ((fromIntegral $ c - center) * delta) ((fromIntegral $ r - center) * delta) 0 gamma | c <- [0 .. numPoints - 1] , r <- [0 .. numPoints - 1] ] logGamma = 0 -- log gamma -- simpsonWeights = weightsSimpsonRule oris xs = L.concat -- . -- L.zipWith -- (\w -> L.map (\(a, b, c, d, v) -> (a, b, c, d, v * w))) -- simpsonWeights $ parMap rdeepseq (\o -> let ori = fromIntegral o * deltaTheta in L.filter (\(_, _, _, _, v) -> v > threshold) . L.map (\point@(R2S1RP x y _ g) -> let v = computePji thetaSigma tau origin (R2S1RP x y ori g) phi = atan2 y x rho = sqrt $ (x ^ 2 + y ^ 2) in ( phi , log rho , ori , logGamma , v * (1 - gaussian2DPolar rho stdR2) )) $ idx) [0 .. oris - 1] -- arr <- -- computeUnboxedP . fromFunction (Z :. oris :. numPoints :. numPoints) $ \(Z :. o :. i :. j) -> -- let x = (fromIntegral $ i - center) * delta -- y = (fromIntegral $ j - center) * delta -- phi = atan2 y x -- rho = sqrt $ (x ^ 2 + y ^ 2) -- theta = fromIntegral o * deltaTheta -- v = computePji thetaSigma tau origin (R2S1RP x y theta gamma) -- in if rho <= 1.5 -- then (1, 1, 1, 1, 0) -- else (phi, log rho, theta, logGamma, v) -- plotImageRepa (folderPath </> "GreensFunction.png") . -- ImageRepa 8 . -- computeS . -- -- reduceContrast 20 . -- extend (Z :. (1 :: Int) :. All :. All) . -- sumS . rotate3D . R.map (\(_, _, _, _, v) -> v) $ -- arr -- simpsonWeights = -- computeWeightArrFromListOfShape [numPoints, numPoints, oris] -- xs = -- L.filter (\(_, _, _, _, v) -> v > threshold) . -- R.toList -- . -- -- R.zipWith (\w (a, b, c, d, v) -> (a, b, c, d, w * v)) simpsonWeights -- $ -- arr let printCurrentTime $ printf "Sparsity: %f%%\n" (100 * (fromIntegral . L.length $ xs) / (fromIntegral $ oris * numPoints ^ 2) :: Double) let phiFreqs = L.map fromIntegral [-maxPhiFreqs .. maxPhiFreqs] rhoFreqs = L.map fromIntegral [-maxRhoFreqs .. maxRhoFreqs] thetaFreqs = L.map fromIntegral [-maxThetaFreqs .. maxThetaFreqs] rFreqs = L.map fromIntegral [-maxRFreqs .. maxRFreqs] hist = L.foldl1' (addHistogram) . parZipWith rdeepseq (\ptx ys -> computeFourierCoefficientsGPU' r2Sigma period phiFreqs rhoFreqs thetaFreqs rFreqs ptx ys) ptxs . divideListN (L.length ptxs) $ xs encodeFile filePath hist return hist sampleCartesianCorner :: FilePath -> FilePath -> [PTX] -> Int -> Double -> Double -> Int -> Double -> Double -> Double -> Double -> Double -> Int -> Int -> Int -> Int -> Double -> Double -> IO (Histogram (Complex Double)) sampleCartesianCorner filePath folderPath ptxs numPoints period delta oris gamma thetaSigma tau threshold r2Sigma maxPhiFreqs maxRhoFreqs maxThetaFreqs maxRFreqs stdR2 weight = do let center = div numPoints 2 deltaTheta = 2 * pi / fromIntegral oris -- origin = R2S1RP 0 0 0 gamma logGamma = 0 idxFunc c r o = ( fromIntegral o * deltaTheta , fromIntegral (c - center) * delta , fromIntegral (r - center) * delta) -- arr1 = -- fromFunction (Z :. oris :. numPoints :. numPoints) $ \(Z :. o :. c :. r) -> -- if c == center && r == center -- then 0 -- else let (ori, x, y) = idxFunc c r o -- in computePji thetaSigma tau origin (R2S1RP x y ori gamma) -- orientations = [fromIntegral i * deltaTheta | i <- [0 .. oris - 1]] -- arr2 = -- fromFunction (Z :. oris :. numPoints :. numPoints) $ \(Z :. o :. c :. r) -> -- if c == center && r == center -- then 0 -- else let (ori, x, y) = idxFunc c r o -- in computePjiCorner' -- thetaSigma -- tau -- threshold -- orientations -- (R2S1RP x y ori gamma) -- arr <- computeUnboxedP $ arr1 +^ (R.map (* weight) arr2) arr <- sampleR2S1Corner numPoints numPoints delta deltaTheta gamma thetaSigma tau threshold [0 .. oris - 1] weight let idx = [ idxFunc c r o | o <- [0 .. oris - 1] , c <- [0 .. numPoints - 1] , r <- [0 .. numPoints - 1] ] xs = L.map (\((ori, x, y), v) -> let phi = atan2 y x rho = sqrt (x ^ 2 + y ^ 2) in ( phi , log rho , ori , logGamma , v * (1 - gaussian2DPolar rho stdR2))) . L.filter (\((_, x, y), v) -> v > threshold && (x /= 0 || y /= 0)) . L.zip idx . R.toList $ arr printCurrentTime $ printf "Sparsity: %f%%\n" (100 * (fromIntegral . L.length $ xs) / (fromIntegral $ oris * numPoints ^ 2) :: Double) let phiFreqs = L.map fromIntegral [-maxPhiFreqs .. maxPhiFreqs] rhoFreqs = L.map fromIntegral [-maxRhoFreqs .. maxRhoFreqs] thetaFreqs = L.map fromIntegral [-maxThetaFreqs .. maxThetaFreqs] rFreqs = L.map fromIntegral [-maxRFreqs .. maxRFreqs] hist = L.foldl1' (addHistogram) . parZipWith rdeepseq (\ptx ys -> computeFourierCoefficientsGPU' r2Sigma period phiFreqs rhoFreqs thetaFreqs rFreqs ptx ys) ptxs . divideListN (L.length ptxs) $ xs encodeFile filePath hist return hist -- sampleLogpolar :: -- FilePath -- -> [PTX] -- -> Int -- -> Int -- -> Int -- -> Double -- -> Double -- -> Double -- -> Double -- -> Double -- -> Double -- -> Int -- -> Int -- -> Int -- -> Int -- -> IO (Histogram (Complex Double)) -- sampleLogpolar filePath ptxs phis rhos oris maxScale gamma sigma tau threshold r2Sigma maxPhiFreqs maxRhoFreqs maxThetaFreqs maxRFreqs = do -- let deltaPhi = 2 * pi / fromIntegral phis -- deltaTheta = 2 * pi / fromIntegral oris -- logMaxScale = log maxScale -- deltaLogRho = logMaxScale / fromIntegral rhos -- logGamma = 0 -- log gamma -- origin = R2S1RP 0 0 0 gamma -- -- xs = -- -- parMap -- -- rdeepseq -- -- (\(phi, logRho, theta) -> -- -- let x = (exp logRho) * cos phi -- -- y = (exp logRho) * sin phi -- -- v = computePji sigma tau origin (R2S1RP x y theta gamma) -- -- in (phi, logRho, theta, 0, v)) -- -- [ ( deltaTheta * fromIntegral iPhi -- -- , deltaLogRho * fromIntegral iLogRho - logMaxScale -- -- , deltaTheta * fromIntegral iTheta) -- -- | iPhi <- [0 .. oris - 1] -- -- , iLogRho <- [0 .. rhos - 1] -- -- , iTheta <- [0 .. oris - 1] -- -- ] -- arr <- -- computeUnboxedP . R.fromFunction (Z :. oris :. rhos :. phis) $ \(Z :. iTheta :. iLogRho :. iPhi) -> -- let theta = deltaTheta * fromIntegral iTheta -- phi = deltaPhi * fromIntegral iPhi -- logRho = deltaLogRho * fromIntegral iLogRho -- logMaxScale -- x = (exp logRho) * cos phi -- y = (exp logRho) * sin phi -- v = computePji sigma tau origin (R2S1RP x y theta gamma) -- in (phi, logRho, theta, logGamma, v) -- let simpsonWeights = computeWeightArrFromListOfShape [phis, rhos, oris] -- xs = -- L.filter (\(_, _, _, _, v) -> v > threshold) . -- R.toList . -- R.zipWith (\w (a, b, c, d, v) -> (a, b, c, d, w * v)) simpsonWeights $ -- arr -- printCurrentTime $ -- printf -- "Sparsity: %f%%\n" -- (100 * (fromIntegral . L.length $ xs) / (fromIntegral $ oris * phis * rhos) :: Double) -- let phiFreqs = L.map fromIntegral [-maxPhiFreqs .. maxPhiFreqs] -- rhoFreqs = L.map fromIntegral [-maxRhoFreqs .. maxRhoFreqs] -- thetaFreqs = L.map fromIntegral [-maxThetaFreqs .. maxThetaFreqs] -- rFreqs = L.map fromIntegral [-maxRFreqs .. maxRFreqs] -- hist = -- L.foldl1' (addHistogram) . -- parZipWith -- rdeepseq -- (\ptx ys -> -- computeFourierCoefficientsGPU' -- r2Sigma -- phiFreqs -- rhoFreqs -- thetaFreqs -- rFreqs -- ptx -- ys) -- ptxs . -- divideListN (L.length ptxs) $ -- xs -- encodeFile filePath hist -- return hist {-# INLINE sampleR2S1 #-} sampleR2S1 :: Int -> Int -> Double -> Double -> Double -> Double -> Double -> [Int] -> IO (R.Array U DIM3 Double) sampleR2S1 rows cols delta deltaTheta gamma sigma tau oris = do let centerRow = div rows 2 centerCol = div cols 2 origin = R2S1RP 0 0 0 gamma computeUnboxedP . R.traverse (fromListUnboxed (Z :. (L.length oris)) oris) (\(Z :. o) -> (Z :. o :. cols :. rows)) $ \f (Z :. o :. c :. r) -> if (c == centerCol) && (r == centerRow) then 0 else computePji sigma tau origin (R2S1RP (delta * fromIntegral (c - centerCol)) (delta * fromIntegral (r - centerRow)) (fromIntegral (f (Z :. o)) * deltaTheta) gamma) {-# INLINE sampleR2S1' #-} sampleR2S1' :: Int -> Int -> Double -> Double -> Double -> Double -> Double -> R.Array U DIM2 (Int, Double) sampleR2S1' rows cols delta gamma sigma tau ori = let centerRow = div rows 2 centerCol = div cols 2 origin = R2S1RP 0 0 0 gamma in computeUnboxedS . R.fromFunction (Z :. cols :. rows) $ \(Z :. c :. r) -> let x = c - centerCol y = r - centerRow in if x == 0 && y == 0 then (0, 0) else ( getVectorIndex2D rows c r , computePji sigma tau origin (R2S1RP (delta * fromIntegral (c - centerCol)) (delta * fromIntegral (r - centerRow)) ori gamma)) {-# INLINE sampleR2S1Corner #-} sampleR2S1Corner :: Int -> Int -> Double -> Double -> Double -> Double -> Double -> Double -> [Int] -> Double -> IO (R.Array U DIM3 Double) sampleR2S1Corner rows cols delta deltaTheta gamma sigma tau threshold oris weight = do let centerRow = div rows 2 centerCol = div cols 2 origin = R2S1RP 0 0 0 gamma orientations = L.map (\o -> deltaTheta * fromIntegral o) oris arr1 <- computeUnboxedP . R.traverse (fromListUnboxed (Z :. (L.length oris)) oris) (\(Z :. o) -> (Z :. o :. cols :. rows)) $ \f (Z :. o :. c :. r) -> if (c == centerCol) && (r == centerRow) then 0 else computePji sigma tau origin (R2S1RP (delta * fromIntegral (c - centerCol)) (delta * fromIntegral (r - centerRow)) (fromIntegral (f (Z :. o)) * deltaTheta) gamma) arr2 <- computeUnboxedP . R.traverse (fromListUnboxed (Z :. (L.length oris)) oris) (\(Z :. o) -> (Z :. o :. cols :. rows)) $ \f (Z :. o :. c :. r) -> if (c == centerCol) && (r == centerRow) then 0 else computePjiCorner' delta sigma tau threshold orientations (R2S1RP (delta * fromIntegral (c - centerCol)) (delta * fromIntegral (r - centerRow)) (fromIntegral (f (Z :. o)) * deltaTheta) gamma) computeUnboxedP $ (arr1 +^ (R.map (* weight) arr2)) cornerDistribution :: Double -> Double -> Double -> Double -> Double -> [Double] -> Double -> (Double, Double) -> [Double] cornerDistribution delta gamma sigma tau threshold oris weight (x, y) = let origin = R2S1RP 0 0 0 gamma in L.map (\ori -> computePji sigma tau origin (R2S1RP x y ori gamma) + weight * computePjiCorner' delta sigma tau threshold oris (R2S1RP x y ori gamma)) oris {-# INLINE cornerDistribution' #-} cornerDistribution' :: Double -> Double -> Double -> Double -> Double -> [Double] -> Double -> (Double, Double) -> Double -> IO (Double, Double, Double) cornerDistribution' delta gamma sigma tau threshold oris weight (x, y) ori = do let origin = R2S1RP 0 0 0 gamma a = computePji sigma tau origin (R2S1RP x y ori gamma) b = computePjiCorner' delta sigma tau threshold oris (R2S1RP x y ori gamma) printf "sigma = %f\ntau = %f\nthreshold = %f\noris = %s\n(R2S1RP %f %f %f %f)\n" sigma tau threshold (show oris) x y ori gamma return (a, b, a + weight * b) computeFourierCoefficients :: FilePath -> [Int] -> [PTX] -> Int -> Int -> Double -> Double -> Double -> Double -> Double -> Int -> Double -> Double -> Int -> Int -> Int -> Int -> Int -> Int -> IO (Histogram (Complex Double)) computeFourierCoefficients histFilePath deviceIDs ptxs numPoints oris delta deltaFreq gamma sigma tau numR2Freqs period std numBatchR2Freqs numBatchOri maxPhiFreq maxRhoFreq maxThetaFreq maxRFreq = do when (even oris) (error "computeFourierCoefficients: the number of orientations is not odd.") let deltaTheta = 2 * pi / fromIntegral oris simpsonWeights = computeUnboxedS $ (computeWeightArrFromListOfShape [numPoints, numPoints] :: R.Array D DIM2 (Complex Double)) oriIdxs = divideListN numBatchOri [0 .. oris - 1] xs <- M.mapM (sampleR2S1 numPoints numPoints delta deltaTheta gamma sigma tau) oriIdxs let weightedVecs = parMap rdeepseq (\arr -> let (Z :. n :. m :. c) = extent arr in CuMat (n * m) c . CuVecHost . VU.convert . toUnboxed . computeS . R.traverse2 arr simpsonWeights const $ \f fW idx@(Z :. i :. j :. _) -> (f idx :+ 0) * fW (Z :. i :. j)) xs coefficients <- computeFourierCoefficientsR2Stream deviceIDs ptxs numR2Freqs numPoints period delta deltaFreq numBatchR2Freqs weightedVecs print "coefficients done" let centerR2Freq = div numR2Freqs 2 centerPoints = div numPoints 2 logGamma = log gamma gaussianWeightedCoef = computeUnboxedS $ applyGaussian deltaFreq std coefficients -- gaussianWeightedCoef = coefficients simpsonWeightsOri = computeUnboxedS $ (computeWeightArrFromListOfShape [oris] :: R.Array D DIM1 (Complex Double)) weightedCoef = R.traverse2 gaussianWeightedCoef simpsonWeightsOri const $ \fG fS idx@(Z :. o :. _ :. _) -> fG idx * fS (Z :. o) folderPath = "output/test/STCPinwheel" -- print . extent $ gaussianWeightedCoef -- inverseR2Harmonics <- -- createInverseHarmonicMatriesGPU ptxs 1 numPoints numR2Freqs period delta -- sourceR2 <- -- computeFourierSeriesR2 -- deviceIDs -- numR2Freqs -- numPoints -- period -- inverseR2Harmonics -- [ CuMat oris (numR2Freqs ^ 2) . CuVecHost . VU.convert . toUnboxed $ -- gaussianWeightedCoef -- ] plotImageRepa (folderPath </> "Green.png") . ImageRepa 8 . fromUnboxed (Z :. (1 :: Int) :. numPoints :. numPoints) . VU.map sqrt . toUnboxed . sumS . R.map (\x -> (x) ** 2) . L.head $ xs plotImageRepa (folderPath </> "Coefficients.png") . ImageRepa 8 . fromUnboxed (Z :. (1 :: Int) :. numR2Freqs :. numR2Freqs) . VU.map sqrt . toUnboxed . sumS . R.map (\x -> (magnitude x) ** 2) . rotate3D $ gaussianWeightedCoef -- plotImageRepa (folderPath </> "GreenRecon.png") . -- ImageRepa 8 . -- fromUnboxed (Z :. (1 :: Int) :. numPoints :. numPoints) . -- VU.map sqrt . toUnboxed . sumS . R.map (\x -> (magnitude x) ** 2) . rotate3D $ -- sourceR2 ys <- (computeUnboxedP . R.traverse weightedCoef id $ \f idx@(Z :. o :. i :. j) -> if i == centerR2Freq && j == centerR2Freq then (0, 0, 0, 0, 0) else let x = deltaFreq * (fromIntegral $ i - centerR2Freq) y = deltaFreq * (fromIntegral $ j - centerR2Freq) phi = atan2 y x logRho = log . sqrt $ (x ^ 2 + y ^ 2) in (phi, logRho, fromIntegral o * deltaTheta, logGamma, f idx)) -- ys <- -- (computeUnboxedP . -- R.traverse -- (R.traverse2 (L.head xs) simpsonWeightsOri const $ \fG fS idx@(Z :. _ :. _ :. o) -> -- (fG idx :+ 0) * fS (Z :. o)) -- id $ \f idx@(Z :. i :. j :. o) -> -- if i == centerPoints && j == centerPoints -- then (0, 0, 0, 0, 0) -- else let x = delta * (fromIntegral $ i - centerPoints) -- y = delta * (fromIntegral $ j - centerPoints) -- phi = atan2 x y -- logRho = log . sqrt $ (x ^ 2 + y ^ 2) -- in ( phi -- , logRho -- , fromIntegral o * deltaTheta -- , logGamma -- , f idx)) let hist = L.foldl1' (addHistogram) . parZipWith rdeepseq (\ptx -> computePinwheelCoefficients maxPhiFreq maxRhoFreq maxThetaFreq maxRFreq ptx) ptxs . divideListN (L.length ptxs) . R.toList $ ys encodeFile histFilePath hist return hist computePinwheelTransformCoefficients :: Int -> FilePath -> [Int] -> [PTX] -> Int -> Int -> Double -> Double -> Double -> Double -> Double -> Int -> Double -> Double -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Double -> IO (Histogram (Complex Double)) computePinwheelTransformCoefficients numThread histFilePath deviceIDs ptxs numPoints oris delta threshold gamma sigma tau numR2Freqs periodR2 std numBatchR2 numBatchPinwheelFreqs maxPhiFreq maxRhoFreq maxThetaFreq maxRFreq batchSize s = do printCurrentTime "compute pinwheelArr" pinwheelArr <- pinwheelFourierSeries deviceIDs ptxs numPoints -- numR2Freqs numPoints delta periodR2 maxPhiFreq maxRhoFreq maxThetaFreq maxRFreq s numBatchR2 numBatchPinwheelFreqs :: IO (IA.Array (Int, Int) (VU.Vector (Complex Double))) printCurrentTime "pinwheelArr done" let folderPath = "output/test/STCPinwheel" let deltaTheta = 2 * pi / (fromIntegral oris) greensFunc = parMap rdeepseq (\o -> let theta = fromIntegral o * deltaTheta vec = toUnboxed $ sampleR2S1' numPoints numPoints delta gamma sigma tau theta in PinwheelTransformData (log gamma) theta . uncurry SparseVector . VU.unzip . VU.map (\(i, v) -> (i, v :+ 0)) . VU.filter (\(_, v) -> v > threshold) $ vec) [0 .. oris - 1] len = L.foldl' (\s (PinwheelTransformData _ _ (SparseVector vec _)) -> s + VU.length vec) 0 greensFunc printCurrentTime $ printf "Sparsity: %f%%\n" (100 * (fromIntegral len) / (fromIntegral $ oris * numPoints ^ 2) :: Double) let hist = pinwheelTransform numThread maxPhiFreq maxRhoFreq maxThetaFreq maxRFreq s pinwheelArr greensFunc encodeFile histFilePath hist return hist
[STATEMENT] lemma Eps12_hypext_inverse [simp]: "Base (x::'a::real_normed_field hyperdual) \<noteq> 0 \<Longrightarrow> Eps12 (inverse x) = Eps1 x * Eps2 x * (2/ (Base x ^ 3)) - Eps12 x / (Base x)\<^sup>2" [PROOF STATE] proof (prove) goal (1 subgoal): 1. Base x \<noteq> (0::'a) \<Longrightarrow> Eps12 (inverse x) = Eps1 x * Eps2 x * ((2::'a) / Base x ^ 3) - Eps12 x / (Base x)\<^sup>2 [PROOF STEP] by simp
{-# OPTIONS --without-K #-} module algebra.group.classifying where open import level open import algebra.group.core open import algebra.group.morphism open import equality.core open import function.isomorphism open import pointed.core open import sets.unit open import sum open import hott.level.core open import hott.loop.core open import hott.truncation.core open import hott.equivalence module _ {i}(G : Set i) ⦃ gG : IsGroup G ⦄ where open import algebra.group.gset G open IsGroup ⦃ ... ⦄ -- G as a G-Set G' : GSet i G' = (G , GisGSet) -- G as a pointed set G* : PSet i G* = (G , e) 𝑩 : Set (lsuc i) 𝑩 = Σ (GSet i) λ X → Trunc 1 (X ≡ G') base : 𝑩 base = (G' , [ refl ]) 𝑩* : PSet (lsuc i) 𝑩* = (𝑩 , base) 𝑩-Ω : (base ≡ base) ≅ G 𝑩-Ω = begin (base ≡ base) ≅⟨ sym≅ Σ-split-iso ⟩ ( Σ (G' ≡ G') λ p → subst (λ X → Trunc 1 (X ≡ G')) p [ refl ] ≡ [ refl ] ) ≅⟨ (Σ-ap-iso refl≅ λ p → contr-⊤-iso (Trunc-level 1 _ _)) ·≅ ×-right-unit ⟩ (G' ≡ G') ≅⟨ GSet-univalence G ⦃ xG = GisGSet ⦄ G ⦃ yG = GisGSet ⦄ ⟩ ( Σ (GSetMorphism G ⦃ xG = GisGSet ⦄ G ⦃ yG = GisGSet ⦄) λ { (f , _) → weak-equiv f } ) ≅⟨ (Σ-ap-iso' (GSet-repr-iso is-set ⦃ xG = GisGSet ⦄) λ _ → refl≅) ⟩ ( Σ G λ { g → weak-equiv (λ x → x * g) } ) ≅⟨ ( Σ-ap-iso refl≅ λ g → contr-⊤-iso ( lem g , h1⇒prop (we-h1 _) _ ) ) ·≅ ×-right-unit ⟩ G ∎ where open ≅-Reasoning lem : (g : G) → weak-equiv (λ x → x * g) lem g = proj₂ (≅'⇒≈ (≅⇒≅' (right-translation-iso g)))
(* SLOT, a formally verified model checker Copyright (C) 2019-2021 0k2 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. *) From Coq Require Import List. Import ListNotations. From SLOT Require Import Foundations Properties Tactics. Section defs. Open Scope slot_scope. Inductive req_t : Set := | grab : req_t | release : req_t. Local Definition ret_t (req : req_t) : Set := match req with | grab => True | release => bool end. Definition state_t := option PID. Let TE := TraceElem req_t ret_t. Inductive mutex_state_transition : state_t -> TE -> state_t -> Prop := | mutex_grab : forall pid, mutex_state_transition None (pid @ I <~ grab) (Some pid) | mutex_release_ok : forall pid, mutex_state_transition (Some pid) (pid @ true <~ release) None | mutex_release_fail : forall pid, mutex_state_transition None (pid @ false <~ release) None. Global Instance t : @IOHandler req_t ret_t := { h_state := state_t; h_state_transition := mutex_state_transition; }. Theorem no_double_grab : forall (a1 a2 : PID), {{ fun _ => True }} [a1 @ I <~ grab; a2 @ I <~ grab] {{ fun _ => False }}. Proof. intros a1 a2 s s' Hss' Hpre. unfold_trace_deep Hss'. discriminate. Qed. Theorem no_double_grab_0 : forall (a1 a2 : PID), ~(PossibleTrace [a1 @ I <~ grab; a2 @ I <~ grab]). Proof. intros a1 a2 H. destruct H as [s [s' H]]. unfold_trace_deep H. discriminate. Qed. End defs. Ltac mutex_contradiction := match goal with [H1 : mutex_state_transition _ ?s1 ?s2 _, H2 : mutex_state_transition _ ?s2 ?s3 _ |- _] => inversion H1; inversion H2; subst; discriminate end. Hint Extern 4 => mutex_contradiction : handlers. Ltac clear_mutex := repeat match goal with [H: mutex_state_transition _ _ _ _ |- _] => clear H end.
myRule { if(strlen(*mvalue) > 0) { *value = "" *key = split(*mvalue, ","); } msiPidSetHandle(*handle, *key, *value); writeLine("stdout", "*handle"); } INPUT *handle="", *key="MYKEY", *value="MYVALUE", *mvalue="" OUTPUT ruleExecOut
/- Copyright (c) 2021 OpenAI. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f -/ import mathzoo.imports.miniF2F open_locale nat rat real big_operators topological_space theorem induction_seq_mul2pnp1 (n : ℕ) (u : ℕ → ℕ) (h₀ : u 0 = 0) (h₁ : ∀ n, u (n + 1) = 2 * u n + (n + 1)) : u n = 2^(n + 1) - (n + 2) := begin apply eq_tsub_of_add_eq, simp [pow_succ], induction n with a ih, { simp [h₀, h₁] }, norm_num [h₀, h₁], simp [nat.succ_eq_add_one], rw [add_left_comm, ← add_assoc], simp only [pow_succ'], rw [mul_two], linarith, end
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Optics.All open import LibraBFT.Prelude open import LibraBFT.Lemmas open import LibraBFT.Base.KVMap open import LibraBFT.Base.PKCS open import LibraBFT.Hash open import LibraBFT.Impl.Base.Types open import LibraBFT.Impl.Consensus.Types open import LibraBFT.Impl.Util.Crypto open import LibraBFT.Impl.Handle sha256 sha256-cr open import LibraBFT.Concrete.System.Parameters open EpochConfig open import LibraBFT.Yasm.Yasm (ℓ+1 0ℓ) EpochConfig epochId authorsN ConcSysParms NodeId-PK-OK -- This module contains placeholders for the future analog of the -- corresponding VotesOnce property. Defining the implementation -- obligation and proving that it is an invariant of an implementation -- is a substantial undertaking. We are working first on proving the -- simpler VotesOnce property to settle down the structural aspects -- before tackling the harder semantic issues. module LibraBFT.Concrete.Properties.LockedRound where -- TODO-3: define the implementation obligation ImplObligation₁ : Set ImplObligation₁ = Unit -- Next, we prove that given the necessary obligations, module Proof (sps-corr : StepPeerState-AllValidParts) (Impl-LR1 : ImplObligation₁) where -- Any reachable state satisfies the LR rule for any epoch in the system. module _ {e}(st : SystemState e)(r : ReachableSystemState st)(eid : Fin e) where -- Bring in 'unwind', 'ext-unforgeability' and friends open Structural sps-corr -- Bring in IntSystemState open import LibraBFT.Concrete.System sps-corr open PerState st r open PerEpoch eid open import LibraBFT.Concrete.Obligations.LockedRound 𝓔 (ConcreteVoteEvidence 𝓔) as LR postulate -- TODO-3: prove it lrr : LR.Type IntSystemState
section \<open>Misc results about polynomials\<close> theory RRI_Misc imports "HOL-Computational_Algebra.Computational_Algebra" "Budan_Fourier.BF_Misc" "Polynomial_Interpolation.Ring_Hom_Poly" begin subsection \<open>Misc\<close> declare pcompose_pCons[simp del] lemma Setcompr_subset: "\<And>f P S. {f x | x. P x} \<subseteq> S = (\<forall> x. P x \<longrightarrow> f x \<in> S)" by blast lemma map_cong': assumes "xs = map h ys" and "\<And>y. y \<in> set ys \<Longrightarrow> f (h y) = g y" shows "map f xs = map g ys" using assms map_replicate_trivial by simp lemma nth_default_replicate_eq: "nth_default dflt (replicate n x) i = (if i < n then x else dflt)" by (auto simp: nth_default_def) lemma square_bounded_less: fixes a b::"'a :: linordered_ring_strict" shows "-a < b \<and> b < a \<Longrightarrow> b*b < a*a" by (metis (no_types, lifting) leD leI minus_less_iff minus_mult_minus mult_strict_mono' neg_less_eq_nonneg neg_less_pos verit_minus_simplify(4) zero_le_mult_iff zero_le_square) lemma square_bounded_le: fixes a b::"'a :: linordered_ring_strict" shows "-a \<le> b \<and> b \<le> a \<Longrightarrow> b*b \<le> a*a" by (metis le_less minus_mult_minus square_bounded_less) context vector_space begin lemma card_le_dim_spanning: assumes BV: "B \<subseteq> V" and VB: "V \<subseteq> span B" and fB: "finite B" and dVB: "dim V \<ge> card B" shows "independent B" proof - { fix a assume a: "a \<in> B" "a \<in> span (B - {a})" from a fB have c0: "card B \<noteq> 0" by auto from a fB have cb: "card (B - {a}) = card B - 1" by auto { fix x assume x: "x \<in> V" from a have eq: "insert a (B - {a}) = B" by blast from x VB have x': "x \<in> span B" by blast from span_trans[OF a(2), unfolded eq, OF x'] have "x \<in> span (B - {a})" . } then have th1: "V \<subseteq> span (B - {a})" by blast have th2: "finite (B - {a})" using fB by auto from dim_le_card[OF th1 th2] have c: "dim V \<le> card (B - {a})" . from c c0 dVB cb have False by simp } then show ?thesis unfolding dependent_def by blast qed end subsection \<open>Misc results about polynomials\<close> lemma smult_power: "smult (x^n) (p^n) = smult x p ^ n" apply (induction n) subgoal by fastforce by (metis smult_power) lemma reflect_poly_monom: "reflect_poly (monom n i) = monom n 0" apply (induction i) by (auto simp: coeffs_eq_iff coeffs_monom coeffs_reflect_poly) lemma poly_eq_by_eval: fixes P Q :: "'a::{comm_ring_1,ring_no_zero_divisors,ring_char_0} poly" assumes h: "\<And>x. poly P x = poly Q x" shows "P = Q" proof - have "poly P = poly Q" using h by fast thus ?thesis by (auto simp: poly_eq_poly_eq_iff) qed lemma poly_binomial: "[:(1::'a::comm_ring_1), 1:]^n = (\<Sum>k\<le>n. monom (of_nat (n choose k)) k)" proof - have "[:(1::'a::comm_ring_1), 1:]^n = (monom 1 1 + 1)^n" by (metis (no_types, lifting) add.left_neutral add.right_neutral add_pCons monom_altdef pCons_one power_one_right smult_1_left) also have "... = (\<Sum>k\<le>n. of_nat (n choose k) * monom 1 1 ^ k)" apply (subst binomial_ring) by force also have "... = (\<Sum>k\<le>n. monom (of_nat (n choose k)) k)" by (auto simp: monom_altdef of_nat_poly) finally show ?thesis . qed lemma degree_0_iff: "degree P = 0 \<longleftrightarrow> (\<exists>a. P = [:a:])" by (meson degree_eq_zeroE degree_pCons_0) interpretation poly_vs: vector_space smult by (simp add: vector_space_def smult_add_right smult_add_left) lemma degree_subspace: "poly_vs.subspace {x. degree x \<le> n}" by (auto simp: poly_vs.subspace_def degree_add_le) lemma monom_span: "poly_vs.span {monom 1 x | x. x \<le> p} = {(x::'a::field poly). degree x \<le> p}" (is "?L = ?R") proof show "?L \<subseteq> ?R" proof fix x assume "x \<in> ?L" moreover have hfin: "finite {P. \<exists>x \<in> {..p}. P = monom 1 x}" by auto ultimately have "x \<in> range (\<lambda>u. \<Sum>v\<in>{monom 1 x | x. x \<in> {..p}}. smult (u v) v)" by (simp add: poly_vs.span_finite) hence "\<exists> u. x = (\<Sum>v\<in>{monom 1 x | x. x \<in> {..p}}. smult (u v) v)" by (auto simp: image_iff) then obtain u where p': "x = (\<Sum>v\<in>{monom 1 x | x. x \<in> {..p}}. smult (u v) v)" by blast have "\<And>v. v \<in> {monom 1 x | x. x \<in> {..p}} \<Longrightarrow> degree (smult (u v) v) \<le> p" by (auto simp add: degree_monom_eq) hence "degree x \<le> p" using hfin apply (subst p') apply (rule degree_sum_le) by auto thus "x \<in> {x. degree x \<le> p}" by force qed next show "?R \<subseteq> ?L" proof fix x assume "x \<in> ?R" hence "degree x \<le> p" by force hence "x = (\<Sum>i\<le>p. monom (coeff x i) i)" by (simp add: poly_as_sum_of_monoms') also have "... = (\<Sum>i\<le>p. smult (coeff x (degree (monom (1::'a) i))) (monom 1 i))" by (auto simp add: smult_monom degree_monom_eq) also have "... = (\<Sum>v\<in>{monom 1 x | x. x \<in> {..p}}. smult ((\<lambda>v. coeff x (degree v)) v) v)" proof (rule sum.reindex_cong) show "inj_on degree {monom (1::'a) x |x. x \<in> {..p}}" proof fix x assume "x \<in> {monom (1::'a) x |x. x \<in> {..p}}" hence "\<exists> a. x = monom 1 a" by blast then obtain a where hx: "x = monom 1 a" by blast fix y assume "y \<in> {monom (1::'a) x |x. x \<in> {..p}}" hence "\<exists> b. y = monom 1 b" by blast then obtain b where hy: "y = monom 1 b" by blast assume "degree x = degree y" thus "x = y" using hx hy by (simp add: degree_monom_eq) qed show "{..p} = degree ` {monom (1::'a) x |x. x \<in> {..p}}" proof show "{..p} \<subseteq> degree ` {monom (1::'a) x |x. x \<in> {..p}}" proof fix x assume "x \<in> {..p}" hence "monom (1::'a) x \<in> {monom 1 x |x. x \<in> {..p}}" by force moreover have "degree (monom (1::'a) x) = x" by (simp add: degree_monom_eq) ultimately show "x \<in> degree ` {monom (1::'a) x |x. x \<in> {..p}}" by auto qed show "degree ` {monom (1::'a) x |x. x \<in> {..p}} \<subseteq> {..p}" by (auto simp add: degree_monom_eq) qed next fix y assume "y \<in> {monom (1::'a) x |x. x \<in> {..p}}" hence "\<exists>z \<in> {..p}. y = monom (1::'a) z" by blast then obtain z where "y = monom (1::'a) z" by blast thus "smult (coeff x (degree (monom (1::'a) (degree y)))) (monom (1::'a) (degree y)) = smult (coeff x (degree y)) y" by (simp add: smult_monom degree_monom_eq) qed finally have "x = (\<Sum>v\<in>{monom 1 x | x. x \<in> {..p}}. smult ((\<lambda>v. coeff x (degree v)) v) v)" . thus "x \<in> ?L" by (auto simp add: poly_vs.span_finite) qed qed lemma monom_independent: "poly_vs.independent {monom (1::'a::field) x | x. x \<le> p}" proof (rule poly_vs.independent_if_scalars_zero) fix f::"'a poly \<Rightarrow> 'a" assume h: "(\<Sum>x\<in>{monom 1 x |x. x \<le> p}. smult (f x) x) = 0" have h': "(\<Sum>i\<le>p. monom (f (monom (1::'a) i)) i) = (\<Sum>x\<in>{monom (1::'a) x |x. x \<le> p}. smult (f x) x)" proof (rule sum.reindex_cong) show "inj_on degree {monom (1::'a) x |x. x \<le> p}" by (smt (verit) degree_monom_eq inj_on_def mem_Collect_eq zero_neq_one) show "{..p} = degree ` {monom (1::'a) x |x. x \<le> p}" proof show "{..p} \<subseteq> degree ` {monom (1::'a) x |x. x \<le> p}" proof fix x assume "x \<in> {..p}" then have "x = degree (monom (1::'a) x) \<and> x \<le> p" by (auto simp: degree_monom_eq) thus "x \<in> degree ` {monom (1::'a) x |x. x \<le> p}" by blast qed show "degree ` {monom (1::'a) x |x. x \<le> p} \<subseteq> {..p}" by (force simp: degree_monom_eq) qed qed (auto simp: degree_monom_eq smult_monom) fix x::"'a poly" assume "x \<in> {monom 1 x |x. x \<le> p}" then obtain y where "y \<le> p" and "x = monom 1 y" by blast hence "f x = coeff (\<Sum>x\<in>{monom 1 x |x. x \<le> p}. smult (f x) x) y" by (auto simp: coeff_sum h'[symmetric]) thus "f x = 0" using h by auto qed force lemma dim_degree: "poly_vs.dim {x. degree x \<le> n} = n + 1" using poly_vs.dim_eq_card_independent[OF monom_independent] by (auto simp: monom_span[symmetric] card_image image_Collect[symmetric] inj_on_def monom_eq_iff') lemma degree_div: fixes p q::"('a::idom_divide) poly" assumes "q dvd p" shows "degree (p div q) = degree p - degree q" using assms by (metis (no_types, lifting) add_diff_cancel_left' degree_0 degree_mult_eq diff_add_zero diff_zero div_by_0 dvd_div_eq_0_iff dvd_mult_div_cancel) lemma lead_coeff_div: fixes p q::"('a::{idom_divide, inverse}) poly" assumes "q dvd p" shows "lead_coeff (p div q) = lead_coeff p / lead_coeff q" using assms by (smt (z3) div_by_0 dvd_div_mult_self lead_coeff_mult leading_coeff_0_iff nonzero_mult_div_cancel_right) lemma complex_poly_eq: "r = map_poly of_real (map_poly Re r) + smult \<i> (map_poly of_real (map_poly Im r))" by (auto simp: poly_eq_iff coeff_map_poly complex_eq) lemma complex_poly_cong: "(map_poly Re p = map_poly Re q \<and> map_poly Im p = map_poly Im q) = (p = q)" by (metis complex_poly_eq) lemma map_poly_Im_of_real: "map_poly Im (map_poly of_real p) = 0" by (auto simp: poly_eq_iff coeff_map_poly) lemma mult_map_poly_imp_map_poly: assumes "map_poly complex_of_real q = r * map_poly complex_of_real p" "p \<noteq> 0" shows "r = map_poly complex_of_real (map_poly Re r)" proof - have h: "Im \<circ> (*) \<i> \<circ> complex_of_real = id" by fastforce have "map_poly complex_of_real q = r * map_poly complex_of_real p" using assms by blast also have "... = (map_poly of_real (map_poly Re r) + smult \<i> (map_poly of_real (map_poly Im r))) * map_poly complex_of_real p" using complex_poly_eq by fastforce also have "... = map_poly of_real (map_poly Re r * p) + smult \<i> (map_poly of_real (map_poly Im r * p))" by (simp add: mult_poly_add_left) finally have "map_poly complex_of_real q = map_poly of_real (map_poly Re r * p) + smult \<i> (map_poly of_real (map_poly Im r * p))" . hence "0 = map_poly Im (map_poly of_real (map_poly Re r * p) + smult \<i> (map_poly of_real (map_poly Im r * p)))" by (auto simp: complex_poly_cong[symmetric] map_poly_Im_of_real) also have "... = map_poly of_real (map_poly Im r * p)" apply (rule poly_eqI) by (auto simp: coeff_map_poly coeff_mult) finally have "0 = map_poly complex_of_real (map_poly Im r) * map_poly complex_of_real p" by auto hence "map_poly complex_of_real (map_poly Im r) = 0" using assms by fastforce thus ?thesis apply (subst complex_poly_eq) by auto qed lemma map_poly_dvd: fixes p q::"real poly" assumes hdvd: "map_poly complex_of_real p dvd map_poly complex_of_real q" "q \<noteq> 0" shows "p dvd q" proof - from hdvd obtain r where h:"map_poly complex_of_real q = r * map_poly complex_of_real p" by fastforce hence "r = map_poly complex_of_real (map_poly Re r)" using mult_map_poly_imp_map_poly assms by force hence "map_poly complex_of_real q = map_poly complex_of_real (p * map_poly Re r)" using h by auto hence "q = p * map_poly Re r" using of_real_poly_eq_iff by blast thus "p dvd q" by force qed lemma div_poly_eq_0: fixes p q::"('a::idom_divide) poly" assumes "q dvd p" "poly (p div q) x = 0" "q \<noteq> 0" shows "poly p x = 0" using assms by fastforce lemma poly_map_poly_of_real_cnj: "poly (map_poly of_real p) (cnj z) = cnj (poly (map_poly of_real p) z)" apply (induction p) by auto text \<open> An induction rule on real polynomials, if $P \neq 0$ then either $(X-x)|P$ or $(X-z)(X-cnj z)|P$, we induct by dividing by these polynomials. \<close> lemma real_poly_roots_induct: fixes P::"real poly \<Rightarrow> bool" and p::"real poly" assumes IH_real: "\<And>p x. P p \<Longrightarrow> P (p * [:-x, 1:])" and IH_complex: "\<And>p a b. b \<noteq> 0 \<Longrightarrow> P p \<Longrightarrow> P (p * [: a*a + b*b, -2*a, 1 :])" and H0: "\<And>a. P [:a:]" defines "d \<equiv> degree p" shows "P p" using d_def proof (induction d arbitrary: p rule: less_induct) fix p::"real poly" assume IH: "(\<And>q. degree q < degree p \<Longrightarrow> P q)" show "P p" proof (cases "0 = degree p") fix p::"real poly" assume "0 = degree p" hence "\<exists> a. p = [:a:]" by (simp add: degree_0_iff) thus "P p" using H0 by blast next assume hdeg: "0 \<noteq> degree p" hence "\<not> constant (poly (map_poly of_real p))" by (metis (no_types, opaque_lifting) constant_def constant_degree of_real_eq_iff of_real_poly_map_poly) then obtain z::complex where h: "poly (map_poly of_real p) z = 0" using fundamental_theorem_of_algebra by blast show "P p" proof cases assume "Im z = 0" hence "z = Re z" by (simp add: complex_is_Real_iff) moreover have "[:-z, 1:] dvd map_poly of_real p" using h poly_eq_0_iff_dvd by blast ultimately have "[:-(Re z), 1:] dvd p" by (smt (z3) dvd_iff_poly_eq_0 h of_real_0 of_real_eq_iff of_real_poly_map_poly) hence 2:"P (p div [:-Re z, 1:])" apply (subst IH) using hdeg by (auto simp: degree_div) moreover have 1:"p = (p div [:- Re z, 1:]) * [:-Re z, 1:]" by (metis \<open>[:- Re z, 1:] dvd p\<close> dvd_div_mult_self) ultimately show "P p" apply (subst 1) by (rule IH_real[OF 2]) next assume "Im z \<noteq> 0" hence hcnj: "cnj z \<noteq> z" by (metis cnj.simps(2) neg_equal_zero) have h2: "poly (map_poly of_real p) (cnj z) = 0" using h poly_map_poly_of_real_cnj by force have "[:-z, 1:] * [:-cnj z, 1:] dvd map_poly of_real p" proof (rule divides_mult) have "\<And>c. c dvd [:-z, 1:] \<Longrightarrow> c dvd [:- cnj z, 1:] \<Longrightarrow> is_unit c" proof - fix c assume h:"c dvd [:-z, 1:]" hence "degree c \<le> 1" using divides_degree by fastforce hence "degree c = 0 \<or> degree c = 1" by linarith thus "c dvd [:- cnj z, 1:] \<Longrightarrow> is_unit c" proof assume "degree c = 0" moreover have "c \<noteq> 0" using h by fastforce ultimately show "is_unit c" by (simp add: is_unit_iff_degree) next assume hdeg: "degree c = 1" then obtain x where 1:"[:-z, 1:] = x*c" using h by fastforce hence "degree [:-z, 1:] = degree x + degree c" by (metis add.inverse_neutral degree_mult_eq mult_cancel_right mult_poly_0_left pCons_eq_0_iff zero_neq_neg_one) hence "degree x = 0" using hdeg by auto then obtain x' where 2: "x = [:x':]" using degree_0_iff by auto assume "c dvd [:-cnj z, 1:]" then obtain y where 3: "[:-cnj z, 1:] = y*c" by fastforce hence "degree [:-cnj z, 1:] = degree y + degree c" by (metis add.inverse_neutral degree_mult_eq mult_cancel_right mult_poly_0_left pCons_eq_0_iff zero_neq_neg_one) hence "degree y = 0" using hdeg by auto then obtain y' where 4: "y = [:y':]" using degree_0_iff by auto moreover from hdeg obtain a b where 5:"c = [:a, b:]" and 6: "b \<noteq> 0" by (meson degree_eq_oneE) from 1 2 5 6 have "x' = inverse b" by (auto simp: field_simps) moreover from 3 4 5 6 have "y' = inverse b" by (auto simp: field_simps) ultimately have "x = y" using 2 4 by presburger then have "z = cnj z" using 1 3 by (metis neg_equal_iff_equal pCons_eq_iff) thus "is_unit c" using hcnj by argo qed qed thus "coprime [:- z, 1:] [:- cnj z, 1:]" by (meson not_coprimeE) show "[:- z, 1:] dvd map_poly complex_of_real p" using h poly_eq_0_iff_dvd by auto show "[:- cnj z, 1:] dvd map_poly complex_of_real p" using h2 poly_eq_0_iff_dvd by blast qed moreover have "[:- z, 1:] * [:- cnj z, 1:] = map_poly of_real [:Re z*Re z + Im z*Im z, -2*Re z, 1:]" by (auto simp: complex_eqI) ultimately have hdvd: "map_poly complex_of_real [:Re z*Re z + Im z*Im z, -2*Re z, 1:] dvd map_poly complex_of_real p" by force hence "[:Re z*Re z + Im z*Im z, -2*Re z, 1:] dvd p" using map_poly_dvd by blast hence 2:"P (p div [:Re z*Re z + Im z*Im z, -2*Re z, 1:])" apply (subst IH) using hdeg by (auto simp: degree_div) moreover have 1: "p = (p div [:Re z*Re z + Im z*Im z, -2*Re z, 1:]) * [:Re z*Re z + Im z*Im z, -2*Re z, 1:]" apply (subst dvd_div_mult_self) using \<open>[:Re z*Re z + Im z*Im z, -2*Re z, 1:] dvd p\<close> by auto ultimately show "P p" apply (subst 1) apply (rule IH_complex[of "Im z" _ "Re z"]) apply (meson \<open>Im z \<noteq> 0\<close>) by blast qed qed qed subsection \<open>The reciprocal polynomial\<close> definition reciprocal_poly :: "nat \<Rightarrow> 'a::zero poly \<Rightarrow> 'a poly" where "reciprocal_poly p P = Poly (rev ((coeffs P) @ (replicate (p - degree P) 0)))" lemma reciprocal_0: "reciprocal_poly p 0 = 0" by (simp add: reciprocal_poly_def) lemma reciprocal_1: "reciprocal_poly p 1 = monom 1 p" by (simp add: reciprocal_poly_def monom_altdef Poly_append) lemma coeff_reciprocal: assumes hi: "i \<le> p" and hP: "degree P \<le> p" shows "coeff (reciprocal_poly p P) i = coeff P (p - i)" proof cases assume "i < p - degree P" hence "degree P < p - i" using hP by linarith thus "coeff (reciprocal_poly p P) i = coeff P (p - i)" by (auto simp: reciprocal_poly_def nth_default_append coeff_eq_0) next assume h: "\<not>i < p - degree P" show "coeff (reciprocal_poly p P) i = coeff P (p - i)" proof cases assume "P = 0" thus "coeff (reciprocal_poly p P) i = coeff P (p - i)" by (simp add: reciprocal_0) next assume hP': "P \<noteq> 0" have "degree P \<ge> p - i" using h hP by linarith moreover hence "(i - (p - degree P)) < length (rev (coeffs P))" using hP' hP hi by (auto simp: length_coeffs) thus "coeff (reciprocal_poly p P) i = coeff P (p - i)" by (auto simp: reciprocal_poly_def nth_default_append coeff_eq_0 hP hP' nth_default_nth rev_nth calculation coeffs_nth length_coeffs_degree) qed qed lemma coeff_reciprocal_less: assumes hn: "p < i" and hP: "degree P \<le> p" shows "coeff (reciprocal_poly p P) i = 0" proof cases assume "P = 0" thus ?thesis by (auto simp: reciprocal_0) next assume "P \<noteq> 0" thus ?thesis using hn by (auto simp: reciprocal_poly_def nth_default_append nth_default_eq_dflt_iff hP length_coeffs) qed lemma reciprocal_monom: assumes "n \<le> p" shows "reciprocal_poly p (monom a n) = monom a (p-n)" proof (cases "a=0") case True then show ?thesis by (simp add: reciprocal_0) next case False with \<open>n\<le>p\<close> show ?thesis apply (rule_tac poly_eqI) by (metis coeff_monom coeff_reciprocal coeff_reciprocal_less diff_diff_cancel diff_le_self lead_coeff_monom not_le_imp_less) qed lemma reciprocal_degree: "reciprocal_poly (degree P) P = reflect_poly P" by (auto simp add: reciprocal_poly_def reflect_poly_def) lemma degree_reciprocal: fixes P :: "('a::zero) poly" assumes hP: "degree P \<le> p" shows "degree (reciprocal_poly p P) \<le> p" proof (auto simp add: reciprocal_poly_def) have "degree (reciprocal_poly p P) \<le> length (replicate (p - degree P) (0::'a) @ rev (coeffs P))" by (metis degree_Poly reciprocal_poly_def rev_append rev_replicate) thus "degree (Poly (replicate (p - degree P) 0 @ rev (coeffs P))) \<le> p" by (smt Suc_le_mono add_Suc_right coeffs_Poly degree_0 hP le_SucE le_SucI le_add_diff_inverse2 le_zero_eq length_append length_coeffs_degree length_replicate length_rev length_strip_while_le reciprocal_0 reciprocal_poly_def rev_append rev_replicate) qed lemma reciprocal_0_iff: assumes hP: "degree P \<le> p" shows "(reciprocal_poly p P = 0) = (P = 0)" proof assume h: "reciprocal_poly p P = 0" show "P = 0" proof (rule poly_eqI) fix n show "coeff P n = coeff 0 n" proof cases assume hn: "n \<le> p" hence "p - n \<le> p" by auto hence "coeff (reciprocal_poly p P) (p - n) = coeff P n" using hP hn by (auto simp: coeff_reciprocal) thus ?thesis using h by auto next assume hn: "\<not> n \<le> p" thus ?thesis using hP by (metis coeff_0 dual_order.trans le_degree) qed qed next assume "P = 0" thus "reciprocal_poly p P = 0" using reciprocal_0 by fast qed lemma poly_reciprocal: fixes P::"'a::field poly" assumes hp: "degree P \<le> p" and hx: "x \<noteq> 0" shows "poly (reciprocal_poly p P) x = x^p * (poly P (inverse x))" proof - have "poly (reciprocal_poly p P) x = poly ((Poly ((replicate (p - degree P) 0) @ rev (coeffs P)))) x" by (auto simp add: hx reflect_poly_def reciprocal_poly_def) also have "... = poly ((monom 1 (p - degree P)) * (reflect_poly P)) x" by (auto simp add: reflect_poly_def Poly_append) also have "... = x^(p - degree P) * x ^ degree P * poly P (inverse x)" by (auto simp add: poly_reflect_poly_nz poly_monom hx) also have "... = x^p * poly P (inverse x)" by (auto simp add: hp power_add[symmetric]) finally show ?thesis . qed lemma reciprocal_fcompose: fixes P::"('a::{ring_char_0,field}) poly" assumes hP: "degree P \<le> p" shows "reciprocal_poly p P = monom 1 (p - degree P) * fcompose P 1 [:0, 1:]" proof (rule poly_eq_by_eval, cases) fix x::'a assume hx: "x = 0" hence "poly (reciprocal_poly p P) x = coeff P p" using hP by (auto simp: poly_0_coeff_0 coeff_reciprocal) moreover have "poly (monom 1 (p - degree P) * fcompose P 1 [:0, 1:]) x = coeff P p" proof cases assume "degree P = p" thus ?thesis apply (induction P arbitrary: p) using hx by (auto simp: poly_monom degree_0_iff fcompose_pCons) next assume "degree P \<noteq> p" hence "degree P < p" using hP by auto thus ?thesis using hx by (auto simp: poly_monom coeff_eq_0) qed ultimately show "poly (reciprocal_poly p P) x = poly (monom 1 (p - degree P) * fcompose P 1 [:0, 1:]) x" by presburger next fix x::'a assume "x \<noteq> 0" thus "poly (reciprocal_poly p P) x = poly (monom 1 (p - degree P) * fcompose P 1 [:0, 1:]) x" using hP by (auto simp: poly_reciprocal poly_fcompose inverse_eq_divide poly_monom power_diff) qed lemma reciprocal_reciprocal: fixes P :: "'a::{field,ring_char_0} poly" assumes hP: "degree P \<le> p" shows "reciprocal_poly p (reciprocal_poly p P) = P" proof (rule poly_eq_by_eval) fix x show "poly (reciprocal_poly p (reciprocal_poly p P)) x = poly P x" proof cases assume "x = 0" thus "poly (reciprocal_poly p (reciprocal_poly p P)) x = poly P x" using hP by (auto simp: poly_0_coeff_0 coeff_reciprocal degree_reciprocal) next assume hx: "x \<noteq> 0" hence "poly (reciprocal_poly p (reciprocal_poly p P)) x = x ^ p * (inverse x ^ p * poly P x)" using hP by (auto simp: poly_reciprocal degree_reciprocal) thus "poly (reciprocal_poly p (reciprocal_poly p P)) x = poly P x" using hP hx left_right_inverse_power right_inverse by auto qed qed lemma reciprocal_smult: fixes P :: "'a::idom poly" assumes h: "degree P \<le> p" shows "reciprocal_poly p (smult n P) = smult n (reciprocal_poly p P)" proof cases assume "n = 0" thus ?thesis by (auto simp add: reciprocal_poly_def) next assume "n \<noteq> 0" thus ?thesis by (auto simp add: reciprocal_poly_def smult_Poly coeffs_smult rev_map[symmetric]) qed lemma reciprocal_add: fixes P Q :: "'a::comm_semiring_0 poly" assumes "degree P \<le> p" and "degree Q \<le> p" shows "reciprocal_poly p (P + Q) = reciprocal_poly p P + reciprocal_poly p Q" (is "?L = ?R") proof (rule poly_eqI, cases) fix n assume "n \<le> p" then show "coeff ?L n = coeff ?R n" using assms by (auto simp: degree_add_le coeff_reciprocal) next fix n assume "\<not>n \<le> p" then show "coeff ?L n = coeff ?R n" using assms by (auto simp: degree_add_le coeff_reciprocal_less) qed lemma reciprocal_diff: fixes P Q :: "'a::comm_ring poly" assumes "degree P \<le> p" and "degree Q \<le> p" shows "reciprocal_poly p (P - Q) = reciprocal_poly p P - reciprocal_poly p Q" by (metis (no_types, lifting) ab_group_add_class.ab_diff_conv_add_uminus assms add_diff_cancel degree_add_le degree_minus diff_add_cancel reciprocal_add) lemma reciprocal_sum: fixes P :: "'a \<Rightarrow> 'b::comm_semiring_0 poly" assumes hP: "\<And>k. degree (P k) \<le> p" shows "reciprocal_poly p (\<Sum>k\<in>A. P k) = (\<Sum>k\<in>A. reciprocal_poly p (P k))" proof (induct A rule: infinite_finite_induct) case (infinite A) then show ?case by (simp add: reciprocal_0) next case empty then show ?case by (simp add: reciprocal_0) next case (insert x F) assume "x \<notin> F" and "reciprocal_poly p (sum P F) = (\<Sum>k\<in>F. reciprocal_poly p (P k))" and "finite F" moreover hence "reciprocal_poly p (sum P (insert x F)) = reciprocal_poly p (P x) + reciprocal_poly p (sum P F)" by (auto simp add: reciprocal_add hP degree_sum_le) ultimately show "reciprocal_poly p (sum P (insert x F)) = (\<Sum>k\<in>insert x F. reciprocal_poly p (P k))" by (auto simp: Groups_Big.comm_monoid_add_class.sum.insert_if) qed lemma reciprocal_mult: fixes P Q::"'a::{ring_char_0,field} poly" assumes "degree (P * Q) \<le> p" and "degree P \<le> p" and "degree Q \<le> p" shows "monom 1 p * reciprocal_poly p (P * Q) = reciprocal_poly p P * reciprocal_poly p Q" proof (cases "P=0 \<or> Q=0") case True then show ?thesis using assms(1) by (auto simp: reciprocal_fcompose fcompose_mult) next case False then show ?thesis using assms by (auto simp: degree_mult_eq mult_monom reciprocal_fcompose fcompose_mult) qed lemma reciprocal_reflect_poly: fixes P::"'a::{ring_char_0,field} poly" assumes hP: "degree P \<le> p" shows "reciprocal_poly p P = monom 1 (p - degree P) * reflect_poly P" proof (rule poly_eqI) fix n show "coeff (reciprocal_poly p P) n = coeff (monom 1 (p - degree P) * reflect_poly P) n" proof cases assume "n \<le> p" thus ?thesis using hP by (auto simp: coeff_reciprocal coeff_monom_mult coeff_reflect_poly coeff_eq_0) next assume "\<not> n \<le> p" thus ?thesis using hP by (auto simp: coeff_reciprocal_less coeff_monom_mult coeff_reflect_poly) qed qed lemma map_poly_reciprocal: assumes "degree P \<le> p" and "f 0 = 0" shows "map_poly f (reciprocal_poly p P) = reciprocal_poly p (map_poly f P)" proof (rule poly_eqI) fix n show "coeff (map_poly f (reciprocal_poly p P)) n = coeff (reciprocal_poly p (map_poly f P)) n" proof (cases "n\<le>p") case True then show ?thesis apply (subst coeff_reciprocal[OF True]) subgoal by (meson assms(1) assms(2) degree_map_poly_le le_trans) by (simp add: assms(1) assms(2) coeff_map_poly coeff_reciprocal) next case False then show ?thesis by (metis assms(1) assms(2) coeff_map_poly coeff_reciprocal_less degree_map_poly_le dual_order.trans leI) qed qed subsection \<open>More about @{term proots_count}\<close> lemma proots_count_monom: assumes "0 \<notin> A" shows "proots_count (monom 1 d) A = 0" using assms by (auto simp: proots_count_def poly_monom) lemma proots_count_reciprocal: fixes P::"'a::{ring_char_0,field} poly" assumes hP: "degree P \<le> p" and h0: "P \<noteq> 0" and h0': "0 \<notin> A" shows "proots_count (reciprocal_poly p P) A = proots_count P {x. inverse x \<in> A}" proof - have "proots_count (reciprocal_poly p P) A = proots_count (fcompose P 1 [:0, 1:]) A" apply (subst reciprocal_fcompose[OF hP], subst proots_count_times) subgoal using h0 by (metis hP reciprocal_0_iff reciprocal_fcompose) subgoal using h0' by (auto simp: proots_count_monom) done also have "... = proots_count P {x. inverse x \<in> A}" proof (rule proots_fcompose_bij_eq[symmetric]) show "bij_betw (\<lambda>x. poly 1 x / poly [:0, 1:] x) A {x. inverse x \<in> A}" proof (rule bij_betw_imageI) show "inj_on (\<lambda>x. poly 1 x / poly [:0, 1:] x) A" by (simp add: inj_on_def) show "(\<lambda>x. poly 1 x / poly [:0, 1:] x) ` A = {x. inverse x \<in> A}" proof show "(\<lambda>x. poly 1 x / poly [:0, 1:] x) ` A \<subseteq> {x. inverse x \<in> A}" by force show "{x. inverse x \<in> A} \<subseteq> (\<lambda>x. poly 1 x / poly [:0, 1:] x) ` A" proof fix x assume "x \<in> {x::'a. inverse x \<in> A}" hence "x = poly 1 (inverse x) / poly [:0, 1:] (inverse x) \<and> inverse x \<in> A" by (auto simp: inverse_eq_divide) thus "x \<in> (\<lambda>x. poly 1 x / poly [:0, 1:] x) ` A" by blast qed qed qed next show "\<forall>c. 1 \<noteq> smult c [:0, 1:]" by (metis coeff_pCons_0 degree_1 lead_coeff_1 pCons_0_0 pcompose_0' pcompose_smult smult_0_right zero_neq_one) qed (auto simp: assms infinite_UNIV_char_0) finally show ?thesis by linarith qed lemma proots_count_reciprocal': fixes P::"real poly" assumes hP: "degree P \<le> p" and h0: "P \<noteq> 0" shows "proots_count P {x. 0 < x \<and> x < 1} = proots_count (reciprocal_poly p P) {x. 1 < x}" proof (subst proots_count_reciprocal) show "proots_count P {x. 0 < x \<and> x < 1} = proots_count P {x. inverse x \<in> Collect ((<) 1)}" apply (rule arg_cong[of _ _ "proots_count P"]) using one_less_inverse_iff by fastforce qed (use assms in auto) lemma proots_count_pos: assumes "proots_count P S > 0" shows "\<exists>x \<in> S. poly P x = 0" proof (rule ccontr) assume "\<not> (\<exists>x\<in>S. poly P x = 0)" hence "\<And>x. x \<in> S \<Longrightarrow> poly P x \<noteq> 0" by blast hence "\<And>x. x \<in> S \<Longrightarrow> order x P = 0" using order_0I by blast hence "proots_count P S = 0" by (force simp: proots_count_def) thus False using assms by presburger qed lemma proots_count_of_root_set: assumes "P \<noteq> 0" "R \<subseteq> S" and "\<And>x. x\<in>R \<Longrightarrow> poly P x = 0" shows "proots_count P S \<ge> card R" proof - have "card R \<le> card (proots_within P S)" apply (rule card_mono) subgoal using assms by auto subgoal using assms(2) assms(3) by (auto simp: proots_within_def) done also have "... \<le> proots_count P S" by (rule card_proots_within_leq[OF assms(1)]) finally show ?thesis . qed lemma proots_count_of_root: assumes "P \<noteq> 0" "x\<in>S" "poly P x = 0" shows "proots_count P S > 0" using proots_count_of_root_set[of P "{x}" S] assms by force subsection \<open>More about @{term changes}\<close> lemma changes_nonneg: "0 \<le> changes xs" apply (induction xs rule: changes.induct) by simp_all lemma changes_replicate_0: shows "changes (replicate n 0) = 0" apply (induction n) by auto lemma changes_append_replicate_0: "changes (xs @ replicate n 0) = changes xs" proof (induction xs rule: changes.induct) case (2 uu) then show ?case apply (induction n) by auto qed (auto simp: changes_replicate_0) lemma changes_scale_Cons: fixes xs:: "real list" assumes hs: "s > 0" shows "changes (s * x # xs) = changes (x # xs)" apply (induction xs rule: changes.induct) using assms by (auto simp: mult_less_0_iff zero_less_mult_iff) lemma changes_scale: fixes xs::"('a::linordered_idom) list" assumes hs: "\<And>i. i < n \<Longrightarrow> s i > 0" and hn: "length xs \<le> n" shows "changes [s i * (nth_default 0 xs i). i \<leftarrow> [0..<n]] = changes xs" using assms proof (induction xs arbitrary: s n rule: changes.induct) case 1 show ?case by (auto simp: map_replicate_const changes_replicate_0) next case (2 uu) show ?case proof (cases n) case 0 then show ?thesis by force next case (Suc m) hence "map (\<lambda>i. s i * nth_default 0 [uu] i) [0..<n] = [s 0 * uu] @ replicate m 0" proof (induction m arbitrary: n) case (Suc m n) from Suc have "map (\<lambda>i. s i * nth_default 0 [uu] i) [0..<Suc m] = [s 0 * uu] @ replicate m 0" by meson hence "map (\<lambda>i. s i * nth_default 0 [uu] i) [0..<n] = [s 0 * uu] @ replicate m 0 @ [0]" using Suc by auto also have "... = [s 0 * uu] @ replicate (Suc m) 0" by (simp add: replicate_append_same) finally show ?case . qed fastforce then show ?thesis by (metis changes.simps(2) changes_append_replicate_0) qed next case (3 a b xs s n) obtain m where hn: "n = m + 2" using 3(5) by (metis add_2_eq_Suc' diff_diff_cancel diff_le_self length_Suc_conv nat_arith.suc1 ordered_cancel_comm_monoid_diff_class.add_diff_inverse) hence h: "map (\<lambda>i. s i * nth_default 0 (a # b # xs) i) [0..<n] = s 0 * a # s 1 * b # map (\<lambda>i. (\<lambda> i. s (i+2)) i * nth_default 0 (xs) i) [0..<m]" apply (induction m arbitrary: n) by auto consider (neg)"a*b<0" | (nil)"b=0" | (pos)"\<not>a*b<0 \<and> \<not>b=0" by linarith then show ?case proof (cases) case neg hence "changes (map (\<lambda>i. s i * nth_default 0 (a # b # xs) i) [0..<n]) = 1 + changes (s 1 * b # map (\<lambda>i. (\<lambda> i. s (i+2)) i * nth_default 0 (xs) i) [0..<m])" apply (subst h) using 3(4)[of 0] 3(4)[of 1] hn by (metis (no_types, lifting) changes.simps(3) mult_less_0_iff pos2 mult_pos_pos one_less_numeral_iff semiring_norm(76) trans_less_add2) also have "... = 1 + changes (map (\<lambda>i. s (Suc i) * nth_default 0 (b # xs) i) [0..<Suc m])" apply (rule arg_cong[of _ _ "\<lambda> x. 1 + changes x"]) apply (induction m) by auto also have "... = changes (a # b # xs)" apply (subst 3(1)[OF neg]) using 3 neg hn by auto finally show ?thesis . next case nil hence "changes (map (\<lambda>i. s i * nth_default 0 (a # b # xs) i) [0..<n]) = changes (s 0 * a # map (\<lambda>i. (\<lambda> i. s (i+2)) i * nth_default 0 (xs) i) [0..<m])" apply (subst h) using 3(4)[of 0] 3(4)[of 1] hn by auto also have "... = changes (map (\<lambda>i. s (if i = 0 then 0 else Suc i) * nth_default 0 (a # xs) i) [0..<Suc m])" apply (rule arg_cong[of _ _ "\<lambda> x. changes x"]) apply (induction m) by auto also have "... = changes (a # b # xs)" apply (subst 3(2)) using 3 nil hn by auto finally show ?thesis . next case pos hence "changes (map (\<lambda>i. s i * nth_default 0 (a # b # xs) i) [0..<n]) = changes (s 1 * b # map (\<lambda>i. (\<lambda> i. s (i+2)) i * nth_default 0 (xs) i) [0..<m])" apply (subst h) using 3(4)[of 0] 3(4)[of 1] hn by (metis (no_types, lifting) changes.simps(3) divisors_zero mult_less_0_iff nat_1_add_1 not_square_less_zero one_less_numeral_iff semiring_norm(76) trans_less_add2 zero_less_mult_pos zero_less_two) also have "... = changes (map (\<lambda>i. s (Suc i) * nth_default 0 (b # xs) i) [0..<Suc m])" apply (rule arg_cong[of _ _ "\<lambda> x. changes x"]) apply (induction m) by auto also have "... = changes (a # b # xs)" apply (subst 3(3)) using 3 pos hn by auto finally show ?thesis . qed qed lemma changes_scale_const: fixes xs::"'a::linordered_idom list" assumes hs: "s \<noteq> 0" shows "changes (map ((*) s) xs) = changes xs" apply (induction xs rule: changes.induct) apply (simp, force) using hs by (auto simp: mult_less_0_iff zero_less_mult_iff) lemma changes_snoc: fixes xs::"'a::linordered_idom list" shows "changes (xs @ [b, a]) = (if a * b < 0 then 1 + changes (xs @ [b]) else if b = 0 then changes (xs @ [a]) else changes (xs @ [b]))" apply (induction xs rule: changes.induct) subgoal by (force simp: mult_less_0_iff) subgoal by (force simp: mult_less_0_iff) subgoal by force done lemma changes_rev: fixes xs:: "'a::linordered_idom list" shows "changes (rev xs) = changes xs" apply (induction xs rule: changes.induct) by (auto simp: changes_snoc) lemma changes_rev_about: fixes xs:: "'a::linordered_idom list" shows "changes (replicate (p - length xs) 0 @ rev xs) = changes xs" proof (induction p) case (Suc p) then show ?case proof cases assume "\<not>Suc p \<le> length xs" hence "Suc p - length xs = Suc (p - length xs)" by linarith thus ?case using Suc.IH changes_rev by auto qed (auto simp: changes_rev) qed (auto simp: changes_rev) lemma changes_add_between: assumes "a \<le> x" and "x \<le> b" shows "changes (as @ [a, b] @ bs) = changes (as @ [a, x, b] @ bs)" proof (induction as rule: changes.induct) case 1 then show ?case using assms apply (induction bs) by (auto simp: mult_less_0_iff) next case (2 c) then show ?case apply (induction bs) using assms by (auto simp: mult_less_0_iff) next case (3 y z as) then show ?case using assms by (auto simp: mult_less_0_iff) qed lemma changes_all_nonneg: assumes "\<And>i. nth_default 0 xs i \<ge> 0" shows "changes xs = 0" using assms proof (induction xs rule: changes.induct) case (3 x1 x2 xs) moreover assume "(\<And>i. 0 \<le> nth_default 0 (x1 # x2 # xs) i)" moreover hence "(\<And>i. 0 \<le> nth_default 0 (x1 # xs) i)" and "(\<And>i. 0 \<le> nth_default 0 (x2 # xs) i)" and "x1 * x2 \<ge> 0" proof - fix i assume h:"(\<And>i. 0 \<le> nth_default 0 (x1 # x2 # xs) i)" show "0 \<le> nth_default 0 (x1 # xs) i" proof (cases i) case 0 then show ?thesis using h[of 0] by force next case (Suc nat) then show ?thesis using h[of "Suc (Suc nat)"] by force qed show "0 \<le> nth_default 0 (x2 # xs) i" using h[of "Suc i"] by simp show "x1*x2 \<ge> 0" using h[of 0] h[of 1] by simp qed ultimately show ?case by auto qed auto lemma changes_pCons: "changes (coeffs (pCons 0 f)) = changes (coeffs f)" by (auto simp: cCons_def) lemma changes_increasing: assumes "\<And>i. i < length xs - 1 \<Longrightarrow> xs ! (i + 1) \<ge> xs ! i" and "length xs > 1" and "hd xs < 0" and "last xs > 0" shows "changes xs = 1" using assms proof (induction xs rule:changes.induct) case (3 x y xs) consider (neg)"x*y<0" | (nil)"y=0" | (pos)"\<not>x*y<0 \<and> \<not>y=0" by linarith then show ?case proof cases case neg have "changes (y # xs) = 0" proof (rule changes_all_nonneg) fix i show "0 \<le> nth_default 0 (y # xs) i" proof (cases "i < length (y # xs)") case True then show ?thesis using 3(4)[of i] apply (induction i) subgoal using 3(6) neg by (fastforce simp: mult_less_0_iff) subgoal using 3(4) by (auto simp: nth_default_def) done next case False then show ?thesis by (simp add: nth_default_def) qed qed thus "changes (x # y # xs) = 1" using neg by force next case nil hence "xs \<noteq> []" using 3(7) by force have h: "\<And>i. i < length (x # xs) - 1 \<Longrightarrow> (x # xs) ! i \<le> (x # xs) ! (i + 1)" proof - fix i assume "i < length (x # xs) - 1" thus "(x # xs) ! i \<le> (x # xs) ! (i + 1)" apply (cases "i = 0") subgoal using 3(4)[of 0] 3(4)[of 1] \<open>xs \<noteq> []\<close> by force using 3(4)[of "i+1"] by simp qed have "changes (x # xs) = 1" apply (rule 3(2)) using nil h \<open>xs \<noteq> []\<close> 3(6) 3(7) by auto thus ?thesis using nil by force next case pos hence "xs \<noteq> []" using 3(6) 3(7) by (fastforce simp: mult_less_0_iff) have "changes (y # xs) = 1" proof (rule 3(3)) show "\<not> x * y < 0" "y \<noteq> 0" using pos by auto show "\<And>i. i < length (y # xs) - 1 \<Longrightarrow> (y # xs) ! i \<le> (y # xs) ! (i + 1)" using 3(4) by force show "1 < length (y # xs)" using \<open>xs \<noteq> []\<close> by force show "hd (y # xs) < 0" using 3(6) pos by (force simp: mult_less_0_iff) show "0 < last (y # xs)" using 3(7) by force qed thus ?thesis using pos by auto qed qed auto end
{- Copyright 2018 Double-oxygeN Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -} module Partition %default total %access export -- define decreasing rule public export (>=) : Nat -> Nat -> Type (>=) = GTE public export data IsDecreasing : List Nat -> Type where DecEmpty : IsDecreasing Nil DecSingle : (a: Nat) -> a >= 1 -> IsDecreasing (a :: Nil) DecMany : (a1: Nat) -> (a2: Nat) -> (ax: List Nat) -> a1 >= a2 -> IsDecreasing (a2 :: ax) -> IsDecreasing (a1 :: a2 :: ax) -- some theorems succDec : IsDecreasing (x :: xs) -> IsDecreasing ((S x) :: xs) succDec (DecSingle x proofXIsPositive) = DecSingle (S x) (lteSuccRight proofXIsPositive) succDec (DecMany x y ys proofXGteY proofYYsIsDec) = DecMany (S x) y ys (lteSuccRight proofXGteY) proofYYsIsDec -- define partition namespace Partition public export data Par : Type where MkPar : (ls: List Nat) -> IsDecreasing ls -> Par ParNil : Par ParNil = MkPar Nil DecEmpty -- partition utility functions toList : Par -> List Nat toList (MkPar ls _) = ls index : (n: Nat) -> (l: Par) -> {auto ok: InBounds n (toList l)} -> Nat index n l = Prelude.List.index n (Partition.toList l) length : Par -> Nat length l = length $ toList l multiplicity : Nat -> Par -> Nat multiplicity e l = length $ elemIndices e (toList l) tail : Par -> Par tail (MkPar Nil _) = ParNil tail (MkPar (x :: Nil) _) = ParNil tail (MkPar (x :: y :: ys) (DecMany x y ys _ proofYYsIsDec)) = (MkPar (y :: ys) proofYYsIsDec) sizePar : Par -> Nat sizePar (MkPar Nil _) = Z sizePar (MkPar (x :: Nil) (DecSingle _ _)) = x sizePar (MkPar (x :: y :: ys) (DecMany x y ys proofXGteY proofYYsIsDec)) = x + sizePar (assert_smaller (MkPar (x :: y :: ys) (DecMany x y ys proofXGteY proofYYsIsDec)) (MkPar (y :: ys) proofYYsIsDec)) Show Par where show l = "(" ++ (join "," (toList l)) ++ ")" where join : (Show a) => String -> List a -> String join _ Nil = "" join _ (x :: Nil) = show x join s (x :: xs) = (show x) ++ s ++ (join s xs) -- define partition of size N public export data ParN : Nat -> Type where MkParN : (l: Par) -> sizePar l = n -> ParN n -- partition with limit data ParUpper : Nat -> Type where MkParUpper : (k: Nat) -> (ls: List Nat) -> IsDecreasing (k :: ls) -> ParUpper k forgetUpper : ParUpper k -> Par forgetUpper (MkParUpper k Nil _) = ParNil forgetUpper (MkParUpper k _ (DecMany _ x xs _ proofXXsIsDec)) = MkPar (x :: xs) proofXXsIsDec parUpperKIsParUpperSuccK : ParUpper k -> ParUpper (S k) parUpperKIsParUpperSuccK (MkParUpper k ls proofKLsIsDec) = MkParUpper (S k) ls (succDec proofKLsIsDec) parUpperCons : (k1: Nat) -> k1 >= k2 -> ParUpper k2 -> ParUpper k1 parUpperCons k1 proofK1GteK2 (MkParUpper k2 ls proofK2LsIsDec) = case proofK2LsIsDec of DecSingle _ proofK2IsPos => MkParUpper k1 [k1] (DecMany k1 k1 [] lteRefl (DecSingle k1 (lteTransitive proofK2IsPos proofK1GteK2))) DecMany _ y ys proofK2GteY proofYYsIsDec => MkParUpper k1 (k1 :: y :: ys) (DecMany k1 k1 (y :: ys) lteRefl (DecMany k1 y ys (lteTransitive proofK2GteY proofK1GteK2) proofYYsIsDec)) -- get all Par(N) naiveAllParNUpper : (k: Nat) -> Nat -> List (ParUpper k) naiveAllParNUpper Z _ = Nil naiveAllParNUpper (S k) Z = (MkParUpper (S k) Nil (DecSingle (S k) (LTESucc LTEZero))) :: Nil naiveAllParNUpper (S k) n with ((S k) <= n) | False = parUpperKIsParUpperSuccK <$> naiveAllParNUpper k n | True = ((parUpperCons (S k) lteRefl) <$> naiveAllParNUpper (S k) (assert_smaller n (n `minus` (S k)))) ++ (parUpperKIsParUpperSuccK <$> (naiveAllParNUpper k n)) naiveAllParN : Nat -> List Par naiveAllParN n = forgetUpper <$> naiveAllParNUpper n n
%function geyser ( ) %*****************************************************************************80 % %% GEYSER uses MATLAB to make a histogram. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 28 April 2011 % % Author: % % John Burkardt % % % Load the data. % t = load ( 'geyser.txt' ); % % Our data lies in the range 40 to 110. % Dividing into bins of width 5, we want 14 bins. % But that means 14+1 "edges". % bin_num = 14; bin_edges = linspace ( 40.0, 110.0, bin_num + 1 ); % % T_BINNED counts data between successive bin edges. % t_binned = histc ( t, bin_edges ); % % Discard the last entry, which counts data greater than the last bin edge. % t_binned = t_binned(1:bin_num); % % Set the average value of each bin. % bar_center = linspace ( ( bin_edges(1) + bin_edges(2) ) / 2, ... ( bin_edges(end-1) + bin_edges(end) ) / 2, ... bin_num ); % % Set the relative width of the bar. % bar_width = 0.90; % % Draw a bar graph. % bar ( bar_center, t_binned, bar_width, 'r' ); grid on title ( 'Time between eruptions of Old Faithful' ) xlabel ( 'Minutes' ) ylabel ( 'Frequency' ) % return %end
using PowerModelsReliability using PowerModels using InfrastructureModels using Ipopt using Mosek using Juniper using Cbc using CPLEX mosek = MosekSolver() ipopt = IpoptSolver() juniper = JuniperSolver(IpoptSolver(print_level=0); mip_solver=CplexSolver()) data_tf = PowerModels.parse_file("./test/data/case5_tf.m") data_tf["multinetwork"] = false data_tf["load"] = data_tf["tf_load"] resultDCunittf = run_unittfopf(data_tf, DCPPowerModel, mosek; multinetwork=false, setting = Dict("output" => Dict("branch_flows" => true),"relax_continuous" => true)) data_tf = PowerModels.parse_file("./test/data/case5_tf.m") data_tf["multinetwork"] = false data_tf["load"] = data_tf["tf_load"] resultACunittf = run_unittfopf(data_tf, ACPPowerModel, juniper; multinetwork=false, setting = Dict("output" => Dict("branch_flows" => true),"relax_continuous" => true))
--- author: Nathan Carter ([email protected]) --- This answer assumes you have imported SymPy as follows. ```python from sympy import * # load all math functions init_printing( use_latex='mathjax' ) # use pretty math output ``` You can define any number of variables as follows. Here we define $x$, $y$, and $z$. ```python var( 'x y z' ) ``` $\displaystyle \left( x, \ y, \ z\right)$ You can tell that they are variables, because when you ask Python to print them out, it does not print a value (such as a number) but rather just the symbol itself. ```python x ``` $\displaystyle x$ And when you use a symbol inside a larger formula, it doesn't attempt to compute a result, but stores the entire formula symbolically. ```python formula = sqrt(x) + 5 formula ``` $\displaystyle \sqrt{x} + 5$
lemma tendsto_null_sum: fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::topological_comm_monoid_add" assumes "\<And>i. i \<in> I \<Longrightarrow> ((\<lambda>x. f x i) \<longlongrightarrow> 0) F" shows "((\<lambda>i. sum (f i) I) \<longlongrightarrow> 0) F"
> module SimpleProb.MonadicProperties > import Data.List > import Data.List.Quantifiers > import Syntax.PreorderReasoning > import SimpleProb.SimpleProb > import SimpleProb.BasicOperations > import SimpleProb.BasicProperties > import SimpleProb.MonadicOperations > import NonNegRational.NonNegRational > import NonNegRational.BasicOperations > import NonNegRational.BasicProperties > import Nat.Positive > import Nat.Coprime > import Fraction.Normal > import Num.Refinements > import Num.Properties > import Fun.Operations > import List.Operations > import List.Properties > import Unique.Predicates > import Finite.Predicates > import Sigma.Sigma > %default total > %access public export > -- %access export > %auto_implicits off * Properties of |normalize|, |support| and |ret|: > ||| > normalizeRetLemma : {A : Type} -> (a : A) -> normalize (ret a) = ret a > normalizeRetLemma a = ( normalize (ret a) ) > ={ Refl }= > ( normalize (MkSimpleProb ((a, 1) :: Nil) (sumMapSndSingletonLemma a 1)) ) > ={ Refl }= > ( MkSimpleProb ((a, 1) :: Nil) (sumMapSndSingletonLemma a 1) ) > ={ Refl }= > ( ret a ) > QED > {- > normalizeRetLemma a = s9 where > s1 : normalize (ret a) = normalize (MkSimpleProb ((a, 1) :: Nil) (sumMapSndSingletonLemma a 1)) > s1 = Refl > s2 : normalize (MkSimpleProb ((a, 1) :: Nil) (sumMapSndSingletonLemma a 1)) > = > MkSimpleProb (discardBySndZero ((a, 1) :: Nil)) > (trans (discardBySndZeroLemma ((a, 1) :: Nil)) (sumMapSndSingletonLemma a 1)) > s2 = Refl > s3 : discardBySndZero ((a, 1) :: Nil) = (a, 1) :: Nil > s3 = discardBySndZeroLemma1 a 1 ?oneNotZero > s4 : discardBySndZeroLemma ((a, 1) :: Nil) = Refl {} {} {} > s4 = ?lika > s5 : MkSimpleProb (discardBySndZero ((a, 1) :: Nil)) > (trans (discardBySndZeroLemma ((a, 1) :: Nil)) (sumMapSndSingletonLemma a 1)) > = > MkSimpleProb ((a, 1) :: Nil) (trans Refl (sumMapSndSingletonLemma a 1)) > s5 = ?leka > s6 : MkSimpleProb ((a, 1) :: Nil) (trans Refl (sumMapSndSingletonLemma a 1)) > = > MkSimpleProb ((a, 1) :: Nil) (sumMapSndSingletonLemma a 1) > s6 = Refl > s7 : MkSimpleProb ((a, 1) :: Nil) (sumMapSndSingletonLemma a 1) = ret a > s7 = Refl > s9 : normalize (ret a) = ret a > s9 = trans s1 (trans s2 (trans s5 (trans s6 s7))) > -} > ||| > supportRetLemma : {A : Type} -> > (a : A) -> support (SimpleProb.MonadicOperations.ret a) = List.Operations.ret a > supportRetLemma a = ( support (SimpleProb.MonadicOperations.ret a) ) > ={ Refl }= > ( map fst (toList (normalize (SimpleProb.MonadicOperations.ret a))) ) > ={ cong {f = \ X => map Prelude.Basics.fst (toList X)} (normalizeRetLemma a) }= > ( map fst (toList (SimpleProb.MonadicOperations.ret a)) ) > ={ Refl }= > ( map fst (toList (MkSimpleProb ((a, 1) :: Nil) (sumMapSndSingletonLemma a 1))) ) > ={ Refl }= > ( map fst ((a, 1) :: Nil) ) > ={ Refl }= > ( a :: Nil ) > ={ Refl }= > ( List.Operations.ret a ) > QED * |SimpleProb| is a container monad: > ||| > elemNonEmptySpec0 : {A : Type} -> > (a : A) -> (sp : SimpleProb A) -> > a `Elem` sp -> SimpleProb.MonadicOperations.NonEmpty sp > elemNonEmptySpec0 {A} a sp aesp = List.Properties.elemNonEmptySpec0 a (support sp) aesp > ||| > elemNonEmptySpec1 : {A : Type} -> > (sp : SimpleProb A) -> > SimpleProb.MonadicOperations.NonEmpty sp -> Sigma A (\ a => a `Elem` sp) > elemNonEmptySpec1 {A} sp nesp = List.Properties.elemNonEmptySpec1 (support sp) nesp > ||| > containerMonadSpec1 : {A : Type} -> {a : A} -> a `SimpleProb.MonadicOperations.Elem` (ret a) > containerMonadSpec1 {A} {a} = s3 where > s1 : a `Data.List.Elem` (List.Operations.ret a) > s1 = List.Properties.containerMonadSpec1 > s2 : a `Data.List.Elem` (support (SimpleProb.MonadicOperations.ret a)) > s2 = replace {P = \ X => a `Data.List.Elem` X} (sym (supportRetLemma a)) s1 > s3 : a `SimpleProb.MonadicOperations.Elem` (ret a) > s3 = s2 > ||| > containerMonadSpec3 : {A : Type} -> {P : A -> Type} -> > (a : A) -> (sp : SimpleProb A) -> > All P sp -> a `Elem` sp -> P a > containerMonadSpec3 {A} {P} a sp allp elemp = List.Properties.containerMonadSpec3 a (support sp) allp elemp * Specific container monad properties > ||| > uniqueAllLemma : {A : Type} -> {P : A -> Type} -> > Unique1 P -> (sp : SimpleProb A) -> Unique (All P sp) > uniqueAllLemma u1P sp = List.Properties.uniqueAllLemma u1P (support sp) > ||| > finiteAll : {A : Type} -> {P : A -> Type} -> > Finite1 P -> (sp : SimpleProb A) -> Finite (All P sp) > finiteAll f1P sp = List.Properties.finiteAll f1P (support sp) > ||| All is decidable > decidableAll : {A : Type} -> {P : A -> Type} -> > (dec : (a : A) -> Dec (P a)) -> (sp : SimpleProb A) -> Dec (All P sp) > decidableAll dec sp = List.Properties.decidableAll dec (support sp) > ||| NotEmpty is finite > finiteNonEmpty : {A : Type} -> (sp : SimpleProb A) -> Finite (SimpleProb.MonadicOperations.NonEmpty sp) > finiteNonEmpty sp = List.Properties.finiteNonEmpty (support sp) > ||| NotEmpty is decidable > decidableNonEmpty : {A : Type} -> (sp : SimpleProb A) -> Dec (SimpleProb.MonadicOperations.NonEmpty sp) > decidableNonEmpty sp = List.Properties.decidableNonEmpty (support sp) * |SimpleProb|s are never empty > ||| > nonEmptyLemma1 : {A : Type} -> (sp : SimpleProb A) -> List.Operations.NonEmpty (toList sp) > nonEmptyLemma1 {A} (MkSimpleProb Nil s1p) = void s9 where > s1 : sumMapSnd {A = A} {B = NonNegRational} Nil = 0 > s1 = sumMapSndNilLemma {A = A} {B = NonNegRational} > s2 : sumMapSnd {A = A} {B = NonNegRational} Nil = 1 > s2 = s1p > s3 : (=) {A = NonNegRational} {B = NonNegRational} 1 0 > s3 = trans (sym s2) s1 > s9 : Void > s9 = not1Eq0 s3 > nonEmptyLemma1 (MkSimpleProb (ap :: aps) s1p) = () > ||| > nonEmptyLemma : {A : Type} -> (sp : SimpleProb A) -> NonEmpty sp > nonEmptyLemma {A} sp = s4 where > s1 : List.Operations.NonEmpty (toList (normalize sp)) > s1 = nonEmptyLemma1 (normalize sp) > s2 : List.Operations.NonEmpty (map fst (toList (normalize sp))) > s2 = mapPreservesNonEmpty fst (toList (normalize sp)) s1 > s3 : List.Operations.NonEmpty (support sp) > s3 = s2 > s4 : NonEmpty sp > s4 = s3 > ||| > toListFmapLemma : {A, B : Type} -> > (f : A -> B) -> (sp : SimpleProb A) -> > toList (fmap f sp) = fmap (cross f id) (toList sp) > toListFmapLemma f (MkSimpleProb aps s1p) = > ( toList (fmap f (MkSimpleProb aps s1p)) ) > ={ Refl }= > ( toList (MkSimpleProb > (fmap (cross f id) aps) > (trans Refl (trans (cong (mapSndMapCrossAnyIdLemma f aps)) s1p))) ) > ={ Refl }= > ( fmap (cross f id) aps ) > ={ Refl }= > ( fmap (cross f id) (toList (MkSimpleProb aps s1p)) ) > QED > {- > ---}