Skip to content

SquaresR ​

The number of ways to write nn as a sum of dd squares, counting signs and order.

✓ checked against that system · ! checked, with disagreements (hover a chip)FungrimSquaresRWolfram LanguageSquaresR✓
SquaresR(d, n)rd(n)r_d(n): ordered, signed dd-tuples summing to nn
Typed signatures
TypePackageApplies
(integer, integer) -> integernumber-theoryalways

Domain: Number theory

Details
  • By brute-force lattice-point enumeration, so signs and order are counted directly rather than adjusted for after the fact.
  • Jacobi's four-square theorem: r4(n)=8σ1(n)r_4(n)=8\sigma_1(n) when 4∤n4 \nmid n. See DivisorSigma.

Examples

Basic #

(±1)2+(±2)2(\pm1)^2+(\pm2)^2 in either order

live ↗
InSquaresR(2,5)\mathrm{SquaresR}(2, 5)Out88
live ↗
InSquaresR(2,25)\mathrm{SquaresR}(2, 25)Out1212

No n≡3(mod4)n\equiv3\pmod4 is a sum of two squares

live ↗
InSquaresR(2,3)\mathrm{SquaresR}(2, 3)Out00

Ways to write 45 as a sum of two squares, with signs and order

live ↗
InSquaresR(2,45)\mathrm{SquaresR}(2, 45)Out88
Scope #
live ↗
InSquaresR(3,6)\mathrm{SquaresR}(3, 6)Out2424
live ↗
InSquaresR(8,3)\mathrm{SquaresR}(8, 3)Out448448
Applications #

Lattice points in a disc of radius 20

live ↗
In∑k=0400SquaresR(2,k)\sum_{k=0}^{400}\mathrm{SquaresR}(2, k)Out1 2571\,257
Properties #

Jacobi: r4(n)=8σ1(n)r_4(n)=8\sigma_1(n) for 4∤n4\nmid n

live ↗
InSquaresR(4,10)\mathrm{SquaresR}(4, 10)Out144144

100=02+102=62+82100=0^2+10^2=6^2+8^2, counting signs and order

live ↗
InSquaresR(2,100)\mathrm{SquaresR}(2, 100)Out1212
About
Examples9
Checked againstWolfram Language 9 agree
CrosswalkFungrimWolfram Language

See also: PowersRepresentations, DivisorSigma