import Mathlib.Data.Finset.Sumimport Mathlib.Data.Finset.Cardopen scoped Classicalnamespace SunflowerReplayuniverse u/-- The uniform sunflower bound implies the same bound for sets of size at most`k`, with the same base `C`. The hypothesis quantifies over every ground type. -/theorem atMost_of_uniform (r C : ℕ)(uniform : ∀ (k : ℕ) (α : Type u) (F : Finset (Finset α)),(∀ A ∈ F, A.card = k) → C ^ k < F.card →∃ G ⊆ F, G.card = r ∧ ∃ K : Finset α,∀ A ∈ G, ∀ B ∈ G, A ≠ B → A ∩ B = K)(k : ℕ) (α : Type u) (F : Finset (Finset α))(hsize : ∀ A ∈ F, A.card ≤ k) (hlarge : C ^ k < F.card) :∃ G ⊆ F, G.card = r ∧ ∃ K : Finset α,∀ A ∈ G, ∀ B ∈ G, A ≠ B → A ∩ B = K := byclassicallet pad (A : Finset α) := A.disjSum (Finset.range (k - A.card))have unpad (A : Finset α) : (pad A).toLeft = A := Finset.toLeft_disjSum ..have pad_injective : Function.Injective pad := byintro A B habsimpa only [unpad] using congrArg Finset.toLeft habhave uniform_size : ∀ X ∈ F.image pad, X.card = k := byintro X hxobtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp hxsimpa only [pad, Finset.card_disjSum, Finset.card_range] usingNat.add_sub_of_le (hsize A hA)have large_image : C ^ k < (F.image pad).card := byrwa [Finset.card_image_of_injective F pad_injective]obtain ⟨G, hG, hcard, K, hcore⟩ :=uniform k (α ⊕ ℕ) (F.image pad) uniform_size large_imagehave restore (X) (hx : X ∈ G) : pad X.toLeft = X := byobtain ⟨A, _, rfl⟩ := Finset.mem_image.mp (hG hx)rw [unpad]refine ⟨G.image Finset.toLeft, ?_, ?_, K.toLeft, ?_⟩· intro A haobtain ⟨X, hx, rfl⟩ := Finset.mem_image.mp haobtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp (hG hx)rwa [unpad]· rw [Finset.card_image_of_injOn, hcard]intro X hx Y hy hxysimpa only [restore X hx, restore Y hy] using congrArg pad hxy· intro A ha B hb habobtain ⟨X, hx, rfl⟩ := Finset.mem_image.mp haobtain ⟨Y, hy, rfl⟩ := Finset.mem_image.mp hbhave hxy : X ≠ Y := fun e => hab (congrArg Finset.toLeft e)ext xhave hm := Finset.ext_iff.mp (hcore X hx Y hy hxy) (.inl x)simpa only [Finset.mem_inter, Finset.mem_toLeft] using hm#print axioms atMost_of_uniformend SunflowerReplay