Post Reply 
(PC-12xx~14xx) qthsh Tanh-Sinh quadrature
04-08-2021, 11:20 AM
Post: #37
RE: (PC-12xx~14xx) qthsh Tanh-Sinh quadrature
(04-08-2021 01:29 AM)robve Wrote:  I only made the small change to replace:

Code:
      double ch = cosh(t);
      double ecs = cosh(M_PI/2 * sqrt(ch*ch - 1));
      double r = sqrt(ecs*ecs - 1)/ecs;
      double w = 1/(ecs*ecs);
with these optimizations:
Code:
    ex = eh = exp(h);
    if (k > 0)
      eh *= eh;
    do {
      double ch = (ex+1/ex)/2; // = cosh(t)
      double u = exp(M_PI*(ex-1/ex)/4);
      double ecs = u+1/u;      // = 2*cosh(M_PI*(ex-1/ex)/4);
      double r = (u-1/u)/ecs;  // = tanh(pi/2*sinh(t))
      double w = 4/(ecs*ecs);
      ...
      ex *= eh;

The optimized code evaluates the same number of functions for all 818 integrals. There is no difference.

Secondly, the absolute error of the results to the exact result is actually smaller for every integral with the optimized version!

I will be happy to share the spreadsheet but you can run the experiment with the zip file I shared earlier by making the changes to the wp34s.sh code as shown above.

- Rob

With these small changes in the Python code (in fact I copied it from your post above) I do see differences in the results. Usually only in the last digit, but enough to get (a really small) decrement on correct digits and a small but noticeable increment in TNFE (this time mainly in the sin(40πx) case). In 32 out of 160 cases the true absolute error get (slightly) worse. Of them, 14 have mutated from 0 true absolute error, to != 0.

Adding the other modifications (suppressing the remaining sqrt, j and t, that's: the code now on GitHub) degraded TNFE mainly because one of the integrals (1 - sqrt(2)*cosh(x)/sqrt(cosh(2*x)), from -inf to +inf) needed one more level. This particular case worsened dramatically, from 13 correct digits with strength reduction to only 4 with these changes). I think this is the only case that worth the effort to study it.

Regards.
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 - emece67 - 04-08-2021 11:20 AM



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