/- Copyright 2025 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ import FormalConjecturesUtil

Hilbert's 17th problem

Let $f(x_1, \dots, x_n)$ be a multivariable polynomial with real coefficients that takes only nonnegative values for all real inputs. Hilbert's 17th problem asks whether there exist rational functions $g_1, \dots, g_m$ such that $f = g_1^2 + g_2^2 + \cdots + g_m^2$. Resolved affirmatively by Artin in 1927. References:

    Wikipedia

    Motzkin, "The arithmetic-geometric inequality". In Shisha, Oved (ed.). Inequalities. Academic Press. pp. 205–224.

open Real MvPolynomial namespace Hilbert17

Hilbert's 17th problem: every non-negative multivariate polynomial is a sum of squares of rational functions.

@[category research solved, AMS 12] theorem declaration uses 'sorry'hilbert_17th_problem {n : } (hn : 0 < n) (f : MvPolynomial (Fin n) ) (h : x : Fin n , 0 f.eval x) : (m : ) (g : Fin m MvRatFunc (Fin n) ), algebraMap _ _ f = i, (g i) ^ 2 := n:hn:0 < nf:MvPolynomial (Fin n) h: (x : Fin n ), 0 (eval x) f m g, (algebraMap (MvPolynomial (Fin n) ) (MvRatFunc (Fin n) )) f = i, g i ^ 2 All goals completed! 🐙

The statement is false in general if we restrict to polynomials. The polynomial (by Motzkin) $f(x, y) = x^4 y^2 + x^2 y^4 - 3 x^2 y^2 + 1$ takes only nonnegative values but cannot be written as a sum of squares of polynomials.

noncomputable def f : MvPolynomial (Fin 2) := X 0 ^ 4 * X 1 ^ 2 + X 0 ^ 2 * X 1 ^ 4 - 3 * X 0 ^ 2 * X 1 ^ 2 + 1

The Motzkin polynomial is non-negative everywhere.

@[category textbook, AMS 12] theorem f_nonneg : x y : , 0 f.eval ![x, y] := (x y : ), 0 (eval ![x, y]) f intro x x:y:0 (eval ![x, y]) f x:y:0 x ^ 4 * y ^ 2 + x ^ 2 * y ^ 4 - 3 * x ^ 2 * y ^ 2 + 1 x:y:hx:x = 00 x ^ 4 * y ^ 2 + x ^ 2 * y ^ 4 - 3 * x ^ 2 * y ^ 2 + 1x:y:hx:¬x = 00 x ^ 4 * y ^ 2 + x ^ 2 * y ^ 4 - 3 * x ^ 2 * y ^ 2 + 1 x:y:hx:x = 00 x ^ 4 * y ^ 2 + x ^ 2 * y ^ 4 - 3 * x ^ 2 * y ^ 2 + 1 All goals completed! 🐙 have h : 0 < (x ^ 2 + y ^ 2) ^ 2 := (x y : ), 0 (eval ![x, y]) f All goals completed! 🐙 x:y:hx:¬x = 0h:0 < (x ^ 2 + y ^ 2) ^ 2 := pow_pos (add_pos_of_pos_of_nonneg (lt_of_le_of_ne' (Even.pow_nonneg (even_two_mul 1) x) (pow_ne_zero 2 hx)) (Even.pow_nonneg (even_two_mul 1) y)) 20 (x ^ 4 * y ^ 2 + x ^ 2 * y ^ 4 - 3 * x ^ 2 * y ^ 2 + 1) * (x ^ 2 + y ^ 2) ^ 2 have H : 0 (x ^ 3 * y + x * y ^ 3 - 2 * x * y) ^ 2 * (1 + x ^ 2 + y ^ 2) + (x ^ 2 - y ^ 2) ^ 2 := (x y : ), 0 (eval ![x, y]) f All goals completed! 🐙 All goals completed! 🐙

The Motzkin polynomial cannot be written as a sum of squares of polynomials.

@[category textbook, AMS 12] theorem declaration uses 'sorry'f_not_sum_of_squares : ¬ (n : ) (hn : 0 < n) (S : Fin n MvPolynomial (Fin 2) ), f = i, S i ^ 2 := ¬ n, (_ : 0 < n), S, f = i, S i ^ 2 All goals completed! 🐙

For the polynomial version, Hilbert showed that every nonnegative homogeneous polynomial in $n$ variables of degree $2d$ can be written as a sum of squares of polynomials if and only if

    $n = 1$

    $n = 2$

    $d = 1$

    $(n, d) = (3, 2)$.

def Hilbert17thProblemHomogenousPoly (n d : ) : Prop := f : MvPolynomial (Fin n) , f.IsHomogeneous (2 * d) ( x : Fin n , 0 f.eval x) (m : ) (g : Fin m MvPolynomial (Fin n) ), f = i, (g i) ^ 2 @[category test, AMS 12] theorem Hilbert17thProblemHomogenousPoly_zero_left (d : ) : Hilbert17thProblemHomogenousPoly 0 d := d:Hilbert17thProblemHomogenousPoly 0 d d:f:MvPolynomial (Fin 0) hf:f.IsHomogeneous (2 * d)hf₀: (x : Fin 0 ), 0 (eval x) ff = i, (fun x => C (coeff 0 f)) i ^ 2 d:f:MvPolynomial (Fin 0) hf:f.IsHomogeneous (2 * d)hf₀: (x : Fin 0 ), 0 (eval x) fhfd:f 0 f.totalDegree = 2 * d := IsHomogeneous.totalDegree hff = i, (fun x => C (coeff 0 f)) i ^ 2 d:f:MvPolynomial (Fin 0) hf:f.IsHomogeneous (2 * d)hf₀: (x : Fin 0 ), 0 (eval x) (C (coeff 0 f))hfd:f 0 f.totalDegree = 2 * dC (coeff 0 f) = i, (fun x => C (coeff 0 (C (coeff 0 f)))) i ^ 2 d:f:MvPolynomial (Fin 0) hf:f.IsHomogeneous (2 * d)hf₀: (x : Fin 0 ), 0 (eval x) (C (coeff 0 f))hfd:f 0 f.totalDegree = 2 * dC (coeff 0 f) = x, C (coeff 0 (C (coeff 0 f))) All goals completed! 🐙 @[category test, AMS 12] theorem Hilbert17thProblemHomogenousPoly_zero_right (n : ) : Hilbert17thProblemHomogenousPoly n 0 := n:Hilbert17thProblemHomogenousPoly n 0 intro f n:f:MvPolynomial (Fin n) hf:f.IsHomogeneous (2 * 0)(∀ (x : Fin n ), 0 (eval x) f) m g, f = i, g i ^ 2 n:f:MvPolynomial (Fin n) hf:f.IsHomogeneous (2 * 0)hf₀: (x : Fin n ), 0 (eval x) f m g, f = i, g i ^ 2 n:hf:IsHomogeneous 0 (2 * 0)hf₀: (x : Fin n ), 0 (eval x) 0 m g, 0 = i, g i ^ 2n:f:MvPolynomial (Fin n) hf:f.IsHomogeneous (2 * 0)hf₀: (x : Fin n ), 0 (eval x) fhf_zero:f 0 m g, f = i, g i ^ 2; n:hf:IsHomogeneous 0 (2 * 0)hf₀: (x : Fin n ), 0 (eval x) 0 m g, 0 = i, g i ^ 2 exact 0, 0, n:hf:IsHomogeneous 0 (2 * 0)hf₀: (x : Fin n ), 0 (eval x) 00 = i, 0 i ^ 2 All goals completed! 🐙 have hfd := f.totalDegree_eq_zero_iff_eq_C.1 <| n:f:MvPolynomial (Fin n) hf:f.IsHomogeneous (2 * 0)hf₀: (x : Fin n ), 0 (eval x) fhf_zero:f 0f.totalDegree = 0 All goals completed! 🐙 n:f:MvPolynomial (Fin n) hf:f.IsHomogeneous (2 * 0)hf₀: (x : Fin n ), 0 (eval x) fhf_zero:f 0hfd:f = C (coeff 0 f) := totalDegree_eq_zero_iff_eq_C.mp (Eq.mp (congrArg (Eq f.totalDegree) (mul_zero 2)) (IsHomogeneous.totalDegree hf hf_zero))f = i, (fun x => C (coeff 0 f)) i ^ 2 n:f:MvPolynomial (Fin n) hf:f.IsHomogeneous (2 * 0)hf₀: (x : Fin n ), 0 (eval x) fhf_zero:f 0hfd:f = C (coeff 0 f) := totalDegree_eq_zero_iff_eq_C.mp (Eq.mp (congrArg (Eq f.totalDegree) (mul_zero 2)) (IsHomogeneous.totalDegree hf hf_zero))f = x, C (coeff 0 f) All goals completed! 🐙

Hilbert's 17th problem for homogeneous polynomials: characterization of dimensions and degrees where non-negative polynomials are sums of squares of polynomials.

@[category research solved, AMS 12] theorem declaration uses 'sorry'hilbert_17th_problem_poly {n d : } (hn : 0 < n) (hd : 0 < d) : Hilbert17thProblemHomogenousPoly n d n = 1 n = 2 d = 1 n = 3 d = 2 := n:d:hn:0 < nhd:0 < dHilbert17thProblemHomogenousPoly n d n = 1 n = 2 d = 1 n = 3 d = 2 All goals completed! 🐙 end Hilbert17