Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,112 +0,0 @@
with Ada.Command_Line;
with Ada.Text_IO;
with GNU_Multiple_Precision.Big_Integers;
with GNU_Multiple_Precision.Big_Rationals;
use GNU_Multiple_Precision;
procedure Pi_Digits is
type Int is mod 2 ** 64;
package Int_To_Big is new Big_Integers.Modular_Conversions (Int);
-- constants
Zero : constant Big_Integer := Int_To_Big.To_Big_Integer (0);
One : constant Big_Integer := Int_To_Big.To_Big_Integer (1);
Two : constant Big_Integer := Int_To_Big.To_Big_Integer (2);
Three : constant Big_Integer := Int_To_Big.To_Big_Integer (3);
Four : constant Big_Integer := Int_To_Big.To_Big_Integer (4);
Ten : constant Big_Integer := Int_To_Big.To_Big_Integer (10);
-- type LFT = (Integer, Integer, Integer, Integer
type LFT is record
Q, R, S, T : Big_Integer;
end record;
-- extr :: LFT -> Integer -> Rational
function Extr (T : LFT; X : Big_Integer) return Big_Rational is
use Big_Integers;
Result : Big_Rational;
begin
-- extr (q,r,s,t) x = ((fromInteger q) * x + (fromInteger r)) /
-- ((fromInteger s) * x + (fromInteger t))
Big_Rationals.Set_Numerator (Item => Result,
New_Value => T.Q * X + T.R,
Canonicalize => False);
Big_Rationals.Set_Denominator (Item => Result,
New_Value => T.S * X + T.T);
return Result;
end Extr;
-- unit :: LFT
function Unit return LFT is
begin
-- unit = (1,0,0,1)
return LFT'(Q => One, R => Zero, S => Zero, T => One);
end Unit;
-- comp :: LFT -> LFT -> LFT
function Comp (T1, T2 : LFT) return LFT is
use Big_Integers;
begin
-- comp (q,r,s,t) (u,v,w,x) = (q*u+r*w,q*v+r*x,s*u+t*w,s*v+t*x)
return LFT'(Q => T1.Q * T2.Q + T1.R * T2.S,
R => T1.Q * T2.R + T1.R * T2.T,
S => T1.S * T2.Q + T1.T * T2.S,
T => T1.S * T2.R + T1.T * T2.T);
end Comp;
-- lfts = [(k, 4*k+2, 0, 2*k+1) | k<-[1..]
K : Big_Integer := Zero;
function LFTS return LFT is
use Big_Integers;
begin
K := K + One;
return LFT'(Q => K,
R => Four * K + Two,
S => Zero,
T => Two * K + One);
end LFTS;
-- next z = floor (extr z 3)
function Next (T : LFT) return Big_Integer is
begin
return Big_Rationals.To_Big_Integer (Extr (T, Three));
end Next;
-- safe z n = (n == floor (extr z 4)
function Safe (T : LFT; N : Big_Integer) return Boolean is
begin
return N = Big_Rationals.To_Big_Integer (Extr (T, Four));
end Safe;
-- prod z n = comp (10, -10*n, 0, 1)
function Prod (T : LFT; N : Big_Integer) return LFT is
use Big_Integers;
begin
return Comp (LFT'(Q => Ten, R => -Ten * N, S => Zero, T => One), T);
end Prod;
procedure Print_Pi (Digit_Count : Positive) is
Z : LFT := Unit;
Y : Big_Integer;
Count : Natural := 0;
begin
loop
Y := Next (Z);
if Safe (Z, Y) then
Count := Count + 1;
Ada.Text_IO.Put (Big_Integers.Image (Y));
exit when Count >= Digit_Count;
Z := Prod (Z, Y);
else
Z := Comp (Z, LFTS);
end if;
end loop;
end Print_Pi;
N : Positive := 250;
begin
if Ada.Command_Line.Argument_Count = 1 then
N := Positive'Value (Ada.Command_Line.Argument (1));
end if;
Print_Pi (N);
end Pi_Digits;

View file

@ -9,7 +9,7 @@ d: 0
dotWritten: false
while [true][
if? (n*t) > (4*q)+r-t [
switch (n*t) > (4*q)+r-t [
d: d+1
prints n
unless dotWritten [
@ -23,8 +23,7 @@ while [true][
n: ((10*(r + 3*q)) / t) - 10*n
q: q*10
r: nr
]
else [
][
nr: (r + 2*q) * l
nn: ((q*(2 + 7*k)) + r*l) / (t*l)
q: q*k

View file

@ -1,57 +0,0 @@
Function Get-Pi ( $Digits )
{
$Big = [bigint[]](0..10)
$ndigits = 0
$Output = ""
$q = $t = $k = $Big[1]
$r = $Big[0]
$l = $n = $Big[3]
# Calculate first digit
$nr = ( $Big[2] * $q + $r ) * $l
$nn = ( $q * ( $Big[7] * $k + $Big[2] ) + $r * $l ) / ( $t * $l )
$q *= $k
$t *= $l
$l += $Big[2]
$k = $k + $Big[1]
$n = $nn
$r = $nr
$Output += [string]$n + '.'
$ndigits++
$nr = $Big[10] * ( $r - $n * $t )
$n = ( ( $Big[10] * ( 3 * $q + $r ) ) / $t ) - 10 * $n
$q *= $Big[10]
$r = $nr
While ( $ndigits -lt $Digits )
{
While ( $ndigits % 100 -ne 0 -or -not $Output )
{
If ( $Big[4] * $q + $r - $t -lt $n * $t )
{
$Output += [string]$n
$ndigits++
$nr = $Big[10] * ( $r - $n * $t )
$n = ( ( $Big[10] * ( 3 * $q + $r ) ) / $t ) - 10 * $n
$q *= $Big[10]
$r = $nr
}
Else
{
$nr = ( $Big[2] * $q + $r ) * $l
$nn = ( $q * ( $Big[7] * $k + $Big[2] ) + $r * $l ) / ( $t * $l )
$q *= $k
$t *= $l
$l += $Big[2]
$k = $k + $Big[1]
$n = $nn
$r = $nr
}
}
$Output
$Output = ""
}
}

View file

@ -1 +0,0 @@
[math]::pi

View file

@ -1,2 +0,0 @@
.Net digits of pi
3.14159265358979

View file

@ -1,29 +1,36 @@
/*REXX program spits out decimal digits of pi (one digit at a time) until Ctrl─Break.*/
parse arg digs oFID . /*obtain optional argument from the CL.*/
if digs=='' | digs=="," then digs= 1e6 /*Not specified? Then use the default.*/
if oFID=='' | oFID=="," then oFID='PI_SPIT.OUT' /* " " " " " " */
write= digs<0 /*if ODIGS is <0, also spit pi to file.*/
numeric digits abs(digs) + 4 /*with bigger digs, spitting is slower.*/
call time 'Reset' /*reset the wall─clock (elapsed) timer.*/
signal on halt /*───► HALT when Ctrl─Break is pressed.*/
spit= 0 /*the index of the spitted pi dec. digs*/
pi=0; v=5; vv=v*v; g=239; gg=g*g; s= 16 /*assign some values to some variables.*/
r= 4 /*calculate π with increasing accuracy */
do n=1 by 2 until old=pi; old= pi /*just calculate pi with odd integers*/
pi= pi + s / (n*v) - r / (n*g) /* ··· using John Machin's formula.*/
s= -s; r= -r; v= v * vv; g= g * gg /*compute some variables for shortcuts.*/
if n>3 then spit= spit + 1 /*maintain a lag for pi digits rounding*/
if spit<4 then iterate /*Not enough digs yet? Then don't show*/
$= substr(pi, spit-3, 1) /*lag behind the true pi calculation. */
call charout , $ /*write the spitted digits to the term.*/
if write then call charout oFID, $ /* " " " " " a file?*/
end /*n*/
-- 12 Sep 2025
include Setting
signal on halt
arg digs
if digs = '' then
digs=1000
$= substr(pi, spit - 2); L= length($) - 4 /*handle any residual decimal digits. */
if L>0 then do /*if any residual digits, then show 'em*/
call charout , substr($, 1, L) /*write to term. */
if write then call charout oFID, substr($, 1, L) /* " " file? */
end
say /*stick a fork in it, we're all done. */
exit: say; say n%2+1 'iterations took' format(time("Elapsed"),,2) 'seconds.'; exit 0
halt: say; say 'PI_SPIT halted via use of CtrlBreak.'; signal exit /*show iterations.*/
say 'PI - Machin formula'
say version
say
numeric digits digs+4
spit=0; pie=0; v=5; vv=v*v; g=239; gg=g*g; s=16; r=4
do n = 1 by 2 until old = pie
old=pie; pie=pie+s/(n*v)-r/(n*g)
s=-s; r=-r; v=v*vv; g=g*gg
if n > 3 then
spit=spit+1
if spit < 4 then
iterate
dd=SubStr(pie,spit-3,1); call CharOut ,dd
end
dd=SubStr(pie,spit-2); l=Length(dd)-4
if l>0 then
call CharOut ,SubStr(dd,1,l)
say
say 'Specified' digs 'digits exhausted.'
call Timer
exit
Halt:
say
say 'Halted because of Ctrl-Break.'
call Timer
exit
include Math

View file

@ -1,32 +1,40 @@
/*REXX program spits out decimal digits of pi (one digit at a time) until Ctrl-Break.*/
signal on halt /*───► HALT when Ctrl─Break is pressed.*/
parse arg digs oFID . /*obtain optional argument from the CL.*/
if digs=='' | digs=="," then digs= 300 /*Not specified? Then use the default.*/
if oFID=='' | oFID=="," then oFID='PI_SPIT2.OUT' /* " " " " " " */
numeric digits digs /*with bigger digs, spitting is slower.*/
q=1; r=0; t=1; k=1; n=3; L=3; z=0 /*define some REXX variables. */
dot=1 /*DOT≡a flag when a dot in pi is shown.*/
do until z==digs; qq= q+q /* qq is a fast version of: q*2 */
tn= t*n /* t*n is used twice (below). */
if qq+qq+r-t < tn then do; z= z+1 /* qq+qq is faster than qq*2 */
call charout , n
call charout oFID, n
if dot then do; dot=0; call charout , .
call charout oFID, .
end
nr= (r - tn) * 10
n = ((( (qq+q+r) * 10) / t) - n*10) %1
q = q*10
end
else do; nr= (qq+r) * L
tL= t*L
n = (q * (k*7 + 2) + r*L) / tL %1
q = q*k
t = tL
L = L+2
k = k+1
end /* %1≡fast way doing TRUNC of a number.*/
r=nr
end /*forever*/
exit /*stick a fork in it, we're all done. */
halt: say; say 'PI_SPIT2 halted via use of Ctrl-Break.'; exit
-- 12 Sep 2025
include Setting
signal on halt
arg digs
if digs = '' then
digs=1000
say 'PI - Gibbons Spigot'
say version
say
numeric digits digs+4
q=1; r=0; t=1; k=1; n=3; l=3; z=0; dot=1
do until z = digs
qq=q+q; tn=t*n
if qq+qq+r-t < tn then do
z=z+1; call CharOut ,n
if dot then do
dot=0; call CharOut ,.
end
nr=(r-tn)*10; n=((((qq+q+r)*10)/t)-n*10)%1
q=q*10
end
else do
nr=(qq+r)*l; tl=t*l; n=(q*(k*7+2)+r*l)/tl%1
q=q*k; t=tl; l=l+2; k=k+1
end
r=nr
end
say
say 'Specified' digs 'digits exhausted.'
call Timer
exit
Halt:
say
say 'Halted because of Ctrl-Break.'
call Timer
exit
include Math