Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,21 @@
defmodule Gamma do
@a [ 1.00000_00000_00000_00000, 0.57721_56649_01532_86061, -0.65587_80715_20253_88108,
-0.04200_26350_34095_23553, 0.16653_86113_82291_48950, -0.04219_77345_55544_33675,
-0.00962_19715_27876_97356, 0.00721_89432_46663_09954, -0.00116_51675_91859_06511,
-0.00021_52416_74114_95097, 0.00012_80502_82388_11619, -0.00002_01348_54780_78824,
-0.00000_12504_93482_14267, 0.00000_11330_27231_98170, -0.00000_02056_33841_69776,
0.00000_00061_16095_10448, 0.00000_00050_02007_64447, -0.00000_00011_81274_57049,
0.00000_00001_04342_67117, 0.00000_00000_07782_26344, -0.00000_00000_03696_80562,
0.00000_00000_00510_03703, -0.00000_00000_00020_58326, -0.00000_00000_00005_34812,
0.00000_00000_00001_22678, -0.00000_00000_00000_11813, 0.00000_00000_00000_00119,
0.00000_00000_00000_00141, -0.00000_00000_00000_00023, 0.00000_00000_00000_00002 ]
|> Enum.reverse
def taylor(x) do
y = x - 1
1 / Enum.reduce(@a, 0, fn a,sum -> sum * y + a end)
end
end
Enum.each(Enum.map(1..10, &(&1/3)), fn x ->
:io.format "~f ~18.15f~n", [x, Gamma.taylor(x)]
end)

View file

@ -0,0 +1,25 @@
2 constant (gamma-shift) \ don't change this
\ an approximation of the d(x) function
: ~d(x) ( f1 -- f2)
fdup 10 s>f f< \ use first symmetrical sigmoidal
if \ for range 1-10
-2705443e-8 fswap 2280802e-6 f/ 1428045e-6 f** 1 s>f f+ f/ 3187831e-8 f+
else \ use second symmetrical sigmoidal
-29372563e-9 fswap 1841693e-6 f/ 1052779e-6 f** 1 s>f f+ f/ 3330828e-8 f+
then 333333333e-10 fover f< if fdrop 1 s>f 30 s>f f/ then
; \ perform some sane clipping to infinity
: (ramanujan) ( f1 -- f2)
fdup fdup f* 4 s>f f* ( n 4n2)
fover fover f* fdup f+ f+ fover f+ ( n 8n3+4n2+n)
fover ~d(x) f+ ( n 8n3+4n2+n+d[x])
1 s>f 6 s>f f/ f** ( n 8n3+4n2+n+d[x]^1/6)
fswap fdup 2.7182818284590452353e f/ ( 8n3+4n2+n+d[x]^1/6 n n/e)
fswap f** f* pi fsqrt f* ( f)
;
: gamma ( f1 -- f2)
fdup f0< >r fdup f0= r> or abort" Gamma less or equal to zero"
fdup (gamma-shift) 1- s>f f+ (ramanujan) fswap
1 s>f (gamma-shift) 0 do fover i s>f f+ f* loop fswap fdrop f/
;

View file

@ -16,7 +16,7 @@ sub Γ(\z) {
-0.7423452510201416151527e-2
0.5384136432509564062961e-7
-0.4023533141268236372067e-8
> Z* 1, map 1/(z + *), 0..*
> Z* 1, |map 1/(z + *), 0..*
}
say Γ($_) for 1/3, 2/3 ... 10/3;

View file

@ -1,68 +1,68 @@
/*REXX pgm calculates GAMMA using Taylor series coefficients, ≈80 digits*/
/*The GAMMA function symbol is the Greek capital letter: Γ */
numeric digits 84 /*able to use extended precision.*/
parse arg y z . /*allow specification of Γ arg.*/
/*either show a range or a ··· */
do j=word(y 1,1) to word(z y 9,1) /* ··· single gamma value(s). */
say 'gamma('j") =" gamma(j) /*compute gamma of J and display.*/
/*REXX pgm calculates GAMMA using Taylor series coefficients, ≈80 decimal digs*/
/*The GAMMA function symbol is the Greek capital letter: Γ */
numeric digits 90 /*be able to handle extended precision.*/
parse arg y z . /*allow specification of gamma argument*/
/* [↓] either show a range or a ··· */
do j=word(y 1,1) to word(z y 9,1) /* ··· single gamma value(s). */
say 'gamma('j") =" gamma(j) /*compute gamma of J and display value.*/
end /*j*/
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────────GAMMA subroutine=──────────────────*/
exit /*stick a fork in it, we're all done. */
/*───────────────────────────────────GAMMA subroutine─────────────────────────────────*/
gamma: procedure; parse arg x; xm=x-1; sum=0
/*coefficients thanks to: Arne Fransén and Staffan Wrigge.*/
#.1 = 1 /* [↓] #.2 is the Euler-Mascheroni constant.*/
#.2 = 0.57721566490153286060651209008240243104215933593992359880576723488486772677766467
#.3 = -0.65587807152025388107701951514539048127976638047858434729236244568387083835372210
#.4 = -0.04200263503409523552900393487542981871139450040110609352206581297618009687597599
#.5 = 0.16653861138229148950170079510210523571778150224717434057046890317899386605647425
#.6 = -0.04219773455554433674820830128918739130165268418982248637691887327545901118558900
#.7 = -0.00962197152787697356211492167234819897536294225211300210513886262731167351446074
#.8 = 0.00721894324666309954239501034044657270990480088023831800109478117362259497415854
#.9 = -0.00116516759185906511211397108401838866680933379538405744340750527562002584816653
#.10 = -0.00021524167411495097281572996305364780647824192337833875035026748908563946371678
#.11 = 0.00012805028238811618615319862632816432339489209969367721490054583804120355204347
#.12 = -0.00002013485478078823865568939142102181838229483329797911526116267090822918618897
#.13 = -0.00000125049348214267065734535947383309224232265562115395981534992315749121245561
#.14 = 0.00000113302723198169588237412962033074494332400483862107565429550539546040842730
#.15 = -0.00000020563384169776071034501541300205728365125790262933794534683172533245680371
#.16 = 0.00000000611609510448141581786249868285534286727586571971232086732402927723507435
#.17 = 0.00000000500200764446922293005566504805999130304461274249448171895337887737472132
#.18 = -0.00000000118127457048702014458812656543650557773875950493258759096189263169643391
#.19 = 0.00000000010434267116911005104915403323122501914007098231258121210871073927347588
#.20 = 0.00000000000778226343990507125404993731136077722606808618139293881943550732692987
#.21 = -0.00000000000369680561864220570818781587808576623657096345136099513648454655443000
#.22 = 0.00000000000051003702874544759790154813228632318027268860697076321173501048565735
#.23 = -0.00000000000002058326053566506783222429544855237419746091080810147188058196444349
#.24 = -0.00000000000000534812253942301798237001731872793994898971547812068211168095493211
#.25 = 0.00000000000000122677862823826079015889384662242242816545575045632136601135999606
#.26 = -0.00000000000000011812593016974587695137645868422978312115572918048478798375081233
#.27 = 0.00000000000000000118669225475160033257977724292867407108849407966482711074006109
#.28 = 0.00000000000000000141238065531803178155580394756670903708635075033452562564122263
#.29 = -0.00000000000000000022987456844353702065924785806336992602845059314190367014889830
#.30 = 0.00000000000000000001714406321927337433383963370267257066812656062517433174649858
#.31 = 0.00000000000000000000013373517304936931148647813951222680228750594717618947898583
#.32 = -0.00000000000000000000020542335517666727893250253513557337960820379352387364127301
#.33 = 0.00000000000000000000002736030048607999844831509904330982014865311695836363370165
#.34 = -0.00000000000000000000000173235644591051663905742845156477979906974910879499841377
#.35 = -0.00000000000000000000000002360619024499287287343450735427531007926413552145370486
#.36 = 0.00000000000000000000000001864982941717294430718413161878666898945868429073668232
#.37 = -0.00000000000000000000000000221809562420719720439971691362686037973177950067567580
#.38 = 0.00000000000000000000000000012977819749479936688244144863305941656194998646391332
#.39 = 0.00000000000000000000000000000118069747496652840622274541550997151855968463784158
#.40 = -0.00000000000000000000000000000112458434927708809029365467426143951211941179558301
#.41 = 0.00000000000000000000000000000012770851751408662039902066777511246477487720656005
#.42 = -0.00000000000000000000000000000000739145116961514082346128933010855282371056899245
#.43 = 0.00000000000000000000000000000000001134750257554215760954165259469306393008612196
#.44 = 0.00000000000000000000000000000000004639134641058722029944804907952228463057968680
#.45 = -0.00000000000000000000000000000000000534733681843919887507741819670989332090488591
#.46 = 0.00000000000000000000000000000000000032079959236133526228612372790827943910901464
#.47 = -0.00000000000000000000000000000000000000444582973655075688210159035212464363740144
#.48 = -0.00000000000000000000000000000000000000131117451888198871290105849438992219023663
#.49 = 0.00000000000000000000000000000000000000016470333525438138868182593279063941453996
#.50 = -0.00000000000000000000000000000000000000001056233178503581218600561071538285049997
#.51 = 0.00000000000000000000000000000000000000000026784429826430494783549630718908519485
#.52 = 0.00000000000000000000000000000000000000000002424715494851782689673032938370921241
do j=52 by -1 to 1
sum = sum * xm + #.j
end /*j*/
/*coefficients thanks to: Arne Fransén and Staffan Wrigge.*/
#.1= 1 /* [↓] #.2 is the Euler-Mascheroni constant. */
#.2= 0.57721566490153286060651209008240243104215933593992359880576723488486772677766467
#.3=-0.65587807152025388107701951514539048127976638047858434729236244568387083835372210
#.4=-0.04200263503409523552900393487542981871139450040110609352206581297618009687597599
#.5= 0.16653861138229148950170079510210523571778150224717434057046890317899386605647425
#.6=-0.04219773455554433674820830128918739130165268418982248637691887327545901118558900
#.7=-0.00962197152787697356211492167234819897536294225211300210513886262731167351446074
#.8= 0.00721894324666309954239501034044657270990480088023831800109478117362259497415854
#.9=-0.00116516759185906511211397108401838866680933379538405744340750527562002584816653
#.10=-0.00021524167411495097281572996305364780647824192337833875035026748908563946371678
#.11= 0.00012805028238811618615319862632816432339489209969367721490054583804120355204347
#.12=-0.00002013485478078823865568939142102181838229483329797911526116267090822918618897
#.13=-0.00000125049348214267065734535947383309224232265562115395981534992315749121245561
#.14= 0.00000113302723198169588237412962033074494332400483862107565429550539546040842730
#.15=-0.00000020563384169776071034501541300205728365125790262933794534683172533245680371
#.16= 0.00000000611609510448141581786249868285534286727586571971232086732402927723507435
#.17= 0.00000000500200764446922293005566504805999130304461274249448171895337887737472132
#.18=-0.00000000118127457048702014458812656543650557773875950493258759096189263169643391
#.19= 0.00000000010434267116911005104915403323122501914007098231258121210871073927347588
#.20= 0.00000000000778226343990507125404993731136077722606808618139293881943550732692987
#.21=-0.00000000000369680561864220570818781587808576623657096345136099513648454655443000
#.22= 0.00000000000051003702874544759790154813228632318027268860697076321173501048565735
#.23=-0.00000000000002058326053566506783222429544855237419746091080810147188058196444349
#.24=-0.00000000000000534812253942301798237001731872793994898971547812068211168095493211
#.25= 0.00000000000000122677862823826079015889384662242242816545575045632136601135999606
#.26=-0.00000000000000011812593016974587695137645868422978312115572918048478798375081233
#.27= 0.00000000000000000118669225475160033257977724292867407108849407966482711074006109
#.28= 0.00000000000000000141238065531803178155580394756670903708635075033452562564122263
#.29=-0.00000000000000000022987456844353702065924785806336992602845059314190367014889830
#.30= 0.00000000000000000001714406321927337433383963370267257066812656062517433174649858
#.31= 0.00000000000000000000013373517304936931148647813951222680228750594717618947898583
#.32=-0.00000000000000000000020542335517666727893250253513557337960820379352387364127301
#.33= 0.00000000000000000000002736030048607999844831509904330982014865311695836363370165
#.34=-0.00000000000000000000000173235644591051663905742845156477979906974910879499841377
#.35=-0.00000000000000000000000002360619024499287287343450735427531007926413552145370486
#.36= 0.00000000000000000000000001864982941717294430718413161878666898945868429073668232
#.37=-0.00000000000000000000000000221809562420719720439971691362686037973177950067567580
#.38= 0.00000000000000000000000000012977819749479936688244144863305941656194998646391332
#.39= 0.00000000000000000000000000000118069747496652840622274541550997151855968463784158
#.40=-0.00000000000000000000000000000112458434927708809029365467426143951211941179558301
#.41= 0.00000000000000000000000000000012770851751408662039902066777511246477487720656005
#.42=-0.00000000000000000000000000000000739145116961514082346128933010855282371056899245
#.43= 0.00000000000000000000000000000000001134750257554215760954165259469306393008612196
#.44= 0.00000000000000000000000000000000004639134641058722029944804907952228463057968680
#.45=-0.00000000000000000000000000000000000534733681843919887507741819670989332090488591
#.46= 0.00000000000000000000000000000000000032079959236133526228612372790827943910901464
#.47=-0.00000000000000000000000000000000000000444582973655075688210159035212464363740144
#.48=-0.00000000000000000000000000000000000000131117451888198871290105849438992219023663
#.49= 0.00000000000000000000000000000000000000016470333525438138868182593279063941453996
#.50=-0.00000000000000000000000000000000000000001056233178503581218600561071538285049997
#.51= 0.00000000000000000000000000000000000000000026784429826430494783549630718908519485
#.52= 0.00000000000000000000000000000000000000000002424715494851782689673032938370921241
#=52; do k=# by -1 for #
sum=sum*xm + #.k
end /*k*/
return 1/sum