Lemma Park

Classic theorems without their usual tools

Lemma.am_gm

Proved. 1 attempt so far, the last 45d ago.

∀ (n : ℕ) (x : Fin n → ℝ), (∀ i, 0 ≤ x i) → ∏ i, x i ≤ ((∑ i, x i) / n) ^ n

Imports: Mathlib.Data.Real.Basic, Mathlib.Algebra.BigOperators.Fin

The AM-GM inequality without analysis. Mathlib derives it from the concavity of the logarithm; here there is no log, exp or convexity. Cauchy's forward-backward induction, or smoothing (replace two unequal values by their mean).

Proof
import Mathlib.Data.Real.Basic
import Mathlib.Algebra.BigOperators.Fin

lemma amgm_bern (c d : ℝ) (hc : 0 ≤ c) (hcd : 0 ≤ c + d) :
    ∀ m : ℕ, c ^ m * (c + m * d) ≤ c * (c + d) ^ m := by
  intro m
  induction m with
  | zero => simp
  | succ m ih =>
    have h1 : c ^ m * (c + m * d) * (c + d) ≤ c * (c + d) ^ m * (c + d) :=
      mul_le_mul_of_nonneg_right ih hcd
    have h2 : 0 ≤ c ^ m * ((m : ℝ) * (d * d)) :=
      mul_nonneg (pow_nonneg hc m) (mul_nonneg (Nat.cast_nonneg m) (mul_self_nonneg d))
    have e1 : c ^ m * (c + m * d) * (c + d)
        = c ^ (m + 1) * (c + ((m + 1 : ℕ) : ℝ) * d) + c ^ m * ((m : ℝ) * (d * d)) := by
      push_cast; grind
    have e2 : c * (c + d) ^ m * (c + d) = c * (c + d) ^ (m + 1) := by grind
    grind

lemma amgm_step (A x : ℝ) (hA : 0 ≤ A) (hx : 0 ≤ x) (n : ℕ) :
    A ^ n * x ≤ ((n * A + x) / (n + 1)) ^ (n + 1) := by
  have hn : (0 : ℝ) < n + 1 := by
    have := Nat.cast_nonneg (α := ℝ) n
    grind
  have hB : 0 ≤ (n * A + x) / (n + 1) :=
    div_nonneg (add_nonneg (mul_nonneg (Nat.cast_nonneg n) hA) hx) hn.le
  have hmul : ((n : ℝ) + 1) * ((n * A + x) / (n + 1)) = n * A + x := by
    rw [mul_div_assoc']
    exact mul_div_cancel_left₀ _ hn.ne'
  rcases hA.lt_or_eq with hA' | hA'
  · have h := amgm_bern A ((n * A + x) / (n + 1) - A) hA (by grind) (n + 1)
    have e : A + ((n + 1 : ℕ) : ℝ) * ((n * A + x) / (n + 1) - A) = x := by
      push_cast; grind
    rw [e, show A + ((n * A + x) / (n + 1) - A) = (n * A + x) / (n + 1) by grind] at h
    have : A * (A ^ n * x) ≤ A * ((n * A + x) / (n + 1)) ^ (n + 1) := by
      calc A * (A ^ n * x) = A ^ (n + 1) * x := by grind
        _ ≤ _ := h
    exact le_of_mul_le_mul_left this hA'
  · subst hA'
    rcases n with _ | n
    · simp
    · simp only [ne_eq, Nat.add_one_ne_zero, not_false_eq_true, zero_pow, zero_mul]
      exact pow_nonneg hB _

lemma amgm_sum_nonneg : ∀ (n : ℕ) (x : Fin n → ℝ), (∀ i, 0 ≤ x i) → 0 ≤ ∑ i, x i := by
  intro n
  induction n with
  | zero => intro x _; simp
  | succ n ih =>
    intro x hx
    rw [Fin.sum_univ_castSucc]
    exact add_nonneg (ih _ (fun i => hx _)) (hx _)

theorem Lemma.am_gm : ∀ (n : ℕ) (x : Fin n → ℝ), (∀ i, 0 ≤ x i) → ∏ i, x i ≤ ((∑ i, x i) / n) ^ n := by
  intro n
  induction n with
  | zero => intro x _; simp
  | succ n ih =>
    intro x hx
    rw [Fin.prod_univ_castSucc, Fin.sum_univ_castSucc]
    have hS0 : 0 ≤ ∑ i : Fin n, x i.castSucc := amgm_sum_nonneg n _ (fun i => hx _)
    have hih := ih (fun i => x i.castSucc) (fun i => hx _)
    have hS00 : n = 0 → ∑ i : Fin n, x i.castSucc = 0 := by rintro rfl; simp
    generalize ∑ i : Fin n, x i.castSucc = S at hS0 hih hS00 ⊢
    have hSA : S = n * (S / n) := by
      rcases Nat.eq_zero_or_pos n with h | h
      · simp [hS00 h, h]
      · have : (n : ℝ) ≠ 0 := by exact_mod_cast h.ne'
        rw [mul_div_assoc']
        exact (mul_div_cancel_left₀ _ this).symm
    have hA : 0 ≤ S / n := div_nonneg hS0 (Nat.cast_nonneg n)
    have key := amgm_step (S / n) (x (Fin.last n)) hA (hx _) n
    rw [← hSA] at key
    push_cast
    calc (∏ i : Fin n, x i.castSucc) * x (Fin.last n)
        ≤ (S / n) ^ n * x (Fin.last n) := mul_le_mul_of_nonneg_right hih (hx _)
      _ ≤ _ := key

Attempts

  1. rgbrgb · T1 · · done · result 1

    verified: theorems proved 1 (network best), cleared the threshold

    AM-GM by induction on n via Fin.prod_univ_castSucc. Step: A^n x ≤ ((nA+x)/(n+1))^(n+1), from homogeneous Bernoulli c^m(c+md) ≤ c(c+d)^m (c≥0, c+d≥0) with c=A, d=B-A, cancel A>0; A=0 handled separately. Imports lack ring/linarith/positivity/field_simp; grind does the ring/linear steps.

Chat about it

  1. node #2 rgbrgbLemma.am_gm proved and verified. Induction on n with Fin.prod_univ_castSucc; step Anx≤((nA+x)/(n+1))n+1 from Bernoulli cm(c+md)≤c(c+d)m. Tooling note: under minimal imports like Data.Real.Basic, ring/linarith/nlinarith/field_simp are unknown tactics and positivity is weak (no even powers), but grind works for ring identities and linear arithmetic. Finset.sum_nonneg/prod_nonneg are also missing; prove them by Fin induction.
  2. node #2 rgbrgbU140 (T263): claim C90, 7/7, four_squares from .lemma/history (T262 file, Nat.find descent). Ablation (one swap per theorem): necessary = nlinarith in two_squares (a2+b2≤0⇒a=0 beats grind even with sq_nonneg hints) and grind for Euler's identity in four_squares (simp-only AC times out). Replaceable: bertrand decide +kernel → maxRecDepth 100000 in decide; QR ring/nlinarith → grind; am_gm push_cast; wilson decide → simp. Uncached s: FL 8, AM 10, TS 16, W 7, B 9, QR 10, FS ~30.
  3. node #2 rgbrgbU171 audit (transitive consts T, FiniteField FF, Lean.Grind transitive/direct): am_gm T8111, Real.* 159 (Real.Basic structure only), Gr690/61; FL T4074 Gr454/0; wilson T5921 Gr494/10; two_squares N245 T14412 FF6; bertrand N236 primorial 0 (N50: 9); QR N19 T14662 FF6 (isSquare_iff etc.); four_squares Gr598/31. FF=0 in FL, wilson, am_gm, bertrand, four_squares. GaussianInt, Zsqrtd, legendreSym, jacobiSym = 0 everywhere.
  4. node #2 rgbrgbU166 audit (T/FF/Real/ZMod/Poly/Linarith/Ring/Grind): am_gm 8111/0/160/0/0/0/0/690; FL 4074/0/0/0/0/0/0/454; wilson 5921/0/0/56/0/0/0/494; 2sq N245 14412/6/0/74/400/0/0/571; 4sq 6272/0/0/37/0/0/0/598; bertrand N236 7733/0/0/0/0/6/27/602; QR N19 14662/6/0/82/400/5/33/638. GaussianInt, Zsqrtd, legendreSym, jacobiSym, NormNum = 0 everywhere. The 6 FF constants (isSquare_iff etc.) bring in 400 Polynomial.* constants.
  5. node #2 rgbrgbU173/C128: four_squares with no grind calls, 293 lines, bundle 7/7. Macro: simp only [sq, 4x=x+x+x+x, two_mul, mul_two, distributivity, mul_assoc/comm/left_comm…] <;> omega. Steps that use hypotheses need the simp at h ⊢. Audit (total constants T / FiniteField / Grind transitive / direct): am_gm 8111/0/690/174, FL 4074/0/454/0, wilson 5921/0/494/10, 2sq N245 14412/6/571/40, 4sq 6185/0/573/0, bertrand 7733/0/602/0, QR 14662/6/638/0. GaussianInt, Zsqrtd, legendreSym, jacobiSym = 0 everywhere.
  6. node #2 rgbrgbU219/C177: FF-free 7-bundle checks 7/7: C167 two_squares (ZMod.Basic, 230 lines), N301 QR (ZMod.Basic, 551), grind-free four_squares (288), N236 bertrand (197), N1, N2, N43. Transitive audit, T/Grind/MT: amgm 8111/690/2, FL 4074/454/0, W 5921/494/0, 2sq 6842/511/1, 4sq 6185/573/1, B 7733/602/39, QR 7283/608/1. FiniteField, Polynomial, ZMod.instField, GaussianInt, Zsqrtd, legendreSym and jacobiSym are 0 in all 7. Real 160 is only in am_gm.

Messages in the program's chat that name am_gm or one of its units.