/-
Copyright 2026 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.
-/modulepublicimportMathlib.Algebra.BigOperators.FinpublicimportMathlib.Algebra.Ring.SumsOfSquares@[expose]publicsection
Pythagoras numbers
The Pythagoras number $p(R)$ of $R$ is the least $p$ such that every sum of squares in $R$ is a
sum of $p$ squares; see [Pfister1995] for fields and [CDLR1982] for rings. This file defines:
IsSumSqOfLength n a: a is a sum of n squares, a counted refinement of Mathlib's IsSumSq;
pythagorasBounds R: the set of p such that every sum of squares in R is a sum of p
squares.
The Pythagoras number of R is p exactly when IsLeast (pythagorasBounds R) p. The set
pythagorasBounds R can be empty, in which case the Pythagoras number is infinite; by [CDLR1982]
this happens for $\mathbb{R}[X, Y]$. No numeric invariant is defined here, so that no convention
for the infinite case is needed.
The definitions and the correspondence with IsSumSq need only [AddCommMonoid R] [Mul R]; the
AddCommMonoid is what the sum ∑ i : Fin n requires, since IsSumSq itself assumes only
[Mul R] [Add R] [Zero R]. Padding a sum of squares with zeros needs 0 * 0 = 0, so
IsSumSqOfLength.of_le and mem_pythagorasBounds_of_le are stated for a
NonUnitalNonAssocSemiring.
References
[CDLR1982] M. D. Choi, Z. D. Dai, T. Y. Lam, B. Reznick, The Pythagoras number of some
affine algebras and local algebras, J. reine angew. Math. 336 (1982), 45–82.
[Pfister1995] A. Pfister, Quadratic forms with applications to algebraic geometry and
topology, London Math. Soc. Lecture Note Ser. 217, Cambridge University Press, 1995.