The representation function is one of the oldest objects in number theory. Fermat characterised the integers with — those in which every prime congruent to modulo occurs to an even power — and Euler's proof supplied the closed form , where counts divisors congruent to modulo (sum of two squares theorem).
That description counts representations but does not relate them to one another. The integers carrying several essentially different representations,
are exactly the integers that produce quadruples with
whose two sides are not identified by swapping the two entries or changing their signs. Three reasons make this relation worth a formal development rather than a passing remark.
takes two representations and produces a third. Known to Brahmagupta and stated by Fibonacci in Liber Quadratorum (1225), it is the multiplicativity of the norm in the Gaussian integers, and it is the engine behind every statement below.
The parametrisation targeted here is classical. Nothing in this mission claims new mathematics; the aim is a machine-checked development in which every hypothesis is explicit.
Fix integers. A solution is a quadruple with . It is trivial if the multisets and coincide, i.e. if equals or ; if entries are allowed to vanish, the least value carried by a non-trivial solution is , and requiring all four entries to be positive raises that value to . A solution is primitive when the four entries have greatest common divisor , and positive when all four entries are positive and pairwise distinct — the case in which nothing about the relation is explained by signs, zeros or coincidences.
Two constructions produce solutions. The four-parameter family associates to integers the quadruple
which solves the equation because both sides equal by the identity above. Substituting particular parameters is unrevealing, so a genuine supply comes instead from the elementary one-parameter family
whose four entries , , , are strictly increasing — hence positive and pairwise distinct — as soon as . The bound is sharp: at the two entries and are equal.
In the reverse direction, rewrite the equation as and set
The halves are integers exactly when and share a parity and so do and , and in that case the equation becomes
The development is organised in the namespace TwoSquares, with node names matching the roles above (four_param_identity, explicit_family_chain, sum_sq_eq_halves, four_factor_param, complete_parametrization).
For all integers with , there are integers with
possibly after interchanging and . The goal asserts only the existence of integral parameters and the necessity of at most one swap; it does not assert uniqueness of , which is false, and it says nothing about how many solutions lie in a given box.
The identity itself, over an arbitrary commutative ring, together with the two forms of the Brahmagupta–Fibonacci identity that imply it — so that the reason it holds, rather than the expansion, is what is recorded.
For every integer the displayed family is a positive pairwise distinct solution; the parametrisation is injective; the set of quadruples it produces is infinite; and no member is a nontrivial integer multiple of another, each member being primitive.
The equivalence of with ; the parity statement that matching entries share a parity after at most one swap; and the resulting existence of the half-sum variables satisfying .
For all integers with there are integers with , , , — the coordinate form of the statement that a rank-one matrix factors through the integers.
The result. Taken together, the reverse chain converts the Diophantine equation into four free integer parameters, at the cost of one possible swap. In that form every question about the solution set becomes a question about four independent variables, which is what makes energy estimates, density statements and searches for primitive solutions tractable. The chain also isolates where integrality enters: over a field the parametrisation of is formal, so the content is carried entirely by the parity step and by divisibility over .
Formalizing it. None of the mathematics is new, and that is the point: the value here is a development in which each link is a reusable statement with explicit hypotheses. Three conventions make the nodes reusable rather than bespoke. The algebraic identity is proved over a general commutative ring, not over . The positivity and distinctness of a family are packaged as one strict chain rather than as a list of inequalities, since later arguments use the ordering, not merely the disequalities. The parity issue is isolated into a single node stating a disjunction, instead of being discharged by case splits buried inside a later proof. Conversely, the shape of the final theorem records honestly what is not claimed: parameters are not unique, and no normal form is asserted.
As difficulty, the early nodes have short proofs, while completeness requires the full chain and is the substantial part of the mission.
The obvious first idea is to use the Gaussian integers: and have the same norm, so factor both and compare. It fails. Equal norm does not make two Gaussian integers associates or divisors of one another — and both have norm and are related by no divisibility — because uniqueness of factorisation regroups prime factors in ways that the norm alone cannot distinguish. The correct route recovers the four parameters from the product equation instead, and there the friction is entirely arithmetic:
Clearing halves. The substitution is not available for arbitrary solutions: forces only that the multiset of parities of matches that of , so may have different parities and no integer may exist. The example shows this is not vacuous, and it is why the goal carries a swap.
Factoring . Taking yields , with , and Euclid's lemma then forces and . The degenerate case — where the gcd vanishes and no cancellation is possible — must be handled separately, and because the variables range over rather than , every divisibility step must be tracked with signs. Working over a ring where division is available would delete both issues and with them the entire content of the statement.
Even.namespace EqualTwoSquares
/-- Objective 6, the goal: the four-parameter parametrisation is complete. -/
theorem complete_parametrization {a b c d : ℤ} (h : a^2 + b^2 = c^2 + d^2) :
(∃ p q r s : ℤ,
a = p * r + q * s ∧ b = p * s - q * r ∧
c = p * r - q * s ∧ d = p * s + q * r) ∨
(∃ p q r s : ℤ,
a = p * r + q * s ∧ b = p * s - q * r ∧
d = p * r - q * s ∧ c = p * s + q * r) := by sorry
end EqualTwoSquaresLet a, b, c and d be integers with a^2 + b^2 = c^2 + d^2. Then there are integers p, q, r and s with a = pr + qs, b = ps - qr, c = pr - qs and d = ps + qr; alternatively, there are integers p, q, r and s with a = pr + qs, b = ps - qr, d = pr - qs and c = ps + qr, i.e. the same conclusion holds after the two entries on the right-hand side are interchanged.
No open leaves. Every sub-goal is proved or awaiting decomposition.