2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,45 +1,50 @@
/*REXX program to implement the Trabb─Pardo-Knuth algorithm for N numbers.*/
N=11 /*N is the number of numbers to be used*/
maxValue=400 /*the maximum value f(x) can have. */
compDigs=200 /*compute with this many decimal digits*/
showDigs=20 /* ··· but only show this many digits.*/
numeric digits compDigs /*the number of digits precision to use*/
say ' _____ ' /*vinculum.*/
/*REXX program implements the Trabb─Pardo-Knuth algorithm for N numbers (default is 11).*/
parse arg N .; if N=='' | N=="," then N=11 /*Not specified? Then use the default.*/
maxValue=400 /*the maximum value f(x) can have. */
wid= 20 /* ··· but only show this many digits.*/
frac= 5 /* ··· show this # of fractional digs.*/
numeric digits 200 /*the number of digits precision to use*/
say ' _____ ' /* ◄───── display a vinculum.*/
say 'function: ƒ(x) x + (5 * x^3)'
prompt= 'enter ' N " numbers for the Trabb─Pardo─Knuth algorithm: (or Quit)"
prompt= 'enter ' N " numbers for the Trabb─Pardo─Knuth algorithm: (or Quit)"
/*▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ */
do ask=0; say; say prompt; say; pull $; say /**/
if abbrev('QUIT',$,1) then exit /*does the user want to QUIT this pgm? */ /**/
do ask=0; say; say prompt; say; pull $; say /**/
if abbrev('QUIT',$,1) then do; say 'quitting.'; exit 1; end /**/
ok=0 /**/
select /*validate that there are N numbers. */ /**/
when $='' then say 'no numbers entered' /**/
when words($)<N then say 'not enough numbers entered' /**/
when words($)>N then say 'too many numbers entered' /**/
select /*validate there're N numbers.*/ /**/
when $='' then say "no numbers entered" /**/
when words($)<N then say "not enough numbers entered" /**/
when words($)>N then say "too many numbers entered" /**/
otherwise ok=1 /**/
end /*select*/ /**/
if \ok then iterate /* [↓] is max width*/ /**/
if \ok then iterate /* [↓] is max width.*/ /**/
w=0; do v=1 for N; _=word($,v); w=max(w,length(_)) /**/
if datatype(_,'N') then iterate /*numeric ? */ /**/
if datatype(_,'N') then iterate /*numeric ? */ /**/
say _ "isn't numeric"; iterate ask /**/
end /*v*/ /**/
leave /**/
end /*ask*/ /**/
say 'numbers entered: ' $; say /**/
/*▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ */
do i=N by -1 to 1; #=word($,i)/1 /*process nums in reverse. */
numeric digits compDigs; g=f(#) /*for func. ƒ, use big digs*/
numeric digits showdigs; g=g/1 /*scale down output digits.*/
gw=right('ƒ('#") ",w+7) /*nice formatted ƒ(number)*/
if g>maxValue then say gw "is > " maxValue ' ['g"]"
else say gw " = " g /*display the (good) result*/
end /*i*/
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
f: procedure; parse arg x; return sqrt(abs(x)) + 5 * x**3
/*────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); i=; m.=9
numeric digits 9; numeric form; h=d+6; if x<0 then do; x=-x; i='i'; end
parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'e'_%2
do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/
numeric digits d; return (g/1)i /*make complex if X < 0.*/
say 'numbers entered: ' $
say
do i=N by -1 to 1; #=word($,i)/1 /*process the numbers in reverse. */
g = fmt( f( # ) ) /*invoke function ƒ with arg number.*/
gw=right( 'ƒ('#") ", w+7) /*nicely formatted ƒ(number). */
if g>maxValue then say gw "is > " maxValue ' ['space(g)"]"
else say gw " = " g
end /*i*/ /* [+] display the result to terminal.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
f: procedure; parse arg x; return sqrt( abs(x) ) + 5 * x**3
/*──────────────────────────────────────────────────────────────────────────────────────*/
fmt: z=right(translate(format(arg(1),wid,frac),'e',"E"),wid) /*right adjust; use e*/
if pos(.,z)\==0 then z=left(strip(strip(z,'T',0),"T",.),wid) /*strip trailing 0 &.*/
return right(z,wid-4*(pos('e',z)==0)) /*adjust: no exponent*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); m.=9; numeric form; h=d+6
numeric digits; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g *.5'e'_ % 2
do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/
return g