Data update

This commit is contained in:
Ingy döt Net 2025-06-11 20:16:52 -04:00
parent 72eb4943cb
commit 4d5544505c
2347 changed files with 62432 additions and 16731 deletions

View file

@ -12,7 +12,7 @@ fastfunc totient n .
if n > 1 : tot -= tot div n
return tot
.
numfmt 0 3
numfmt 3 0
print " N Prim Phi"
for n = 1 to 25
tot = totient n

View file

@ -1,24 +0,0 @@
/*REXX program calculates the totient numbers for a range of numbers, and count primes. */
parse arg N . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N= 25 /*Not specified? Then use the default.*/
tell= N>0 /*N positive>? Then display them all. */
N= abs(N) /*use the absolute value of N for loop.*/
w= length(N) /*W: is used in aligning the output. */
primes= 0 /*the number of primes found (so far).*/
/*if N was negative, only count primes.*/
do j=1 for N; T= phi(j) /*obtain totient number for a number. */
prime= word('(prime)', 1 + (T \== j-1 ) ) /*determine if J is a prime number. */
if prime\=='' then primes= primes + 1 /*if a prime, then bump the prime count*/
if tell then say 'totient number for ' right(j, w) " ──► " right(T, w) ' ' prime
end /*j*/
say
say right(primes, w) ' primes detected for numbers up to and including ' N
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
gcd: parse arg x,y; do until y==0; parse value x//y y with y x
end /*until*/; return x
/*──────────────────────────────────────────────────────────────────────────────────────*/
phi: procedure; parse arg z; if z==1 then return 1
#= 1
do m=2 for z-2; if gcd(m, z)==1 then #= # + 1
end /*m*/; return #

View file

@ -1,25 +0,0 @@
/*REXX program calculates the totient numbers for a range of numbers, and count primes. */
parse arg N . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N= 25 /*Not specified? Then use the default.*/
tell= N>0 /*N positive>? Then display them all. */
N= abs(N) /*use the absolute value of N for loop.*/
w= length(N) /*W: is used in aligning the output. */
primes= 0 /*the number of primes found (so far).*/
/*if N was negative, only count primes.*/
do j=1 for N; T= phi(j) /*obtain totient number for a number. */
prime= word('(prime)', 1 + (T \== j-1 ) ) /*determine if J is a prime number. */
if prime\=='' then primes= primes + 1 /*if a prime, then bump the prime count*/
if tell then say 'totient number for ' right(j, w) " ──► " right(T, w) ' ' prime
end /*j*/
say
say right(primes, w) ' primes detected for numbers up to and including ' N
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
phi: procedure; parse arg z; if z==1 then return 1
#= 1
do m=2 for z-2; parse value m z with x y
do until y==0; parse value x//y y with y x
end /*until*/
if x==1 then #= # + 1
end /*m*/
return #

View file

@ -1,137 +0,0 @@
include Settings
say version; say 'Totient function (Phi)'; say
call Time('r')
numeric digits 10; cycl. = 0; m = 7
call First25A
call PrimeCountA m
say Format(Time('e'),,3) 'seconds'; say
call Time('r')
call Totients 10**m
call First25B
call PrimeCountB m
say Format(Time('e'),,3) 'seconds'
exit
First25A:
procedure
say 'A: using calls to an optimized Totient()'; say
say ' N Phi(N) Prime?'
say Copies('-',16)
n = 0
do i = 1 to 25
p = Totient(i)
if p = i-1 then do
n = n+1; pr = 'Yes'
end
else
pr = ''
say Right(i,2) Right(p,6) pr
end
say Copies('-',16); say
say 'Found' Right(n,6) 'primes <' Right(25,8)
return
PrimeCountA:
procedure
arg x
n = 0; d = 1
do i = 1
p = Totient(i)
if p = i-1 then
n = n+1
e = Xpon(i)
if e > d then do
say 'Found' Right(n,6) 'primes <' Right(10**e,8)
if e > x-1 then
leave i
d = e
end
end
say
return
First25B:
procedure expose toti.
say 'B: generate and save all Totients, and use the stored values'; say
say ' N Phi(N) Prime?'
say Copies('-',16)
n = 0
do i = 1 to 25
p = toti.totient.i
if p = i-1 then do
n = n+1; pr = 'Yes'
end
else
pr = ''
say Right(i,2) Right(p,6) pr
end
say Copies('-',16)
say
say 'Found' Right(n,6) 'primes <' Right(25,8)
return
PrimeCountB:
procedure expose toti.
arg x
n = 0; d = 1
do i = 1
p = toti.totient.i
if p = i-1 then
n = n+1
e = Xpon(i)
if e > d then do
say 'Found' Right(n,6) 'primes <' Right(10**e,8)
if e > x-1 then
leave i
d = e
end
end
say
return
Totient:
/* Euler's totient function */
procedure expose toti.
arg x
/* Fast values */
if x < 3 then
return 1
if x < 5 then
return 2
/* Multiplicative property using Factors */
f = Factors(x)+1; fact.factor.f = 0
y = 1; v = fact.factor.1; n = 1
do i = 2 to f
a = fact.factor.i
if a = v then
n = n+1
else do
y = y*v**(n-1)*(v-1)
v = a; n = 1
end
end
return y
Totients:
/* Euler's totient numbers */
procedure expose toti.
arg x
/* Recurring sequence */
do i = 1 to x
toti.totient.i = i
end
do i = 2 to x
if toti.totient.i < i then
iterate i
do j = i by i to x
toti.totient.j = toti.totient.j-toti.totient.j/i
end
end
toti.0 = x
return x
include Functions
include Numbers
include Sequences
include Abend

View file

@ -0,0 +1,99 @@
-- 8 May 2025
include Settings
say 'TOTIENT FUNCTION (PHI)'
say version
numeric digits 10; m = 6
call First25A
call PrimeCountA m
say Format(Time('e'),,3) 'seconds'; say
call Time('r')
call First25B m
call PrimeCountB m
say Format(Time('e'),,3) 'seconds'
exit
First25A:
procedure
say 'A: using calls to function Totient()'; say
say ' N Phi(N) Prime?'
say Copies('-',16)
n = 0
do i = 1 to 25
p = Totient(i)
if p = i-1 then do
n = n+1; pr = 'Yes'
end
else
pr = ''
say Right(i,2) Right(p,6) pr
end
say Copies('-',16); say
say 'Found' Right(n,6) 'PrimeS <' Right(25,8)
return
PrimeCountA:
procedure
arg x
n = 0; d = 1
do i = 1
p = Totient(i)
if p = i-1 then
n = n+1
e = Xpon(i)
if e > d then do
say 'Found' Right(n,6) 'PrimeS <' Right(10**e,8)
if e > x-1 then
leave i
d = e
end
end
say
return
First25B:
procedure expose toti.
arg m
say 'B: generate and save all TotientS, use the stored values'; say
call TotientS 10**m
say ' N Phi(N) Prime?'
say Copies('-',16)
n = 0
do i = 1 to 25
p = toti.i
if p = i-1 then do
n = n+1; pr = 'Yes'
end
else
pr = ''
say Right(i,2) Right(p,6) pr
end
say Copies('-',16)
say
say 'Found' Right(n,6) 'PrimeS <' Right(25,8)
return
PrimeCountB:
procedure expose toti.
arg x
n = 0; d = 1
do i = 1
p = toti.i
if p = i-1 then
n = n+1
e = Xpon(i)
if e > d then do
say 'Found' Right(n,6) 'PrimeS <' Right(10**e,8)
if e > x-1 then
leave i
d = e
end
end
say
return
include Functions
include Special
include Numbers
include Sequences
include Abend