Theorem: Lagrange.interpolate_eq_sum_interpolate_insert_sdiff
File: Mathlib/LinearAlgebra/Lagrange.lean

tactic: symm
state_before: F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
⊢ ↑(interpolate t v) r = ∑ i in s, ↑(interpolate (insert i (t \ s)) v) r * Lagrange.basis s v i

tactic: refine' eq_interpolate_of_eval_eq _ hvt (lt_of_le_of_lt (degree_sum_le _ _) _) fun i hi => _
state_before: F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
⊢ ∑ i in s, ↑(interpolate (insert i (t \ s)) v) r * Lagrange.basis s v i = ↑(interpolate t v) r

tactic: simp_rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe t.card), degree_mul]
state_before: case refine'_1
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
⊢ (sup s fun b => degree (↑(interpolate (insert b (t \ s)) v) r * Lagrange.basis s v b)) < ↑(card t)

tactic: intro i hi
state_before: case refine'_1
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
⊢ ∀ (b : ι), b ∈ s → degree (↑(interpolate (insert b (t \ s)) v) r) + degree (Lagrange.basis s v b) < ↑(card t)

tactic: have hs : 1 ≤ s.card := Nonempty.card_pos ⟨_, hi⟩
state_before: case refine'_1
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ s
⊢ degree (↑(interpolate (insert i (t \ s)) v) r) + degree (Lagrange.basis s v i) < ↑(card t)

tactic: have hst' : s.card ≤ t.card := card_le_of_subset hst
state_before: case refine'_1
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs✝ : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ s
hs : 1 ≤ card s
⊢ degree (↑(interpolate (insert i (t \ s)) v) r) + degree (Lagrange.basis s v i) < ↑(card t)

tactic: have H : t.card = 1 + (t.card - s.card) + (s.card - 1) := by
  rw [add_assoc, tsub_add_tsub_cancel hst' hs, ← add_tsub_assoc_of_le (hs.trans hst'),
    Nat.succ_add_sub_one, zero_add]
state_before: case refine'_1
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs✝ : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ s
hs : 1 ≤ card s
hst' : card s ≤ card t
⊢ degree (↑(interpolate (insert i (t \ s)) v) r) + degree (Lagrange.basis s v i) < ↑(card t)

tactic: rw [degree_basis (Set.InjOn.mono hst hvt) hi, H, WithBot.coe_add, Nat.cast_withBot,
  WithBot.add_lt_add_iff_right (@WithBot.coe_ne_bot _ (s.card - 1))]
state_before: case refine'_1
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs✝ : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ s
hs : 1 ≤ card s
hst' : card s ≤ card t
H : card t = 1 + (card t - card s) + (card s - 1)
⊢ degree (↑(interpolate (insert i (t \ s)) v) r) + degree (Lagrange.basis s v i) < ↑(card t)

tactic: convert degree_interpolate_lt _
    (hvt.mono (coe_subset.mpr (insert_subset.mpr ⟨hst hi, sdiff_subset _ _⟩)))
state_before: case refine'_1
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs✝ : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ s
hs : 1 ≤ card s
hst' : card s ≤ card t
H : card t = 1 + (card t - card s) + (card s - 1)
⊢ degree (↑(interpolate (insert i (t \ s)) v) r) < ↑(1 + (card t - card s))

tactic: rw [card_insert_of_not_mem (not_mem_sdiff_of_mem_right hi), card_sdiff hst, add_comm]
state_before: case h.e'_4.h.e'_1
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs✝ : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ s
hs : 1 ≤ card s
hst' : card s ≤ card t
H : card t = 1 + (card t - card s) + (card s - 1)
⊢ 1 + (card t - card s) = card (insert i (t \ s))

tactic: rw [add_assoc, tsub_add_tsub_cancel hst' hs, ← add_tsub_assoc_of_le (hs.trans hst'),
  Nat.succ_add_sub_one, zero_add]
state_before: F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs✝ : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ s
hs : 1 ≤ card s
hst' : card s ≤ card t
⊢ card t = 1 + (card t - card s) + (card s - 1)

tactic: simp_rw [eval_finset_sum, eval_mul]
state_before: case refine'_2
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
⊢ eval (v i) (∑ i in s, ↑(interpolate (insert i (t \ s)) v) r * Lagrange.basis s v i) = r i

tactic: by_cases hi' : i ∈ s
state_before: case refine'_2
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
⊢ ∑ x in s, eval (v i) (↑(interpolate (insert x (t \ s)) v) r) * eval (v i) (Lagrange.basis s v x) = r i

tactic: rw [← add_sum_erase _ _ hi', eval_basis_self (hvt.mono hst) hi',
  eval_interpolate_at_node _
    (hvt.mono (coe_subset.mpr (insert_subset.mpr ⟨hi, sdiff_subset _ _⟩)))
    (mem_insert_self _ _),
  mul_one, add_right_eq_self]
state_before: case pos
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : i ∈ s
⊢ ∑ x in s, eval (v i) (↑(interpolate (insert x (t \ s)) v) r) * eval (v i) (Lagrange.basis s v x) = r i

tactic: refine' sum_eq_zero fun j hj => _
state_before: case pos
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : i ∈ s
⊢ ∑ x in Finset.erase s i, eval (v i) (↑(interpolate (insert x (t \ s)) v) r) * eval (v i) (Lagrange.basis s v x) = 0

tactic: rcases mem_erase.mp hj with ⟨hij, _⟩
state_before: case pos
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j✝ : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : i ∈ s
j : ι
hj : j ∈ Finset.erase s i
⊢ eval (v i) (↑(interpolate (insert j (t \ s)) v) r) * eval (v i) (Lagrange.basis s v j) = 0

tactic: rw [eval_basis_of_ne hij hi', MulZeroClass.mul_zero]
state_before: case pos.intro
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j✝ : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : i ∈ s
j : ι
hj : j ∈ Finset.erase s i
hij : j ≠ i
right✝ : j ∈ s
⊢ eval (v i) (↑(interpolate (insert j (t \ s)) v) r) * eval (v i) (Lagrange.basis s v j) = 0

tactic: have H : (∑ j in s, eval (v i) (Lagrange.basis s v j)) = 1 := by
  rw [← eval_finset_sum, sum_basis (hvt.mono hst) hs, eval_one]
state_before: case neg
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : ¬i ∈ s
⊢ ∑ x in s, eval (v i) (↑(interpolate (insert x (t \ s)) v) r) * eval (v i) (Lagrange.basis s v x) = r i

tactic: rw [← mul_one (r i), ← H, mul_sum]
state_before: case neg
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : ¬i ∈ s
H : ∑ j in s, eval (v i) (Lagrange.basis s v j) = 1
⊢ ∑ x in s, eval (v i) (↑(interpolate (insert x (t \ s)) v) r) * eval (v i) (Lagrange.basis s v x) = r i

tactic: refine' sum_congr rfl fun j hj => _
state_before: case neg
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : ¬i ∈ s
H : ∑ j in s, eval (v i) (Lagrange.basis s v j) = 1
⊢ ∑ x in s, eval (v i) (↑(interpolate (insert x (t \ s)) v) r) * eval (v i) (Lagrange.basis s v x) =
    ∑ x in s, r i * eval (v i) (Lagrange.basis s v x)

tactic: congr
state_before: case neg
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j✝ : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : ¬i ∈ s
H : ∑ j in s, eval (v i) (Lagrange.basis s v j) = 1
j : ι
hj : j ∈ s
⊢ eval (v i) (↑(interpolate (insert j (t \ s)) v) r) * eval (v i) (Lagrange.basis s v j) =
    r i * eval (v i) (Lagrange.basis s v j)

tactic: exact
  eval_interpolate_at_node _ (hvt.mono (insert_subset.mpr ⟨hst hj, sdiff_subset _ _⟩))
    (mem_insert.mpr (Or.inr (mem_sdiff.mpr ⟨hi, hi'⟩)))
state_before: case neg.e_a
F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j✝ : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : ¬i ∈ s
H : ∑ j in s, eval (v i) (Lagrange.basis s v j) = 1
j : ι
hj : j ∈ s
⊢ eval (v i) (↑(interpolate (insert j (t \ s)) v) r) = r i

tactic: rw [← eval_finset_sum, sum_basis (hvt.mono hst) hs, eval_one]
state_before: F : Type u_2
inst✝¹ : Field F
ι : Type u_1
inst✝ : DecidableEq ι
s t : Finset ι
i✝ j : ι
v r r' : ι → F
hvt : Set.InjOn v ↑t
hs : Finset.Nonempty s
hst : s ⊆ t
i : ι
hi : i ∈ t
hi' : ¬i ∈ s
⊢ ∑ j in s, eval (v i) (Lagrange.basis s v j) = 1