Post Reply 
HP PPL and Statistical distributions
05-22-2021, 05:18 PM
Post: #18
RE: HP PPL and Statistical distributions
Thanks a lot to Albert Chan who reduced the computation time to 1 second / 1.2 seconds (HP PRIME G2).
In some posts I have noticed that the HP PRIME calculator becomes even faster if programmed in PYTHON language. Therefore, I tried to translate Albert Chan's quad6-program from #Cas ... #end to PYTHON. However, I was unable to get the program to work - where am I wrong? Below the program:

Code:

#PYTHON EXPORT quadr6
from sys import *
from math import *
f=argv[0]
a=float(argv[1])
b=float(argv[2])
d=float(argv[3])
n=float(argv[4])
eps=float(argv[5])
fp = fm = k = c = 0.
t0 = 7.38905609893065 # e^2
mode = (a-a != 0) + 2* (b-b != 0)
if mode == 0: # tanh-sinh
    c, d, s = d, (b-a)/2, f((a+b)/2)
else:
    if mode == 3: # sinh-sinh
        s = f(c)
    else: # exp-sinh
        if mode == 2:
            c = a
        else:
            c =b
        if bool(a>b) == bool(mode==2):
            d = −d
        s = f(c+d)
while err >=10*eps*abs(s) or k<n:
    p, t, t1 = 0, sqrt(t0), t0
    if k==0:
        t1 = t
    t0 = t
    if mode == 0:
        while abs(y) >= eps*abs(p):
            u = exp(1/t-t)
            r = 2*u/(1+u)
            x = d*r
            if a+x != a:
                y = f(a+x)
                if y-y == 0:
                    fp = y
                else:
                    fp *= c
            if b-x != b:
                y = f(b-x)
                if y-y==0:
                    fm =y
                else:
                    fm *=c
            y = (t+1/t)*r/(1+u) * (fp+fm)
            p, t = p+y, t*t1
    else:
        t *= 0.5
        while abs(fp) >= eps*abs(p):
            r = exp(t-0.25/t)
            u = r
            fp =0
            if mode == 3:
                r = 0.5*r - 0.5/r
                u = 0.5*u + 0.5/u
                y = f(c-d*r)
                if y-y == 0:
                    fp = y*u
            else:
                x = c + d/r
                if x == c:
                    break
                y = f(x)
                if y-y == 0:
                    fp = y/u
            y = f(c+d*r)
            if y-y == 0:
                fp += y*u
            fp *= (t+0.25/t)
            p, t = p+fp, t*t1
    s, err, k = s+p, abs(s-p), k+1
if mode == 1 or (mode==3 and a>b):
    d = −d
ris=[d*ldexp(s,1-k), err/abs(s)] 
print(ris) 
#end


EXPORT Quadratura_Python(f,a,b,d,n,eps)
BEGIN
PYTHON(quadr6,f,a,b,d,n,eps);
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP PPL and Statistical distributions - robmio - 05-22-2021 05:18 PM



User(s) browsing this thread: 2 Guest(s)