(phixonline)--> with javascript_semantics sequence p = {0,1}, pl = {2,2} for i=2 to 41 do p &= 2*p[i]+p[i-1] pl &= 2*pl[i]+pl[i-1] end for printf(1,"First 20 Pell numbers: %s\n",{join_by(p[1..20],1,20," ",fmt:="%d")}) printf(1,"First 20 Pell-Lucas: %s\n",{join_by(pl[1..20],1,20," ",fmt:="%d")}) printf(1,"First 20 rational approximations of sqrt(2) (%.16f):\n",{sqrt(2)}) for i=2 to 21 do integer n = pl[i]/2, d = p[i] printf(1,"%d/%d ~= %.16g\n", {n,d,n/d}) end for printf(1,"\nFirst 20 Pell primes:\n") include mpfr.e mpz {p0,p1,p2} = mpz_inits(3,{0,1,0}) sequence ppdx = {} integer pdx = 2 while length(ppdx)<20 do mpz_mul_si(p2,p1,2) mpz_add(p2,p2,p0) if is_prime(pdx) and mpz_prime(p2) then printf(1,"%s\n",mpz_get_short_str(p2)) ppdx = append(ppdx,sprintf("%d",pdx)) end if pdx += 1 mpz_set(p0,p1) mpz_set(p1,p2) end while printf(1,"\nIndices of first 20 Pell primes: %s\n",join(ppdx," ")) sequence nsw = {} for n=1 to 20 do nsw = append(nsw,sprintf("%d",p[2*n]+p[2*n-1])) end for nsw[8..-3] = {"..."} printf(1,"\nFirst 20 Newman-Shank-Williams numbers: %s\n",{join(nsw," ")}) printf(1,"\nFirst 20 near isosceles right triangles:\n") for i=4 to 42 by 2 do atom side = sum(p[1..i-1]), hypot = p[i] printf(1,"[%d, %d, %d]\n", {side,side+1,hypot}) end for