Theorem: affineCombination_mem_affineSpan
File: Mathlib/LinearAlgebra/AffineSpace/Combination.lean

tactic: classical
  have hnz : (∑ i in s, w i) ≠ 0 := h.symm ▸ one_ne_zero
  have hn : s.Nonempty := Finset.nonempty_of_sum_ne_zero hnz
  cases' hn with i1 hi1
  let w1 : ι → k := Function.update (Function.const ι 0) i1 1
  have hw1 : (∑ i in s, w1 i) = 1 := by
    simp only [Pi.const_zero, Finset.sum_update_of_mem hi1, Pi.zero_apply,
        Finset.sum_const_zero, add_zero]
  have hw1s : s.affineCombination k p w1 = p i1 :=
    s.affineCombination_of_eq_one_of_eq_zero w1 p hi1 (Function.update_same _ _ _) fun _ _ hne =>
      Function.update_noteq hne _ _
  have hv : s.affineCombination k p w -ᵥ p i1 ∈ (affineSpan k (Set.range p)).direction := by
    rw [direction_affineSpan, ← hw1s, Finset.affineCombination_vsub]
    apply weightedVSub_mem_vectorSpan
    change (Finset.sum s fun i => w i - w1 i) = 0
    simp only [Finset.sum_sub_distrib, h, hw1, sub_self]
  rw [← vsub_vadd (s.affineCombination k p w) (p i1)]
  exact AffineSubspace.vadd_mem_of_mem_direction hv (mem_affineSpan k (Set.mem_range_self _))
state_before: k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
⊢ ↑(Finset.affineCombination k s p) w ∈ affineSpan k (Set.range p)

tactic: have hnz : (∑ i in s, w i) ≠ 0 := h.symm ▸ one_ne_zero
state_before: k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
⊢ ↑(Finset.affineCombination k s p) w ∈ affineSpan k (Set.range p)

tactic: have hn : s.Nonempty := Finset.nonempty_of_sum_ne_zero hnz
state_before: k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
⊢ ↑(Finset.affineCombination k s p) w ∈ affineSpan k (Set.range p)

tactic: cases' hn with i1 hi1
state_before: k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
hn : Finset.Nonempty s
⊢ ↑(Finset.affineCombination k s p) w ∈ affineSpan k (Set.range p)

tactic: let w1 : ι → k := Function.update (Function.const ι 0) i1 1
state_before: case intro
k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
⊢ ↑(Finset.affineCombination k s p) w ∈ affineSpan k (Set.range p)

tactic: have hw1 : (∑ i in s, w1 i) = 1 := by
  simp only [Pi.const_zero, Finset.sum_update_of_mem hi1, Pi.zero_apply,
      Finset.sum_const_zero, add_zero]
state_before: case intro
k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
⊢ ↑(Finset.affineCombination k s p) w ∈ affineSpan k (Set.range p)

tactic: have hw1s : s.affineCombination k p w1 = p i1 :=
  s.affineCombination_of_eq_one_of_eq_zero w1 p hi1 (Function.update_same _ _ _) fun _ _ hne =>
    Function.update_noteq hne _ _
state_before: case intro
k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
hw1 : ∑ i in s, w1 i = 1
⊢ ↑(Finset.affineCombination k s p) w ∈ affineSpan k (Set.range p)

tactic: have hv : s.affineCombination k p w -ᵥ p i1 ∈ (affineSpan k (Set.range p)).direction := by
  rw [direction_affineSpan, ← hw1s, Finset.affineCombination_vsub]
  apply weightedVSub_mem_vectorSpan
  change (Finset.sum s fun i => w i - w1 i) = 0
  simp only [Finset.sum_sub_distrib, h, hw1, sub_self]
state_before: case intro
k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i1
⊢ ↑(Finset.affineCombination k s p) w ∈ affineSpan k (Set.range p)

tactic: rw [← vsub_vadd (s.affineCombination k p w) (p i1)]
state_before: case intro
k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i1
hv : ↑(Finset.affineCombination k s p) w -ᵥ p i1 ∈ AffineSubspace.direction (affineSpan k (Set.range p))
⊢ ↑(Finset.affineCombination k s p) w ∈ affineSpan k (Set.range p)

tactic: exact AffineSubspace.vadd_mem_of_mem_direction hv (mem_affineSpan k (Set.mem_range_self _))
state_before: case intro
k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i1
hv : ↑(Finset.affineCombination k s p) w -ᵥ p i1 ∈ AffineSubspace.direction (affineSpan k (Set.range p))
⊢ ↑(Finset.affineCombination k s p) w -ᵥ p i1 +ᵥ p i1 ∈ affineSpan k (Set.range p)

tactic: simp only [Pi.const_zero, Finset.sum_update_of_mem hi1, Pi.zero_apply,
    Finset.sum_const_zero, add_zero]
state_before: k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
⊢ ∑ i in s, w1 i = 1

tactic: rw [direction_affineSpan, ← hw1s, Finset.affineCombination_vsub]
state_before: k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i1
⊢ ↑(Finset.affineCombination k s p) w -ᵥ p i1 ∈ AffineSubspace.direction (affineSpan k (Set.range p))

tactic: apply weightedVSub_mem_vectorSpan
state_before: k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i1
⊢ ↑(Finset.weightedVSub s p) (w - w1) ∈ vectorSpan k (Set.range p)

tactic: change (Finset.sum s fun i => w i - w1 i) = 0
state_before: case h
k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i1
⊢ ∑ i in s, (w - w1) i = 0

tactic: simp only [Finset.sum_sub_distrib, h, hw1, sub_self]
state_before: case h
k : Type u_2
V : Type u_4
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_1
inst✝ : Nontrivial k
s : Finset ι
w : ι → k
h : ∑ i in s, w i = 1
p : ι → P
hnz : ∑ i in s, w i ≠ 0
i1 : ι
hi1 : i1 ∈ s
w1 : ι → k := Function.update (Function.const ι 0) i1 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i1
⊢ ∑ i in s, (w i - w1 i) = 0