Post Reply 
(PC-12xx~14xx) qthsh Tanh-Sinh quadrature
04-07-2021, 12:15 PM (This post was last modified: 04-07-2021 02:25 PM by robve.)
Post: #31
RE: (PC-12xx~14xx) qthsh Tanh-Sinh quadrature
(04-06-2021 06:26 PM)emece67 Wrote:  OK, I see now. I've changed it to:
...

There is also this part:

Code:
    while True:
      # try to avoid the computation of too many exp functions...
      ch = cosh(t)
      # pi/2*sinh(t)
      pi2sh = pi2*sqrt(ch**2 - 1)
      ecs = exp(pi2sh) if expsinh else cosh(pi2sh)

We can try a little harder to avoid computation of too many functions. Strength reduction is also applicable to the WP34S code to remove an exp() and then a sqrt() from the inner loop:
Code:
    ex = eh = exp(t)
    if level > 0:
      eh *= eh
    while True:
      ch = (ex+1/ex)/2               # cosh(t)
      pi2sh = pi2*(ex-1/ex)/2        # pi/2*sinh(t)
      ecs = exp(pi2sh) if expsinh else cosh(pi2sh)
      ...
      t = j*h
      ex *= eh

Another sqrt() can be removed from the inner loop by reusing exp(pi2sh) to replace cosh(pi2sh) and to get tanh(pi2sh) almost for free:

Code:
      ch = (ex+1/ex)/2               # cosh(t)
      pi2sh = pi2*(ex-1/ex)/2        # pi/2*sinh(t)
      r = ecs = exp(pi2sh)
      if not expsinh:
        ecs += 1/r         # 2*cosh(pi2sh)
        r -= 1/r           # 2*sinh(pi2sh)
        if tanhsinh:
          r /= ecs         # tanh(pi2sh)
        ecs /= 2           # cosh(pi2sh)
      w = 1/ecs**2 if tanhsinh else ecs
      ...
      t = j*h
      ex *= eh

- Rob

Edit: corrected code in the last block, typo made when translating from C

"I count on old friends" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (PC-12xx~14xx) qthsh Tanh-Sinh quadrature - robve - 04-07-2021 12:15 PM



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