Skip to content

Commit 2dced9b

Browse files
Proof for natDeg_sum_eq_of_unique (#394)
Automated commit at 20260307_183047 Co-authored-by: aleph-prover[bot] <247409690+aleph-prover[bot]@users.noreply.github.com>
1 parent ce46f26 commit 2dced9b

File tree

1 file changed

+57
-25
lines changed

1 file changed

+57
-25
lines changed

ArkLib/Data/Polynomial/Bivariate.lean

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Authors: Katerina Hristova, František Silváši, Julian Sutherland, Ilia Vlasov
66

77
import ArkLib.Data.Polynomial.Prelims
88

9+
import Mathlib.Algebra.Polynomial.BigOperators
10+
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
911
/-!
1012
# Definitions and Theorems about Bivariate Polynomials with coefficients in a semiring
1113
@@ -189,35 +191,65 @@ attribute [local grind =] natDegree_mul natDegree_add_eq_right_of_degree_lt
189191
@[local grind _=_]
190192
private lemma support_eq_support_toFinsupp {f : F[X][Y]} : f.support = f.toFinsupp.support := rfl
191193

192-
open Classical in
193-
/-- If a summand in a finite sum has degree `deg`, and the degree of every other summand
194-
is strictly less than `deg`, then the degree of the whole sum is exactly `deg`. -/
195-
lemma natDeg_sum_eq_of_unique {α : Type} {s : Finset α} {f : α → F[X]} {deg : ℕ}
194+
theorem natDegree_sum_lt_of_forall_lt {F : Type} [Semiring F] {α : Type} {s : Finset α} {g : α → F[X]} {deg : ℕ} :
195+
0 < deg → (∀ x ∈ s, (g x).natDegree < deg) → (∑ x ∈ s, g x).natDegree < deg := by
196+
intro deg_pos h
197+
have hle : (∑ x ∈ s, g x).natDegree ≤ Nat.pred deg := by
198+
refine Polynomial.natDegree_sum_le_of_forall_le (s := s) (f := g) (n := Nat.pred deg) ?_
199+
intro x hx
200+
exact Nat.le_pred_of_lt (h x hx)
201+
exact lt_of_le_of_lt hle (Nat.pred_lt_self deg_pos)
202+
203+
204+
theorem natDeg_sum_eq_of_unique {α : Type} {s : Finset α} {f : α → F[X]} {deg : ℕ}
196205
(mx : α) (h : mx ∈ s) :
197206
(f mx).natDegree = deg →
198207
(∀ y ∈ s, y ≠ mx → (f y).natDegree < deg ∨ f y = 0) →
199208
(∑ x ∈ s, f x).natDegree = deg := by
200-
intros f_x_deg others_le
201-
by_cases deg_zero : deg = 0
202-
· rw [←f_x_deg, Finset.sum_eq_single] <;> grind
203-
· suffices (∑ x ∈ s with x ≠ mx, f x).degree < (f mx).degree by
204-
have : ∑ x ∈ s, f x = (∑ x ∈ s.filter (fun x => x ≠ mx), f x) + f mx := by
205-
rw (occs := .pos [1]) [
206-
show s = s.filter (fun x => x ≠ mx) ∪ {mx} by grind,
207-
Finset.sum_union (by simp)
208-
]
209-
grind
210-
grind
211-
apply lt_of_le_of_lt (Polynomial.degree_sum_le _ _)
212-
rw [
213-
Finset.sup_lt_iff (by rw [Polynomial.degree_eq_natDegree (by aesop)]
214-
exact WithBot.bot_lt_coe _)
215-
]
216-
intros b h''
217-
obtain ⟨h₁, h₂⟩ : b ∈ s ∧ ¬b = mx := by grind
218-
rcases others_le b h₁ h₂ with h' | h'
219-
· exact Polynomial.degree_lt_degree (f_x_deg.symm ▸ h')
220-
· cases cs : (f mx).degree <;> sorry
209+
classical
210+
intro hmxdeg others
211+
by_cases hdeg0 : deg = 0
212+
·
213+
have hothers0 : ∀ y ∈ s, y ≠ mx → f y = 0 := by
214+
intro y hy hne
215+
have h' := others y hy hne
216+
rcases h' with hlt | hy0
217+
· have hlt0 : (f y).natDegree < 0 := by simpa [hdeg0] using hlt
218+
exact (False.elim ((Nat.not_lt_zero _ ) hlt0))
219+
· exact hy0
220+
have hsum : (∑ x ∈ s, f x) = f mx := by
221+
classical
222+
refine Finset.sum_eq_single_of_mem mx h ?_?
223+
intro y hy hne
224+
exact hothers0 y hy hne
225+
calc
226+
(∑ x ∈ s, f x).natDegree = (f mx).natDegree := by simpa [hsum]
227+
_ = deg := hmxdeg
228+
·
229+
have deg_pos : 0 < deg := Nat.pos_of_ne_zero hdeg0
230+
have hlt_sum : (∑ x ∈ s \ {mx}, f x).natDegree < deg := by
231+
refine natDegree_sum_lt_of_forall_lt (s := s \ {mx}) (g := f) (deg := deg) deg_pos ?_
232+
intro y hy
233+
have hy_s : y ∈ s := (Finset.mem_sdiff.mp hy).1
234+
have hy_not : y ∉ ({mx} : Finset α) := (Finset.mem_sdiff.mp hy).2
235+
have hy_ne : y ≠ mx := by
236+
simpa [Finset.mem_singleton] using hy_not
237+
have h' := others y hy_s hy_ne
238+
rcases h' with hlt | hy0
239+
· exact hlt
240+
· simpa [hy0] using deg_pos
241+
have hlt_mx : (∑ x ∈ s \ {mx}, f x).natDegree < (f mx).natDegree := by
242+
simpa [hmxdeg] using hlt_sum
243+
have hsum_decomp : (∑ x ∈ s, f x) = (∑ x ∈ s \ {mx}, f x) + f mx := by
244+
classical
245+
simpa using (Finset.sum_eq_sum_diff_singleton_add (s := s) (i := mx) (f := f) h)
246+
calc
247+
(∑ x ∈ s, f x).natDegree = ((∑ x ∈ s \ {mx}, f x) + f mx).natDegree := by
248+
simpa [hsum_decomp]
249+
_ = (f mx).natDegree := by
250+
exact Polynomial.natDegree_add_eq_right_of_natDegree_lt hlt_mx
251+
_ = deg := hmxdeg
252+
221253

222254
/-- If some element `x ∈ s` maps to `y` under `f`, and every element of `s` maps to a value
223255
less than or equal to `y`, then the supremum of `f` over `s` is exactly `y`. -/

0 commit comments

Comments
 (0)