### Author Topic: graph of the gamma function (Euler-Mascheroni)  (Read 770 times)

0 Members and 1 Guest are viewing this topic.

#### BSpinoza ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #15 on: August 24, 2021, 02:04:23 PM »
I've attached my screenshot (value with full 16 digits) made with my 64bit Linux (Q4OS).
I have the same result with Windows 10, 64 bit.
Could it be that you have an 32 bit system  and this is the reason for this different results?

"Simplicity is the result of maturity."  Friedrich Schiller

#### bplus ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #16 on: August 24, 2021, 02:50:57 PM »
Quote
Could it be that you have an 32 bit system  and this is the reason for this different results?

No.

Could it be your line #4 is different than your line #4 from before?

But I don't really think that explains our difference. No my theory rests upon the different voltage they use in  Europe ;-))
« Last Edit: August 24, 2021, 02:53:50 PM by bplus »

#### bplus ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #17 on: August 24, 2021, 03:00:37 PM »
Dang my screen shot cut off the QB64 x 64 icon at top left corner, sorry.

I thought I was doing good showing the version number in bottom right corner, wait that should be assoc with x64 too.
« Last Edit: August 24, 2021, 03:02:10 PM by bplus »

#### BSpinoza ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #18 on: August 25, 2021, 01:38:27 AM »
@bplus:

Quote
Could it be your line #4 is different than your line #4 from before?
Yes, I reduced the number of iterations a little bit and 500 is enough for a 16 digit precision.

I can not explain our difference in the results (The voltage is a good theory ! ;-) )

As conclusion: My result is the better one and give me what I expect.  So this all remains as your problem ...   ;-)
(Change the voltage!)

Perhaps somebody else has an idea what the reason is for this different program results!

jack has written:

Quote
_Pi will only give Pi to double precision, if you want Pi to _Float precision then don't use _Pi(1)

This could be right, but this is not an explanation for our difference, because we both use _PI(1).

"Simplicity is the result of maturity."  Friedrich Schiller

#### SMcNeill ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #19 on: August 25, 2021, 04:39:47 AM »
The difference in precision might be between the stable build and the development build.  If you guys remember, Luke pushed some changes into the source a while back which alters 64-bit precision with the development builds.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

#### BSpinoza ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #20 on: August 25, 2021, 06:37:13 AM »
SMcNeill has written:

Quote
The difference in precision might be between the stable build and the development build.

I'm not sure:
I have written this code for the Gamma function in 2017 and I remember that I had the same precision.
My selfmade UPN calculator , which implements this gamma function (I had an old exe from 2018) delivers the same good precision:

"Simplicity is the result of maturity."  Friedrich Schiller

#### bplus ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #21 on: August 25, 2021, 08:38:30 AM »
Thanks BSpinoza, just for the record I tried older stable versions of QB64 and get same.

All this makes me wonder what others are getting? What is the voltage in Australia or Brazil or India? ;-))

#### _vince ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #22 on: August 26, 2021, 07:03:55 AM »
I did a little experiment by numerically integrating

\int_0^1 log(1/t)^(z - 1) dt for Re(z) > 0

then using the reflection formula Gamma(z)Gamma(-z) = -pi / (z*sin(pi*z)) to get Re(z) < 0

and drawing a real plot and a domain colouring plot (ie https://en.wikipedia.org/wiki/Gamma_function#/media/File:Gamma1.png)

You can see that the real plot looks okay visually but the complex plot shows the integration errors around x=0

#### BSpinoza ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #23 on: August 27, 2021, 07:14:20 AM »
jack sended me a pm with his construction of a gamma approximation
("' it's a blend of the Spouge and Lanczos method")   ->    @jack: Many thanks!!!

Code: QB64: [Select]
1. ' -------------- gamma function --------------------------
2. ' The (complete) gamma function â(n) is defined to be an extension
3. ' of the factorial to complex and real number arguments.
4. ' It is related to the factorial by
5. ' â(n)=(n-1)!,
6. '
7. ' a slightly unfortunate notation due to Legendre which is now universally
8. ' used instead of Gauss's simpler Pi(n)=n! (Gauss 1812; Edwards 2001, p. 8).
9. ' ( from: ttps://mathworld.wolfram.com/GammaFunction.html)
10. ' ---------------------------------------------------------
11. ' jack constructed this gamma approximation,
12. ' it's a blend of the Spouge and Lanczos method
13. ' ---------------------------------------------------------
14.
15.
16. 'DIM I AS LONG, n AS LONG
17.
18. PRINT "  Keisan (CASIO online calculator):"
19. PRINT "        â(1.25) = 0.90640247705547707798267128896691800074879192072  "
20. PRINT "  Approximations:"
21. PRINT USING "  Stirling       ##.###################^^^^^"; gamma_stirling##(1.25)
22. PRINT USING "  Spouge/Lanczos ##.###################^^^^^"; gamma_spouge##(1.25)
23. PRINT "--------------------------------------------------------------------------"
24. PRINT "  Keisan (CASIO online calculator):"
25. PRINT "         â(100) = 9.332621544394415268169923885626670049071596826E+155"
26. PRINT "  Approximations:"
27. PRINT USING "  Stirling       ##.###################^^^^^"; gamma_stirling##(100)
28. PRINT USING "  Spouge/Lanczos ##.###################^^^^^"; gamma_spouge##(100)
29.
30.
31.
32. FUNCTION gamma_stirling## (x##)
33.     DIM AS LONG I, n
34.     DIM AS _FLOAT a, b, c
35.     PI## = 3.141592653589793238462643383F0
36.     n = 500
37.     a = (x## + n)
38.     b = x##
39.     FOR I = 1 TO (n - 1)
40.         b = b * (x## + I)
41.     NEXT I
42.     gamma_stirling## = SQR((2 * PI##) / a) * a ^ a * EXP(a * (-1) + (1 / (12 * a)) - (1 / (360 * a ^ 3))) / b
43.
44.
45. FUNCTION gamma_spouge## (z AS _FLOAT) ' blend of the Spouge and Lanczos approximation method by jack
46.     DIM AS _FLOAT a, y, y2
47.     z = z - 1
48.     a = 11##
49.     y = (275.9379958989626453381F0 + 2.506628274631000413006F0 * z)
50.     y = (13669.27934220190127409F0 + y * z)
51.     y = (4.012693332808590111572F5 + y * z)
52.     y = (7.730287584695298154390F6 + y * z)
53.     y = (1.021171143779219783165F8 + y * z)
54.     y = (9.367828308832242704191F8 + y * z)
55.     y = (5.892810811988612011167F9 + y * z)
56.     y = (2.432626162101472730328F10 + y * z)
57.     y = (5.950924515204440739993F10 + y * z)
58.     y = 6.550975741601077694099F10 + y * z
59.
60.     y2 = (55## + z)
61.     y2 = (1320## + y2 * z)
62.     y2 = (18150## + y2 * z)
63.     y2 = (157773## + y2 * z)
64.     y2 = (902055## + y2 * z)
65.     y2 = (3416930## + y2 * z)
66.     y2 = (8409500## + y2 * z)
67.     y2 = (12753576## + y2 * z)
68.     y2 = (10628640## + y2 * z)
69.     y2 = (3628800## + y2 * z)
70.     y = y / y2
71.
72.     y = y * (z + a) ^ (z + .5##) * EXP(-z - a)
73.     gamma_spouge## = y
At the End of this post you see my result.

@ bplus: Perhaps you could check this version. It would be interesting if you have a lower precision too.

"Simplicity is the result of maturity."  Friedrich Schiller

#### bplus ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #24 on: August 27, 2021, 10:52:03 AM »
Quote
@ bplus: Perhaps you could check this version. It would be interesting if you have a lower precision too.

Hi @BSpinoza

Jack has already advised me to get latest dev build because of this (Luke's fix of precision):
https://www.qb64.org/forum/index.php?topic=3987.msg133338#msg133338

Plus what Fellippe has been doing with debugging, yep!, definitely time for update.

For me, I already solved the problem of running code with extended precision with my not-so-basic interpreter.
(A little plug): https://www.qb64.org/forum/index.php?topic=3723.msg130797#msg130797
It does that calculation that gets close to 500 terms in the Fibonacci sequence which as you know takes thousands of digits to get right. :)
https://www.qb64.org/forum/index.php?topic=2921.msg133318#msg133318

And thanks again to jack for helping me get it debugged.
« Last Edit: August 27, 2021, 11:00:48 AM by bplus »

#### jack ##### Re: graph of the gamma function (Euler-Mascheroni)
« Reply #25 on: August 27, 2021, 11:35:43 AM »
@BSpinoza if you are interested in how I derived the coefficients for the Spouge/Lanczos gamma function let me know