Skip to content

Commit 01de3c4

Browse files
committed
Merge branch 'LagrangeDerivative' into ChebyshevExtremal
2 parents d679345 + 8d3c1b4 commit 01de3c4

3 files changed

Lines changed: 61 additions & 120 deletions

File tree

Mathlib/Algebra/Polynomial/Derivative.lean

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -652,55 +652,36 @@ theorem iterate_derivative_eq_zero_of_degree_lt {k : ℕ} {P : R[X]} (h : P.degr
652652

653653
theorem iterate_derivative_prod_X_sub_C {k : ℕ} {S : Finset R} (hk : k ≤ #S) :
654654
derivative^[k] (∏ a ∈ S, (X - C a)) =
655-
k.factorial * ∑ T ∈ S.powerset with #T = #S - k, ∏ a ∈ T, (X - C a):= by
655+
k.factorial * ∑ T ∈ S.powersetCard (#S - k), ∏ a ∈ T, (X - C a):= by
656656
classical
657657
induction k
658-
case zero =>
659-
suffices {T ∈ S.powerset | #T = #S} = {S} by simp [this]
660-
refine eq_singleton_iff_unique_mem.mpr ⟨by simp, fun T hT => ?_⟩
661-
simp only [mem_filter, mem_powerset] at hT
662-
exact Finset.eq_of_subset_of_card_le hT.1 (ge_of_eq hT.2)
658+
case zero => simp
663659
case succ k ind =>
664-
replace ind := ind (Nat.le_of_succ_le hk)
660+
specialize ind (Nat.le_of_succ_le hk)
665661
nth_rewrite 1 [add_comm]
666662
rw [Function.iterate_add_apply, Function.iterate_one, ind, ← nsmul_eq_mul, derivative_smul,
667663
nsmul_eq_mul, derivative_sum, Nat.factorial_succ, mul_comm (k + 1), Nat.cast_mul, mul_assoc]
668664
congr 1
669-
set r₁ : Set ((Finset R) × R) :=
670-
{ p : (Finset R) × R | p.1 ∈ S.powerset ∧ #(p.1) = #S - k ∧ p.2 ∈ p.1 } with hr₁
671-
have : Fintype r₁ := by
672-
refine Set.Finite.fintype (Set.finite_image_fst_and_snd_iff.mp ⟨?_, ?_⟩)
673-
· exact Set.Finite.subset (Finite.of_fintype S.powerset) (by grind)
674-
· exact Set.Finite.subset (Finite.of_fintype S) (by grind)
675-
set r₂ : Set ((Finset R) × R) :=
676-
{p : (Finset R) × R | p.1 ∈ S.powerset ∧ #(p.1) = #S - (k + 1) ∧ p.2 ∈ S \ p.1} with hr₂
677-
have : Fintype r₂ := by
678-
refine Set.Finite.fintype (Set.finite_image_fst_and_snd_iff.mp ⟨?_, ?_⟩)
679-
· exact Set.Finite.subset (Finite.of_fintype S.powerset) (by grind)
680-
· exact Set.Finite.subset (Finite.of_fintype S) (by grind)
681665
calc
682-
∑ T ∈ S.powerset with #T = #S - k, derivative (∏ a ∈ T, (X - C a)) =
683-
∑ T ∈ S.powerset with #T = #S - k, ∑ i ∈ T, ∏ a ∈ T.erase i, (X - C a) := by
666+
∑ T ∈ S.powersetCard (#S - k), derivative (∏ a ∈ T, (X - C a)) =
667+
∑ T ∈ S.powersetCard (#S - k), ∑ i ∈ T, ∏ a ∈ T.erase i, (X - C a) := by
684668
congr! with T hT
685669
simp_rw [derivative_prod_finset, derivative_X_sub_C, mul_one]
686-
_ = ∑ pr₁.toFinset, ∏ a ∈ p.1.erase p.2, (X - C a) := by
670+
_ = ∑ (TS.powersetCard (#S - k)) (i ∈ S) with i ∈ T, ∏ a ∈ T.erase i, (X - C a) := by
687671
rw [← sum_finset_product']
688672
grind
689-
_ = ∑ p ∈ r₂.toFinset, ∏ a ∈ p.1, (X - C a) := by
690-
apply sum_bij' (fun p hp => ⟨p.1.erase p.2, p.2⟩) (fun p hp => ⟨insert p.2 p.1, p.2⟩)
691-
· intro r hr; congr 1; grind
692-
· intro r hr; congr 1; grind
693-
· simp
694-
· grind
695-
· grind
696-
_ = ∑ T ∈ S.powerset with #T = #S - (k + 1), ∑ i ∈ S \ T, ∏ a ∈ T, (X - C a) := by
673+
_ = ∑ (T ∈ S.powersetCard (#S - (k + 1))) (i ∈ S) with i ∉ T, ∏ a ∈ T, (X - C a) := by
674+
apply sum_bij' (fun ⟨T, i⟩ _ => ⟨T.erase i, i⟩) (fun ⟨T, i⟩ _ => ⟨insert i T, i⟩)
675+
· intro r hr; dsimp at hr ⊢; congr 1; grind
676+
· intro r hr; dsimp at hr ⊢; congr 1; grind
677+
all_goals grind
678+
_ = ∑ T ∈ S.powersetCard (#S - (k + 1)), ∑ i ∈ S \ T, ∏ a ∈ T, (X - C a) := by
697679
rw [← sum_finset_product']
698680
grind
699-
_ = (k + 1) * ∑ T ∈ S.powerset with #T = #S - (k + 1), ∏ a ∈ T, (X - C a) := by
681+
_ = (k + 1) * ∑ T ∈ S.powersetCard (#S - (k + 1)), ∏ a ∈ T, (X - C a) := by
700682
rw [mul_sum]
701683
congr! 1 with T hT
702-
have : #(S \ T) = k + 1 := by grind
703-
simp [sum_const, this]
684+
simp [sum_const, show #(S \ T) = k + 1 by grind]
704685
_ = _ := by grind
705686

706687
end CommRing

Mathlib/Data/Finset/Powerset.lean

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,39 +75,16 @@ theorem powerset_eq_singleton_empty : s.powerset = {∅} ↔ s = ∅ := by
7575

7676
theorem image_injOn_powerset_of_injOn {β : Type*} [DecidableEq β] {f : α → β} (H : Set.InjOn f s) :
7777
Set.InjOn (fun (x : Finset α) => x.image f) s.powerset := by
78-
intro x hx y hy h
79-
rw [mem_coe, mem_powerset] at hx hy
80-
dsimp at h
81-
ext a
82-
by_cases a ∈ s
83-
case pos ha =>
84-
have {z : Finset α} (hz : z ⊆ s) : a ∈ z ↔ f a ∈ z.image f := by
85-
refine ⟨fun b => mem_image_of_mem f b, fun h => ?_⟩
86-
obtain ⟨b, hb₁, hb₂⟩ := mem_image.mp h
87-
suffices b = a by rwa [this] at hb₁
88-
exact (H.eq_iff (hz hb₁) ha).mp hb₂
89-
rw [this hx, this hy, h]
90-
case neg ha => tauto
78+
have {z a} (_ : z ⊆ s) (_ : a ∈ s) : a ∈ z ↔ f a ∈ z.image f := by grind [H.eq_iff]
79+
exact fun _ _ _ _ _ => by grind
9180

9281
theorem image_surjOn_powerset {β : Type*} [DecidableEq β] {f : α → β} :
93-
Set.SurjOn (fun (x : Finset α) => x.image f) s.powerset (s.image f).powerset := by
94-
intro t ht
95-
rw [mem_coe, mem_powerset] at ht
96-
simp_rw [Set.mem_image, mem_coe, mem_powerset]
97-
use { x ∈ s | f x ∈ t}
98-
grind
82+
Set.SurjOn (fun (x : Finset α) => x.image f) s.powerset (s.image f).powerset :=
83+
fun t ht => ⟨{ x ∈ s | f x ∈ t}, by grind⟩
9984

10085
theorem powerset_image {β : Type*} [DecidableEq β] {f : α → β} :
101-
(s.image f).powerset = s.powerset.image (fun x => x.image f) := by
102-
ext a
103-
rw [mem_powerset, mem_image]
104-
refine ⟨fun ha => ?_, fun ha => ?_⟩
105-
· use { x ∈ s | f x ∈ a }
106-
grind
107-
· obtain ⟨b, hb₁, hb₂⟩ := ha
108-
rw [mem_powerset] at hb₁
109-
rw [← hb₂]
110-
exact image_subset_image hb₁
86+
(s.image f).powerset = s.powerset.image (fun x => x.image f) :=
87+
ext fun a => ⟨fun _ => mem_image.mpr ⟨{ x ∈ s | f x ∈ a}, by grind⟩, by grind⟩
11188

11289
/-- **Number of Subsets of a Set** -/
11390
@[simp]

Mathlib/LinearAlgebra/Lagrange.lean

Lines changed: 41 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ theorem iterate_derivative_interpolate
460460
(hvs : Set.InjOn v s) {k : ℕ} (hk : k ≤ #s - 1) :
461461
derivative^[k] (interpolate s v r) = k.factorial *
462462
∑ i ∈ s, C (r i / ∏ j ∈ s.erase i, ((v i) - (v j))) *
463-
∑ t ∈ (s.erase i).powerset with #t = #s - (k + 1),
463+
∑ t ∈ (s.erase i).powersetCard (#s - (k + 1)),
464464
∏ a ∈ t, (X - C (v a)) := by
465465
classical
466466
simp_rw [interpolate_eq_sum, iterate_derivative_sum, iterate_derivative_C_mul, mul_sum (s := s),
@@ -471,88 +471,71 @@ theorem iterate_derivative_interpolate
471471
derivative^[k] (∏ j ∈ s.erase i, (X - C (v j))) =
472472
derivative^[k] (∏ vj ∈ (s.erase i).image v, (X - C vj)) := by
473473
rw [Finset.prod_image hvs']
474-
_ = k.factorial * ∑ t ∈ ((s.erase i).image v).powerset with #t = #s - (k + 1),
474+
_ = k.factorial * ∑ t ∈ ((s.erase i).image v).powersetCard (#s - (k + 1)),
475475
∏ va ∈ t, (X - C va) := by
476476
have hcard : #((s.erase i).image v) = #s - 1 := by
477477
rw [card_image_of_injOn hvs', card_erase_of_mem hi]
478-
have : k ≤ #((s.erase i).image v) := by rwa [hcard]
479-
rw [iterate_derivative_prod_X_sub_C this]
480-
congr! 5
478+
rw [iterate_derivative_prod_X_sub_C (by rwa [hcard])]
479+
congr! 3
481480
omega
482-
_ = k.factorial * ∑ t ∈ (s.erase i).powerset with #t = #s - (k + 1),
481+
_ = k.factorial * ∑ t ∈ (s.erase i).powersetCard (#s - (k + 1)),
483482
∏ a ∈ t, (X - C (v a)) := by
484-
rw [powerset_image, sum_nbij (fun (t : Finset ι) => t.image v)]
483+
rw [powersetCard_eq_filter, powerset_image, sum_nbij (fun (t : Finset ι) => t.image v)]
485484
case hi =>
486485
intro a ha
487-
rw [mem_filter, mem_powerset] at ha
486+
rw [mem_powersetCard] at ha
488487
rw [mem_filter, mem_image]
489-
constructor
490-
· use a; simp [ha.1]
491-
· rw [card_image_of_injOn (hvs'.mono (coe_subset.mpr ha.1))]
492-
exact ha.2
493-
case i_inj =>
494-
refine (image_injOn_powerset_of_injOn hvs').mono (coe_subset.mpr ?_)
495-
simp
488+
refine ⟨⟨a, by simp [ha.1]⟩, ?_⟩
489+
rw [card_image_of_injOn (hvs'.mono (by grind))]
490+
exact ha.2
491+
case i_inj => exact (image_injOn_powerset_of_injOn hvs').mono (by grind)
496492
case i_surj =>
497493
intro t ht
498494
rw [mem_coe, mem_filter, mem_image] at ht
499495
obtain ⟨a, ha⟩ := ht.1
500-
simp_rw [Set.mem_image, mem_coe, mem_filter]
501-
use a
502-
refine ⟨⟨ha.1, ?_⟩, ha.2
503-
rw [← ht.2, ← ha.2, card_image_of_injOn (hvs'.mono (coe_subset.mpr (mem_powerset.mp ha.1)))]
496+
simp_rw [Set.mem_image, mem_coe, mem_powersetCard]
497+
refine ⟨a, ⟨⟨mem_powerset.mp ha.1, ?_⟩, ha.2⟩⟩
498+
rw [← ht.2, ← ha.2, card_image_of_injOn (hvs'.mono (by grind))]
504499
case h =>
505500
intro a ha
506-
rw [mem_filter, mem_powerset] at ha
507-
rw [prod_image (hvs'.mono (coe_subset.mpr ha.1))]
508-
509-
omit [DecidableEq ι] in
510-
private theorem degree_eq_of_card_eq {P : Polynomial F} (hP : #s = P.degree + 1) :
511-
P.degree = ↑(s.card - 1) := by
512-
cases h : P.degree
513-
case bot => simp_all
514-
case coe d =>
515-
rw [Nat.cast_withBot] at hP ⊢
516-
suffices #s = d + 1 by grind
517-
rw [h] at hP
518-
simp [← WithBot.coe_inj, hP]
519-
520-
omit [DecidableEq ι] in
521-
private theorem natDegree_eq_of_card_eq {P : Polynomial F} (hP : #s = P.degree + 1) :
522-
P.natDegree = s.card - 1 := natDegree_eq_of_degree_eq_some (degree_eq_of_card_eq hP)
523-
524-
omit [DecidableEq ι] in
525-
private theorem degree_lt_of_card_eq {P : Polynomial F} (hP : #s = P.degree + 1) :
526-
P.degree < s.card := by
527-
have := degree_eq_of_card_eq hP
528-
have := natDegree_eq_of_card_eq hP
529-
have s_card : s.card > 0 := by by_contra! h; simp_all
530-
grind [Nat.cast_lt]
501+
convert (prod_image (hvs'.mono (coe_subset.mpr (mem_powersetCard.mp ha).1))).symm
502+
rfl
531503

532504
theorem eval_iterate_derivative_eq_sum
533505
(hvs : Set.InjOn v s) {P : Polynomial F} (hP : #s = P.degree + 1)
534506
{k : ℕ} (hk : k ≤ P.degree) (x : F) :
535507
(derivative^[k] P).eval x = k.factorial *
536508
∑ i ∈ s, (P.eval (v i) / ∏ j ∈ s.erase i, ((v i) - (v j))) *
537-
∑ t ∈ (s.erase i).powerset with #t = #s - (k + 1),
509+
∑ t ∈ (s.erase i).powersetCard (#s - (k + 1)),
538510
∏ a ∈ t, (x - v a) := by
539-
rw (occs := [1]) [eq_interpolate hvs (degree_lt_of_card_eq hP)]
540-
rw [iterate_derivative_interpolate, ← nsmul_eq_mul, eval_smul, nsmul_eq_mul, eval_finset_sum]
541-
· congr! 2 with i hi
542-
simp_rw [eval_C_mul, eval_finset_sum, eval_prod, eval_sub, eval_X, eval_C]
543-
· exact hvs
544-
· rw [degree_eq_of_card_eq hP] at hk
545-
exact WithBot.coe_le_coe.mp hk
511+
lift P.degree to ℕ using (by contrapose! hP; rw [hP]; simp) with deg hdeg
512+
rw [← WithBot.coe_one, ← WithBot.coe_add] at hP
513+
replace hP := WithBot.coe_eq_coe.mp hP
514+
have hdegree : P.degree = ↑(#s - 1) := hdeg.symm.trans (WithBot.coe_eq_coe.mpr (by grind))
515+
rw (occs := [1]) [eq_interpolate hvs (f := P)]
516+
· rw [iterate_derivative_interpolate, ← nsmul_eq_mul, eval_smul, nsmul_eq_mul, eval_finset_sum]
517+
· congr! 2 with i hi
518+
simp_rw [eval_C_mul, eval_finset_sum, eval_prod, eval_sub, eval_X, eval_C]
519+
· exact hvs
520+
· exact WithBot.coe_le_coe.mp (le_of_le_of_eq hk (by rwa [hdeg]))
521+
· exact lt_of_eq_of_lt hdeg.symm (WithBot.coe_lt_coe.mpr <|
522+
lt_of_lt_of_eq (lt_add_one deg) hP.symm)
546523

547524
theorem leadingCoeff_eq_sum
548525
(hvs : Set.InjOn v s) {P : Polynomial F} (hP : #s = P.degree + 1) :
549526
P.leadingCoeff = ∑ i ∈ s, (P.eval (v i)) / ∏ j ∈ s.erase i, ((v i) - (v j)) := by
550-
rw [leadingCoeff, natDegree_eq_of_card_eq hP]
551-
rw (occs := [1]) [eq_interpolate hvs (degree_lt_of_card_eq hP)]
552-
rw [interpolate_apply, finset_sum_coeff]
553-
congr! with i hi
554-
rw [coeff_C_mul, ← natDegree_basis hvs hi, ← leadingCoeff, leadingCoeff_basis hvs hi]
555-
field_simp
527+
lift P.degree to ℕ using (by contrapose! hP; rw [hP]; simp) with deg hdeg
528+
rw [← WithBot.coe_one, ← WithBot.coe_add] at hP
529+
replace hP := WithBot.coe_eq_coe.mp hP
530+
have hdegree : P.degree = ↑(#s - 1) := hdeg.symm.trans (WithBot.coe_eq_coe.mpr (by grind))
531+
rw [leadingCoeff, natDegree_eq_of_degree_eq_some hdegree]
532+
rw (occs := [1]) [eq_interpolate (f := P) hvs]
533+
· rw [interpolate_apply, finset_sum_coeff]
534+
congr! with i hi
535+
rw [coeff_C_mul, ← natDegree_basis hvs hi, ← leadingCoeff, leadingCoeff_basis hvs hi]
536+
field_simp
537+
· exact lt_of_eq_of_lt hdeg.symm (WithBot.coe_lt_coe.mpr <|
538+
lt_of_lt_of_eq (lt_add_one deg) hP.symm)
556539

557540
end Interpolate
558541

0 commit comments

Comments
 (0)