Ramanujan's Notebooks, Part IV, Ch. 23: ch23SumTwoSqCount
DefinitionRamanujanNotebooks_ch23_ch23SumTwoSqCountnumber-theoryramanujan-notebooks
ch23SumTwoSqCount x is Landau's B(x) (Chapter 23, Entry 13, pp. 60-62): the number of
positive integers n ≤ x that are a sum of two squares of integers (0 allowed as a
square, so 1, 2, 4, 5, 8, 9, 10, … are counted).
Total: for every real x the set is finite (empty for x < 1), so Nat.card is its true
cardinality and no junk value occurs.
Reference: B(10) = 7, B(100) = 43, B(1000) = 330.
Definition code
import Mathlib
namespace RamanujanNotebooks
/-- `ch23SumTwoSqCount x` is Landau's `B(x)` (Chapter 23, Entry 13, pp. 60-62): the number of
positive integers `n ≤ x` that are a sum of two squares of integers (`0` allowed as a
square, so `1, 2, 4, 5, 8, 9, 10, …` are counted).
Total: for every real `x` the set is finite (empty for `x < 1`), so `Nat.card` is its true
cardinality and no junk value occurs.
Reference: `B(10) = 7`, `B(100) = 43`, `B(1000) = 330`. -/
noncomputable def ch23SumTwoSqCount (x : ℝ) : ℕ :=
Nat.card {n : ℕ // 0 < n ∧ (n : ℝ) ≤ x ∧ ∃ a b : ℕ, n = a ^ 2 + b ^ 2}
end RamanujanNotebooks
Source
Bruce C. Berndt, Ramanujan's Notebooks, Part IV (Springer, 1994), Chapter 23.