Skip to content

JL2014/sum-two-consecutive-squares

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 

Repository files navigation

Contributing

Pull requests welcome. Don't hesitate to start a conversation in Discussions.

Sum of the squares of two consecutive numbers

See Fermat's theorem on sums of two squares, but here for specific case with x and y are consecutive.
See this conversation on SeqFan mailing list.

For any $x >= 0$ and $y = x + 1$, $s = x² + y²$.
And also $s = 2x^2 + 2x + 1=\frac{(4x+2)²+4}{8}$

Start with $x = 0$, then the first fifty-one terms of $s$, arranged in this way (and prime numbers underlined) :
  0² + 1² = 1,  1² + 2² = 5, 2² + 3² = 13,  3² + 4² = 25, 4² + 5² = 41, 5² + 6² = 61,  6² + 7² = 85, 7² + 8² = 113,  8² + 9² = 145, 9² + 10² = 181, 10² + 11² = 221, 11² + 12² = 265, 12² + 13² = 313, 13² + 14² = 365, 14² + 15² = 421, 15² + 16² = 481, 16² + 17² = 545, 17² + 18² = 613, 18² + 19² = 685, 19² + 20² = 761, 20² + 21² = 841, 21² + 22² = 925, 22² + 23² = 1013, 23² + 24² = 1105, 24² + 25² = 1201, 25² + 26² = 1301, 26² + 27² = 1405, 27² + 28² = 1513, 28² + 29² = 1625, 29² + 30² = 1741, 30² + 31² = 1861, 31² + 32² = 1985, 32² + 33² = 2113, 33² + 34² = 2245, 34² + 35² = 2381, 35² + 36² = 2521, 36² + 37² = 2665, 37² + 38² = 2813, 38² + 39² = 2965, 39² + 40² = 3121, 40² + 41² = 3281, 41² + 42² = 3445, 42² + 43² = 3613, 43² + 44² = 3785, 44² + 45² = 3961, 45² + 46² = 4141, 46² + 47² = 4325, 47² + 48² = 4513, 48² + 49² = 4705, 49² + 50² = 4901, 50² + 51² = 5101, ...

We can observe :

  • first column :
  • second column :
    • odd lines with $s$ ending by 13 (at position $5j + 2$)
    • even lines with $s$ ending by 1 (with gap of $100n + 40$ between them), a cycle ending by $41, 81, 21, 61, 01$
  • third column :
    • $s$ ending by 1 (with gap of $100n + 60$ between them), a cycle ending by $61, 21, 81, 41, 01$
    • some square values as $25, 841, \dots$ with this relation : $x=\frac{\sqrt{8s-4}-2}{4}$

For $s$ ending by 13, if we use this form : $s = 100z + 13$, then the sequence of $z$ is :

   0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, ...

We observe the terms of OEIS A000217 sequence.

Connection to the Brahmagupta-Fibonacci identity (first column)

The first column consists of terms that always ending by 5, meaning they are all multiples of 5 (such as $5, 25, 85, 145, 265, 365, \dots$).

According to the Brahmagupta-Fibonacci identity, the product —or perfect quotient— of two sums of two squares is itself a sum of two squares.
Since 5 can be written as $1^2 + 2^2$, it follows a property: dividing any number from this first column by 5 will always yield a quotient that is also a sum of two squares.

For example:

  • $5 / 5 = 1 \implies 0^2 + 1^2$
  • $25 / 5 = 5 \implies 1^2 + 2^2$
  • $85 / 5 = 17 \implies 1^2 + 4^2$
  • $145 / 5 = 29 \implies 2^2 + 5^2$
  • $265 / 5 = 53 \implies 2^2 + 7^2$
  • $365 / 5 = 73 \implies 3^2 + 8^2$
  • $545 / 5 = 109 \implies 3^2 + 10^2$

For the first column (where $s$ is a multiple of 5), the relationship $s/5 = x'^2 + y'^2$ reveals two linear structures (one for the odd-numbered lines and one for even-numbered lines).
For odd-lines, by tracking the resulting pairs $(x', y')$, we observe an arithmetic progression:

  • The values of $x'$ follow the sequence $k$ (for $k=0, 1, 2, 3 \dots$)
  • The values of $y'$ follow the sequence $3k + 1$
x y s s/5 x′^2+y′^2 (x′, y′)
1 2 5 1 0²+1² (0, 1)
6 7 85 17 1²+4² (1, 4)
11 12 265 53 2²+7² (2, 7)
16 17 545 109 3²+10² (3, 10)

This proves that every term in the first column is linked to a specific Gaussian integer transition.
Specifically, each sum $s/5$ can be expressed as: $s/5 = k^2 + (3k+1)^2 = 10k^2 + 6k + 1$.
The gap between $s/5$ values are form of $20k + 16$ = $4(5k + 4)$.
Actually, no existing OEIS sequence for this polynomial.

In the same way, for even-lines, by tracking the resulting pairs $(x', y')$, we observe an arithmetic progression:

  • The values of $x'$ follow the sequence $k$ (for $k=0, 1, 2, 3 \dots$)
  • The values of $y'$ follow the sequence $3k - 1$

Specifically, each sum $s/5$ can be expressed as: $s/5 = k^2 + (3k-1)^2 = 10k^2 - 6k + 1$.
The gap between $s/5$ values are form of $20k + 24$ = $4(5k + 6)$.
This is related to the OEIS A087348 sequence.

This confirms that the first column is not just a collection of multiples of 5, but a structured sequence of sums of squares where the base values $(x', y')$ evolve linearly.
This regularity is a direct consequence of the Brahmagupta-Fibonacci identity applied to the prime factor 5.

Connection to Fermat's theorem on sums of two squares (second column, ending by 13)

By observing the equation $s = 100z + 13$, we can deduce a property regarding the prime factors of these specific numbers.

First, since $s = 100z + 13$, it follows that $s \equiv 13 \pmod{100}$, which simplifies to $s \equiv 1 \pmod 4$.
This aligns with the necessary condition in Fermat's theorem on sums of two squares.

Because $x$ and $y$ are consecutive integers ($y = x + 1$), they are strictly coprime ($\gcd(x, y) = 1$).
A corollary of Fermat's theorem states that if a number can be expressed as the sum of two coprime squares, every single odd prime factor of that number must be congruent to 1 modulo 4 (i.e., of the form $4k + 1$).

Then for any sum of two consecutive squares ending by 13 (where $z$ is a triangular number from the OEIS A000217 sequence, none of its prime factors will ever be congruent to 3 modulo 4 (i.e., of the form $4k + 3$).

This guarantees that these numbers (if not primes) will never be divisible by non Pythagorean primes (such as $3, 7, 11, 19, 23, \dots$).
All of the prime factors of these s are strictly of the form $4k + 1$ as Pythagorean primes (such as $5, 13, 17, 29, 37, \dots$).

The values of $x$ for these terms are $2, 7, 12, 17, \dots$, which can be written as $x = 5k + 2$.

Properties of the second column (numbers ending by 1)

If we isolate the even-line terms from the second column that do not ending by 13 (such as $41, 181, 421, 761, 1201, \dots$), we can observe a predictable growth.
The sum becomes $s_k = 50k^2 + 90k + 41$.
The values of $x$ for these terms are $4, 9, 14, 19, \dots$, which can be written as $x = 5k + 4$.

By calculating the difference between consecutive terms in this sub-sequence, we find that the gap grows by exactly $100n + 40$ (where $n$ is the step index: $140, 240, 340, 440, \dots$).

This $100n + 40$ gap leads to two deductions:

  • the 2-digit cycle: Because the difference adds exactly $40$ to the tens and units digits (modulo 100) at each step, the last two digits of these numbers follow an infinite, repeating 5-step cycle: 41, 81, 21, 61, 01 (and then back to 41)
  • triangular number formula: just like the terms ending by 13 can be expressed using triangular numbers ($100 T_n + 13$), we can express this sub-sequence using the $k$-th triangular number ($T_k$) and the term index ($k$): $s_k = 100 T_k + 40k + 41$

Properties of the third column (numbers ending by 1)

The third column consists of terms where $x$ is a multiple of 5 ($x = 5, 10, 15, 20 \dots$).
If we write $x = 5k$ (for $k \ge 1$), the sum becomes $s_k = 50k^2 + 10k + 1$.

By analyzing the difference between consecutive terms in this column ($61, 221, 481, 841, 1301, \dots$), we find that the gap grows by exactly $100k + 60$ (the gaps being $160, 260, 360, 460 \dots$).

This $100k + 60$ progression creates a mirror image of the second column's properties:

  • the reversed 2-digit cycle: because the difference adds $60$ to the tens and units digits (modulo 100) at each step, the last two digits follow an infinite 5-step cycle that is the exact reverse of the second column's cycle: 61, 21, 81, 41, 01 (and then back to 61)
  • triangular number formula: we can express this sequence using the $(k-1)$-th triangular number ($T_{k-1}$): $s_k = 100 T_{k-1} + 60k + 1$

Prime numbers of s values and Bunyakovsky's conjecture

If we expand our initial equation $s = x^2 + (x+1)^2$, we obtain the quadratic polynomial $s = 2x^2 + 2x + 1$.
Note: a known property for this polynomial is 8s − 4 = (4x + 2)², then s is the sum of two consecutive squares if and only if 8s − 4 is a perfect square.

By factoring it, we can rewrite the equation as $s = 2x(x+1) + 1$, or simply $s = 2xy + 1$ (since $y = x+1$).
This factored form provides proof that $s$ is always an odd number ($2 \times \text{integer} + 1$), meaning 2 will never be a prime factor in this sequence.

This quadratic polynomial satisfies the three strict conditions of Bunyakovsky's conjecture:

  • its leading coefficient is positive ($2 > 0$)
  • it is irreducible over the integers (it cannot be factored into two linear polynomials with rational coefficients)
  • the generated values share no common divisor greater than 1 for all $x$ (for example, the first two terms, 5 and 13, are strictly coprime)

Because it meets all these criteria, Bunyakovsky's conjecture dictates that this sequence should generate an infinite number of primes.
While this remains one of the unproven problems in mathematics (no one has yet been able to prove that any polynomial of degree 2 or higher generates infinitely many primes), the mathematical structure of $s = 2xy + 1$ strongly implies that prime numbers will never stop appearing throughout this sequence.

Linking first column and second column

An algebraic analysis reveals an intersection between the first and second columns, showing that they are structurally intertwined.

For the sub-sequence in the first column where $x = 5k + 1$ (yielding $s/5 = 10k^2 + 6k + 1$), the gap (or first difference) between consecutive terms is exactly: $$\Delta (s/5) = 20k + 16 = 4(5k + 4)$$

$5k + 4$ is the formula for the base $x$ in the second column ($x_{col2} = 5k + 4$ for even lines).
This shared mathematical DNA allows us to deduce two properties:

  • the accumulation rule: the values of $s/5$ in the first column are directly generated by summing up the sequential base values of the second column. It forms this hybrid identity: $$\frac{s_{col1}(k)}{5} = 1 + 4 \sum_{j=0}^{k-1} x_{col2}(j)$$
  • inter-column synergy: the columns in this system are not isolated patterns. The acceleration rate of the first column's growth is strictly governed by the linear progression of the second column's base numbers.

Combining squares and triangular numbers (extended symmetries)

The Daniel's contribution highlighted additional layers of symmetry connecting this sequence to the broader world of triangular numbers.
While we have already established how our specific sums of squares generate triangular patterns, there are further fundamental properties at play.

The relationship flows in both directions: just as our sums are linked to triangular numbers, the sum of any two consecutive triangular numbers forms a perfect square ($T_{n} + T_{n-1} = n^2$). By combining these geometric properties, we can extract two new observations about our sequences:

1. The $100k² + 26$ identity

If we group specific pairs of sums from our sequence —specifically, the sums of consecutive squares originating from base numbers symmetrically offset around multiples of 5— their combined total yields a clean equation.
For any integer $k$, adding these two distinct sums of two consecutive squares gives:

$$(5k-3)² + (5k-2)² + (5k+2)² + (5k+3)² = 100k² + 26$$

(For example, with $k=1$, we evaluate the bases $x=2$ and $x=7$. Their respective sums of consecutive squares are $2²+3²=13$ and $7²+8²=113$. Adding them together gives $13 + 113 = 126$, which matches the formula $100(1²) + 26$)

2. Connection to OEIS A016802 sequence

As a natural extension of how squares and triangular numbers interact, there is a strict rule regarding specific pairs of even triangular numbers.
If we sum $T_{4n-1}$ and $T_{4n}$ (which are consecutive even triangular numbers), the result is always a perfect square strictly of the form $16n²$ (perfect square).

  • for $n=1$: $T_3 + T_4 = 6 + 10 = 16 \implies 16(1²)$
  • for $n=2$: $T_7 + T_8 = 28 + 36 = 64 \implies 16(2²)$
  • for $n=3$: $T_{11} + T_{12} = 66 + 78 = 144 \implies 16(3²)$

This progression ($16, 64, 144, 256 \dots$) maps directly to the OEIS A016802 sequence, further demonstrating the deep, infinite arithmetic ties between sums of squares and triangular geometries.

Connection to perfect squares, Pythagorean triples, and the negative Pell equation

Occasionally, the sum of two consecutive squares results in a perfect square ($s = m²$). Looking at the sequence, this happens at specific values of $x$:

  • $x=0 \implies 0² + 1² = 1² \implies s=1$
  • $x=3 \implies 3² + 4² = 5² \implies s=25$
  • $x=20 \implies 20² + 21² = 29² \implies s=841$
  • $x=119 \implies 119² + 120² = 169² \implies s=28561$

Note: for $s$, we observe the OEIS A008844 sequence.

When this occurs, the equation $x² + (x + 1)² = m²$ geometrically describes a Pythagorean triple where the legs are consecutive integers (e.g., the famous 3-4-5 right triangle).

Through algebraic manipulation, we can rewrite our base equation $2x² + 2x + 1 = m²$ by multiplying by 2 and completing the square: $$(2x + 1)² + 1 = 2m²$$ $$(2x + 1)² - 2m² = -1$$

By substituting $A = 2x + 1$ and $B = m$, we arrive at $A^2 - 2B^2 = -1$.

This is the classic negative Pell's equation. It proves that the values of $x$ ($0, 3, 20, 119, \dots$ as the OEIS A001652 sequence) and the square roots of $s$ ($1, 5, 29, 169, \dots$ as the OEIS A001653 sequence) are not random; they are governed by the sequence of Pell numbers.
Because Pell's equation solutions grow exponentially based on the silver ratio ($1 + \sqrt{2}$), these perfect squares become rare as the sequence progresses, yet there are infinitely many of them.

Pell numbers and the rational approximation of $\sqrt{2}$

When exploring the sequence $S(n) = n² + (n+1)²$, a pattern emerges when we look for cases where the sum is itself a perfect square: $n² + (n+1)² = c²$.
Geometrically, this corresponds to finding right-angled triangles with integer sides where the two legs are consecutive integers.

The negative Pell equation

Expanding the initial equation gives:
$$2n² + 2n + 1 = c²$$ By multiplying both sides by 2 to complete the square on the left, we get:
$$4n² + 4n + 2 = 2c²$$
$$(2n+1)² - 2c² = -1$$

If we substitute $X = 2n + 1$ and $Y = c$, this reveals a classic Diophantine equation known as the negative Pell equation (or Pell-Fermat equation):
$$X² - 2Y² = -1$$

The Pell and companion Pell sequences

The solutions to this equation are entirely generated by the Pell number sequences:

  • The hypotenuse $Y = c$ perfectly matches the odd-indexed Pell numbers ($P_k$). The Pell sequence is defined by $P_k = 2P_{k-1} + P_{k-2}$ (with $P_0=0, P_1=1$).
  • The term $X = 2n+1$ matches the odd-indexed Companion Pell numbers (or half-Pell-Lucas numbers, $H_k$), defined by $H_k = 2H_{k-1} + H_{k-2}$ (with $H_0=1, H_1=1$).

Converging to $\sqrt{2}$

The fundamental structure of the equation $X² - 2Y² = -1$ implies that as the numbers grow larger, $X² \approx 2Y²$. Consequently, the ratio $\frac{X}{Y}$ approaches $\sqrt{2}$.

In the context of our consecutive squares, this means that the ratio $\frac{2n+1}{c}$ generates some of the best possible rational approximations of $\sqrt{2}$.

$k$ (odd) $n$ Hypotenuse $c$ ($P_k$) $X = 2n+1$ ($H_k$) Ratio $\frac{2n+1}{c}$ Approximation of $\sqrt{2}$
3 3 5 7 7 / 5 1.400000...
5 20 29 41 41 / 29 1.413793...
7 119 169 239 239 / 169 1.414201...
9 696 985 1393 1393 / 985 1.414213...

This demonstrates that our geometric search for consecutive integer right triangles is linked to the continuous fraction expansion of $\sqrt{2}$.

A001333 : 1, 1, 3, 7, 17, 41, 99, 239, 577, 1393, 3363, 8119, 19601, 47321, 114243, 275807, 665857, 1607521, 3880899, 9369319, 22619537, 54608393, 131836323, 318281039, 768398401, 1855077841, 4478554083, 10812186007, 26102926097, 63018038201, 152139002499, 367296043199, ...
A000129 : 0, 1, 2, 5, 12, 29, 70, 169, 408, 985, 2378, 5741, 13860, 33461, 80782, 195025, 470832, 1136689, 2744210, 6625109, 15994428, 38613965, 93222358, 225058681, 543339720, 1311738121, 3166815962, 7645370045, 18457556052, 44560482149, 107578520350, 259717522849, ...