Show full file and definitions
/-
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.
-/
module
public import FormalConjecturesUtil
/-!
# Largest smallest-base in a decomposition of $n$ into at most four squares
The sequence $a(n)$ is the largest integer $k$ such that $n = k^2 + \dots$ is a
decomposition of $n$ into a sum of at most four nondecreasing squares:
$$a(n) = \max \{k \ge 1 : \exists b_1, b_2, b_3 \in \{0\} \cup [k, n],
k^2 + b_1^2 + b_2^2 + b_3^2 = n\}$$
*References:*
- [A241898](https://oeis.org/A241898)
-/
@[expose] public section
namespace OeisA241898
open Finset
/-- Predicate testing whether $k$ is the smallest base in a decomposition of $n$ into a sum
of at most four squares. -/
def isValidBase (n k : ℕ) : Bool :=
let S := 0 :: List.range' k (n - k + 1)
0 < k && S.any fun b1 => S.any fun b2 => S.any fun b3 =>
k ^ 2 + b1 ^ 2 + b2 ^ 2 + b3 ^ 2 == n
/-- Largest integer $k$ such that $n = k^2 + \dots$ is a decomposition of $n$ into a sum
of at most four nondecreasing squares. -/
def a (n : ℕ) : ℕ :=
((Icc 1 n).filter (fun k => isValidBase n k)).max.getD 0
@[category test, AMS 11]
theorem a_1 : a 1 = 1 := by
decide
@[category test, AMS 11]
theorem a_2 : a 2 = 1 := by
decide
@[category test, AMS 11]
theorem a_3 : a 3 = 1 := by
decide
@[category test, AMS 11]
theorem a_4 : a 4 = 2 := by
decide
@[category test, AMS 11]
theorem a_5 : a 5 = 1 := by
decide
/--
"From the data that I have, it would seem that $a(n)$ is greater than $7$ for all $n > 599$."
- _David S. Newman_, May 02 2014
This is false: since every four-square decomposition of a multiple of $8$ uses only even squares,
$a(4m) = 2a(m)$ for all even $m \ge 2$. From $a(46) = 1$ (via $46 = 1^2 + 3^2 + 6^2$) we obtain
$a(184) = 2$ and $a(736) = a(16 \cdot 46) = 4 \le 7$.
-/
@[category research solved, AMS 11]
theorem conjecture_1 : ¬ ∀ n : ℕ, 599 < n → 7 < a n := by
intro h
-- A finite check: no `k ≥ 8` is a valid base for `736` (all bases involved are at most `27`).
have hcheck : (List.range' 8 20).all (fun k =>
(0 :: List.range' k (28 - k)).all fun b1 =>
(0 :: List.range' k (28 - k)).all fun b2 =>
(0 :: List.range' k (28 - k)).all fun b3 =>
k ^ 2 + b1 ^ 2 + b2 ^ 2 + b3 ^ 2 != 736) = true := by
decide +kernel
have hvalid : ∀ k, isValidBase 736 k = true → k ≤ 7 := by
intro k hk
by_contra hk7
simp only [isValidBase, Bool.and_eq_true, decide_eq_true_eq, List.any_eq_true,
beq_iff_eq] at hk
obtain ⟨-, b1, hb1, b2, hb2, b3, hb3, heq⟩ := hk
have hsmall : ∀ b, b ^ 2 ≤ 736 → b ≤ 27 := fun b hb => by
by_contra hc
have := Nat.pow_le_pow_left (show 28 ≤ b by omega) 2
omega
have hk27 : k ≤ 27 := hsmall k (by omega)
have hmem : ∀ b, b ∈ 0 :: List.range' k (736 - k + 1) → b ^ 2 ≤ 736 →
b ∈ 0 :: List.range' k (28 - k) := fun b hb hb2 => by
have hb27 := hsmall b hb2
rw [List.mem_cons, List.mem_range'_1] at hb ⊢
omega
have hall := List.all_eq_true.mp hcheck k (List.mem_range'_1.mpr ⟨by omega, by omega⟩)
have hne := List.all_eq_true.mp (List.all_eq_true.mp (List.all_eq_true.mp hall b1
(hmem b1 hb1 (by omega))) b2 (hmem b2 hb2 (by omega))) b3 (hmem b3 hb3 (by omega))
simp [heq] at hne
have ha : a 736 ≤ 7 := by
unfold a
cases hmax : ((Icc 1 736).filter fun k => isValidBase 736 k).max with
| bot => exact Nat.zero_le 7
| coe m => exact hvalid m (Finset.mem_filter.mp (Finset.mem_of_max hmax)).2
have := h 736 (by norm_num)
omega
/--
"By Lagrange's Theorem every number can be written as a sum of four squares. Can the same be
said of the set of $\{a^2 \mid a \text{ is any integer not equal to } 7\}$? If this could be
proved, it would only remain to check if all the numbers up to $599$ can be written as the sum
of $4$ squares none of which is $7^2$."
- _David S. Newman_, May 02 2014
Note that $0 \in \mathbb{N} \setminus \{7\}$ allows representations as a sum of at most four
positive squares none of which is $7^2$.
-/
@[category research open, question, AMS 11]
theorem conjecture_2 :
∀ n : ℕ, ∃ a b c d : ℕ,
a ≠ 7 ∧ b ≠ 7 ∧ c ≠ 7 ∧ d ≠ 7 ∧ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n := by
sorry
end OeisA241898