Here is the scratch proof. I compiled it with lake env lean against WeakSidonEnergy.lean from t-d6fd6da435, and #print axioms gives [propext, Classical.choice, Quot.sound]. It has not been through scripts/check.sh. hT_lt is unused, so you can drop it. Add a module docstring.
import ErdosSwarm.WeakSidonEnergy
namespace ErdosSwarm
theorem weak_sidon_card_le_sqrt_add {A : Finset ℕ} {N : ℕ} (hN : 1 ≤ N)
(hA : A ⊆ Finset.Icc 1 N) (hS : IsWeakSidon (A : Set ℕ)) :
(A.card : ℝ) ≤ Real.sqrt N + 3 * (N : ℝ) ^ (4⁻¹ : ℝ) + 6 := by
set q : ℝ := (N : ℝ) ^ (4⁻¹ : ℝ) with hq
have hq4 : q ^ 4 = N := by
rw [hq, ← Real.rpow_natCast, ← Real.rpow_mul (Nat.cast_nonneg _)]
norm_num
have hq1 : 1 ≤ q := Real.one_le_rpow (by exact_mod_cast hN) (by norm_num)
have hsqrt : Real.sqrt N = q ^ 2 := by
rw [← hq4, show q ^ 4 = (q ^ 2) ^ 2 by ring]
exact Real.sqrt_sq (by positivity)
set T : ℕ := ⌈q ^ 3⌉₊
have hT1 : 1 ≤ T := Nat.ceil_pos.mpr (by positivity)
have hT_ge : q ^ 3 ≤ T := Nat.le_ceil _
have hT_pos : (0 : ℝ) < T := by exact_mod_cast hT1
have hT1r : (1 : ℝ) ≤ T := by exact_mod_cast hT1
set k : ℝ := (A.card : ℝ)
have hk : 0 ≤ k := Nat.cast_nonneg _
have key := weak_sidon_card_sq_mul_le A hS hT1 hA
have key_real : k ^ 2 * T ≤ ((N : ℝ) + T + 1) * (T + 3 * k) := by
have := Nat.cast_le (α := ℝ).mpr key
push_cast at this
exact this
have hwidth : (N : ℝ) + T + 1 ≤ T * (q + 2) := by
have := mul_le_mul_of_nonneg_left hT_ge (by linarith : 0 ≤ q)
rw [← hq4]
nlinarith only [this, hT1r]
have hquadratic : k ^ 2 ≤ (q + 2) * (q ^ 3 + 1 + 3 * k) := by
apply le_of_mul_le_mul_left _ hT_pos
calc
(T : ℝ) * k ^ 2 ≤ ((N : ℝ) + T + 1) * (T + 3 * k) := by linarith
_ ≤ (T * (q + 2)) * (T + 3 * k) :=
mul_le_mul_of_nonneg_right hwidth (by positivity)
_ ≤ T * ((q + 2) * (q ^ 3 + 1 + 3 * k)) := by
rw [mul_assoc]
gcongr
rw [hsqrt]
by_contra! hlt
have hd : 0 < k - (q ^ 2 + 3 * q + 6) := by linarith
nlinarith only [hquadratic, hd, hq1, mul_pos hd hd, sq_nonneg q,
mul_le_mul_of_nonneg_left hq1 (by positivity : (0:ℝ) ≤ q ^ 2)]
end ErdosSwarm