How to resolve the algorithm Pell numbers step by step in the J programming language
How to resolve the algorithm Pell numbers step by step in the J programming language
Table of Contents
Problem Statement
Pell numbers are an infinite sequence of integers that comprise the denominators of the closest rational approximations to the square root of 2 but have many other interesting uses and relationships. The numerators of each term of rational approximations to the square root of 2 may also be derived from Pell numbers, or may be found by taking half of each term of the related sequence: Pell-Lucas or Pell-companion numbers.
The Pell numbers: 0, 1, 2, 5, 12, 29, 70, etc., are defined by the recurrence relation: Or, may also be expressed by the closed form formula:
Pell-Lucas or Pell-companion numbers: 2, 2, 6, 14, 34, 82, etc., are defined by a very similar recurrence relation, differing only in the first two terms: Or, may also be expressed by the closed form formula: or
The sequence of rational approximations to the square root of 2 begins: Starting from n = 1, for each term, the denominator is Pn and the numerator is Qn / 2 or Pn-1 + Pn.
Pell primes are Pell numbers that are prime. Pell prime indices are the indices of the primes in the Pell numbers sequence. Every Pell prime index is prime, though not every prime index corresponds to a prime Pell number.
If you take the sum S of the first 4n + 1 Pell numbers, the sum of the terms P2n and P2n + 1 will form the square root of S. For instance, the sum of the Pell numbers up to P5; 0 + 1 + 2 + 5 + 12 + 29 == 49, is the square of P2 + P3 == 2 + 5 == 7. The sequence of numbers formed by the sums P2n + P2n + 1 are known as Newman-Shank-Williams numbers or NSW numbers.
Pell numbers may also be used to find Pythagorean triple near isosceles right triangles; right triangles whose legs differ by exactly 1. E.G.: (3,4,5), (20,21,29), (119,120,169), etc. For n > 0, each right triangle hypotenuse is P2n + 1. The shorter leg length is the sum of the terms up to P2n + 1. The longer leg length is 1 more than that.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Pell numbers step by step in the J programming language
Source code in the j programming language
nextPell=: , 1 2+/ .*_2&{. NB. pell, list extender
Pn=: (%:8) %~(1+%:2)&^ - (1-%:2)&^ NB. pell, closed form
Qn=: (1+%:2)&^ + (1-%:2)&^ NB. pell lucas, closed form
QN=: +: %&Pn ] NB. pell lucas, closed form
qn=: 2 * (+&Pn <:) NB. pell lucas, closed form
nextPell^:9(0 1)
0 1 2 5 12 29 70 169 408 985 2378
Pn i.11
0 1 2 5 12 29 70 169 408 985 2378
nextPell^:9(2 2)
2 2 6 14 34 82 198 478 1154 2786 6726
Qn i.11
2 2 6 14 34 82 198 478 1154 2786 6726
QN i.11
0 2 6 14 34 82 198 478 1154 2786 6726
qn i.11
2 2 6 14 34 82 198 478 1154 2786 6726
QN=: 2 >. +: %&Pn ]
QN i.11
2 2 6 14 34 82 198 478 1154 2786 6726
}.(%~ _1}. +//.@,:~) nextPell^:9(0 1)
1 1.5 1.4 1.41667 1.41379 1.41429 1.4142 1.41422 1.41421 1.41421
}.(%~ _1}. +//.@,:~) nextPell^:9(0 1x)
1 3r2 7r5 17r12 41r29 99r70 239r169 577r408 1393r985 3363r2378
10{.(#~ 1&p:)nextPell^:99(0 1x)
2 5 29 5741 33461 44560482149 1746860020068409 68480406462161287469 13558774610046711780701 4125636888562548868221559797461449
10{.I. 1&p:nextPell^:99(0 1x)
2 3 5 11 13 29 41 53 59 89
_2 +/\ nextPell^:20(0 1x)
1 7 41 239 1393 8119 47321 275807 1607521 9369319 54608393
}.(21$1 0)#|:(}.,~0 1+/+/\@}:)nextPell^:(20)0 1
3 4 5
20 21 29
119 120 169
696 697 985
4059 4060 5741
23660 23661 33461
137903 137904 195025
803760 803761 1136689
4684659 4684660 6625109
27304196 27304197 38613965
You may also check:How to resolve the algorithm Algebraic data types step by step in the REXX programming language
You may also check:How to resolve the algorithm String prepend step by step in the Haskell programming language
You may also check:How to resolve the algorithm Show ASCII table step by step in the C# programming language
You may also check:How to resolve the algorithm Minimum positive multiple in base 10 using only 0 and 1 step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Call a foreign-language function step by step in the D programming language