Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit eb8b1b8

Browse files
committed
feat(linear_algebra/affine_space/barycentric_coords): characterise affine bases in terms of coordinate matrices (#10370)
Formalized as part of the Sphere Eversion project.
1 parent fb82d0a commit eb8b1b8

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

src/linear_algebra/affine_space/barycentric_coords.lean

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ begin
147147
exact b.coord_apply_combination_of_mem (finset.mem_univ i) hw,
148148
end
149149

150+
lemma ext_elem [fintype ι] {q₁ q₂ : P} (h : ∀ i, b.coord i q₁ = b.coord i q₂) : q₁ = q₂ :=
151+
begin
152+
rw [← b.affine_combination_coord_eq_self q₁, ← b.affine_combination_coord_eq_self q₂],
153+
simp only [h],
154+
end
155+
150156
@[simp] lemma coe_coord_of_subsingleton_eq_one [subsingleton ι] (i : ι) :
151157
(b.coord i : P → k) = 1 :=
152158
begin
@@ -203,7 +209,57 @@ begin
203209
rw [to_matrix_apply, coord_apply, matrix.one_eq_pi_single, pi.single_apply],
204210
end
205211

206-
variables [fintype ι] (b₂ : affine_basis ι k P)
212+
variables {ι' : Type*} [fintype ι'] [fintype ι] (b₂ : affine_basis ι k P)
213+
214+
lemma to_matrix_row_sum_one {ι' : Type*} (q : ι' → P) (i : ι') :
215+
∑ j, b.to_matrix q i j = 1 :=
216+
by simp
217+
218+
/-- Given a family of points `p : ι' → P` and an affine basis `b`, if the matrix whose rows are the
219+
coordinates of `p` with respect `b` has a right inverse, then `p` is affine independent. -/
220+
lemma affine_independent_of_to_matrix_right_inv [decidable_eq ι']
221+
(p : ι' → P) {A : matrix ι ι' k} (hA : (b.to_matrix p) ⬝ A = 1) : affine_independent k p :=
222+
begin
223+
rw affine_independent_iff_eq_of_fintype_affine_combination_eq,
224+
intros w₁ w₂ hw₁ hw₂ hweq,
225+
have hweq' : (b.to_matrix p).vec_mul w₁ = (b.to_matrix p).vec_mul w₂,
226+
{ ext j,
227+
change ∑ i, (w₁ i) • (b.coord j (p i)) = ∑ i, (w₂ i) • (b.coord j (p i)),
228+
rw [← finset.univ.affine_combination_eq_linear_combination _ _ hw₁,
229+
← finset.univ.affine_combination_eq_linear_combination _ _ hw₂,
230+
← finset.univ.map_affine_combination p w₁ hw₁,
231+
← finset.univ.map_affine_combination p w₂ hw₂, hweq], },
232+
replace hweq' := congr_arg (λ w, A.vec_mul w) hweq',
233+
simpa only [matrix.vec_mul_vec_mul, ← matrix.mul_eq_mul, hA, matrix.vec_mul_one] using hweq',
234+
end
235+
236+
/-- Given a family of points `p : ι' → P` and an affine basis `b`, if the matrix whose rows are the
237+
coordinates of `p` with respect `b` has a left inverse, then `p` spans the the entire space. -/
238+
lemma affine_span_eq_top_of_to_matrix_left_inv [decidable_eq ι] [nontrivial k]
239+
(p : ι' → P) {A : matrix ι ι' k} (hA : A ⬝ b.to_matrix p = 1) : affine_span k (range p) = ⊤ :=
240+
begin
241+
suffices : ∀ i, b.points i ∈ affine_span k (range p),
242+
{ rw [eq_top_iff, ← b.tot, affine_span_le],
243+
rintros q ⟨i, rfl⟩,
244+
exact this i, },
245+
intros i,
246+
have hAi : ∑ j, A i j = 1,
247+
{ calc ∑ j, A i j = ∑ j, (A i j) * ∑ l, b.to_matrix p j l : by simp
248+
... = ∑ j, ∑ l, (A i j) * b.to_matrix p j l : by simp_rw finset.mul_sum
249+
... = ∑ l, ∑ j, (A i j) * b.to_matrix p j l : by rw finset.sum_comm
250+
... = ∑ l, (A ⬝ b.to_matrix p) i l : rfl
251+
... = 1 : by simp [hA, matrix.one_apply, finset.filter_eq], },
252+
have hbi : b.points i = finset.univ.affine_combination p (A i),
253+
{ apply b.ext_elem,
254+
intros j,
255+
rw [b.coord_apply, finset.univ.map_affine_combination _ _ hAi,
256+
finset.univ.affine_combination_eq_linear_combination _ _ hAi],
257+
change _ = (A ⬝ b.to_matrix p) i j,
258+
simp_rw [hA, matrix.one_apply, @eq_comm _ i j],
259+
congr, },
260+
rw hbi,
261+
exact affine_combination_mem_affine_span hAi p,
262+
end
207263

208264
/-- A change of basis formula for barycentric coordinates.
209265
@@ -235,6 +291,20 @@ lemma is_unit_to_matrix :
235291
val_inv := b.to_matrix_mul_to_matrix b₂,
236292
inv_val := b₂.to_matrix_mul_to_matrix b, }, rfl⟩
237293

294+
lemma is_unit_to_matrix_iff [nontrivial k] (p : ι → P) :
295+
is_unit (b.to_matrix p) ↔ affine_independent k p ∧ affine_span k (range p) = ⊤ :=
296+
begin
297+
split,
298+
{ rintros ⟨⟨B, A, hA, hA'⟩, (rfl : B = b.to_matrix p)⟩,
299+
rw matrix.mul_eq_mul at hA hA',
300+
exact ⟨b.affine_independent_of_to_matrix_right_inv p hA,
301+
b.affine_span_eq_top_of_to_matrix_left_inv p hA'⟩, },
302+
{ rintros ⟨h_tot, h_ind⟩,
303+
let b' : affine_basis ι k P := ⟨p, h_tot, h_ind⟩,
304+
change is_unit (b.to_matrix b'.points),
305+
exact b.is_unit_to_matrix b', },
306+
end
307+
238308
end ring
239309

240310
section comm_ring

src/linear_algebra/affine_space/independent.lean

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,26 @@ begin
211211
simpa [w2] using hws }
212212
end
213213

214+
/-- A finite family is affinely independent if and only if any affine
215+
combinations (with sum of weights 1) that evaluate to the same point are equal. -/
216+
lemma affine_independent_iff_eq_of_fintype_affine_combination_eq [fintype ι] (p : ι → P) :
217+
affine_independent k p ↔ ∀ (w1 w2 : ι → k), ∑ i, w1 i = 1 → ∑ i, w2 i = 1
218+
finset.univ.affine_combination p w1 = finset.univ.affine_combination p w2 → w1 = w2 :=
219+
begin
220+
rw affine_independent_iff_indicator_eq_of_affine_combination_eq,
221+
split,
222+
{ intros h w1 w2 hw1 hw2 hweq,
223+
simpa only [set.indicator_univ, finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq, },
224+
{ intros h s1 s2 w1 w2 hw1 hw2 hweq,
225+
have hw1' : ∑ i, (s1 : set ι).indicator w1 i = 1,
226+
{ rwa set.sum_indicator_subset _ (finset.subset_univ s1) at hw1, },
227+
have hw2' : ∑ i, (s2 : set ι).indicator w2 i = 1,
228+
{ rwa set.sum_indicator_subset _ (finset.subset_univ s2) at hw2, },
229+
rw [finset.affine_combination_indicator_subset w1 p (finset.subset_univ s1),
230+
finset.affine_combination_indicator_subset w2 p (finset.subset_univ s2)] at hweq,
231+
exact h _ _ hw1' hw2' hweq, },
232+
end
233+
214234
variables {k}
215235

216236
/-- If we single out one member of an affine-independent family of points and affinely transport

0 commit comments

Comments
 (0)