/- 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. -/ import FormalConjecturesUtil

Erdős Problem 1148

References:

open Filter namespace Erdos1148

A natural number $n$ which can be written as $n$ if $n = x^2 + y^2 - z^2$ with $\max(x^2, y^2, z^2) \leq n$.

def Erdos1148Prop (n : ) : Prop := x y z : , n = x ^ 2 + y ^ 2 - z ^ 2 x ^ 2 n y ^ 2 n z ^ 2 n

Can every large integer $n$ be written as $n=x^2+y^2-z^2$ with $\max(x^2,y^2,z^2)\leq n$?

This was proved affirmatively by Chojecki [Ch26], using a Duke-type equidistribution theorem. A Lean formalisation of the reduction (conditional on a Duke-type equidistribution theorem) exists; see the forum discussion.

@[category research solved, AMS 11] theorem declaration uses 'sorry'erdos_1148 : answer(True) ∀ᶠ n in atTop, Erdos1148Prop n := True ∀ᶠ (n : ) in atTop, Erdos1148Prop n All goals completed! 🐙

The largest integer known which cannot be written this way is $6563$.

private instance (n : ) : Decidable (Erdos1148Prop n) := decidable_of_iff ( x Finset.range (Nat.sqrt n + 1), y Finset.range (Nat.sqrt n + 1), z Finset.range (Nat.sqrt n + 1), n = x ^ 2 + y ^ 2 - z ^ 2 x ^ 2 n y ^ 2 n z ^ 2 n) (n:(∃ x Finset.range (n.sqrt + 1), y Finset.range (n.sqrt + 1), z Finset.range (n.sqrt + 1), n = x ^ 2 + y ^ 2 - z ^ 2 x ^ 2 n y ^ 2 n z ^ 2 n) Erdos1148Prop n n:(∃ x Finset.range (n.sqrt + 1), y Finset.range (n.sqrt + 1), z Finset.range (n.sqrt + 1), n = x ^ 2 + y ^ 2 - z ^ 2 x ^ 2 n y ^ 2 n z ^ 2 n) Erdos1148Prop nn:Erdos1148Prop n x Finset.range (n.sqrt + 1), y Finset.range (n.sqrt + 1), z Finset.range (n.sqrt + 1), n = x ^ 2 + y ^ 2 - z ^ 2 x ^ 2 n y ^ 2 n z ^ 2 n n:(∃ x Finset.range (n.sqrt + 1), y Finset.range (n.sqrt + 1), z Finset.range (n.sqrt + 1), n = x ^ 2 + y ^ 2 - z ^ 2 x ^ 2 n y ^ 2 n z ^ 2 n) Erdos1148Prop n n:x:y:z:h:n = x ^ 2 + y ^ 2 - z ^ 2 x ^ 2 n y ^ 2 n z ^ 2 nErdos1148Prop n; All goals completed! 🐙 n:Erdos1148Prop n x Finset.range (n.sqrt + 1), y Finset.range (n.sqrt + 1), z Finset.range (n.sqrt + 1), n = x ^ 2 + y ^ 2 - z ^ 2 x ^ 2 n y ^ 2 n z ^ 2 n n:x:y:z:h1:n = x ^ 2 + y ^ 2 - z ^ 2h2:x ^ 2 nh3:y ^ 2 nh4:z ^ 2 n x Finset.range (n.sqrt + 1), y Finset.range (n.sqrt + 1), z Finset.range (n.sqrt + 1), n = x ^ 2 + y ^ 2 - z ^ 2 x ^ 2 n y ^ 2 n z ^ 2 n n:x:y:z:h1:n = x ^ 2 + y ^ 2 - z ^ 2h2:x ^ 2 nh3:y ^ 2 nh4:z ^ 2 nx < n.sqrt + 1n:x:y:z:h1:n = x ^ 2 + y ^ 2 - z ^ 2h2:x ^ 2 nh3:y ^ 2 nh4:z ^ 2 ny < n.sqrt + 1n:x:y:z:h1:n = x ^ 2 + y ^ 2 - z ^ 2h2:x ^ 2 nh3:y ^ 2 nh4:z ^ 2 nz < n.sqrt + 1 all_goals (n:x:y:z:h1:n = x ^ 2 + y ^ 2 - z ^ 2h2:x ^ 2 nh3:y ^ 2 nh4:z ^ 2 nz n.sqrt; All goals completed! 🐙))

The integer $6563$ cannot be written as $x^2 + y^2 - z^2$ with $\max(x^2, y^2, z^2) \leq 6563$.

@[category textbook, AMS 11] theorem erdos_1148.variants.lower_bound : ¬ Erdos1148Prop 6563 := ¬Erdos1148Prop 6563 All goals completed! 🐙

The weaker property: $n = x^2 + y^2 - z^2$ such that $\max(x^2, y^2, z^2) \leq n + 2\sqrt{n}$.

def erdos_1148_weaker_prop (n : ) : Prop := x y z : , n = x ^ 2 + y ^ 2 - z ^ 2 (x ^ 2 : ) n + 2 * Real.sqrt n (y ^ 2 : ) n + 2 * Real.sqrt n (z ^ 2 : ) n + 2 * Real.sqrt n

[Va99] reports this is 'obvious' if we replace $\leq n$ with $\leq n+2\sqrt{n}$.

@[category research solved, AMS 11] theorem declaration uses 'sorry'erdos_1148.variants.weaker : n, erdos_1148_weaker_prop n := (n : ), erdos_1148_weaker_prop n All goals completed! 🐙 end Erdos1148