On Mon, Oct 1, 2012 at 2:06 AM, Fredrik Johansson
<
fredrik....@gmail.com> wrote:
> Hi Ondrej
>
> On Mon, Oct 1, 2012 at 9:38 AM, Ondřej Čertík <
ondrej...@gmail.com> wrote:
>> Hi Fredrik,
>>
>> but hypsum() seems to be just summing up the hypergeometric series for 2F0 here,
>> which has radius of convergence 0.
>> The force_series=True, so it will fail if it doesn't converge.
>
>> But I don't understand the logic here --- how can the series for 2F0 converge?
>> I noticed that ctx_fp.py just has a very simple implementation, but
>> ctx_mp.py is quite complex, it seems to be using some convergence accelerators?
>
> The 2F0 series "converges" when the terms become small enough. This is
> just a heuristic.
Ah I see -- that's why it is called "asymptotic series":
http://mathworld.wolfram.com/AsymptoticSeries.html
so what happens is that for a fixed "x", the series first (typically) converges
a bit, and then starts to diverge. The idea is that in the limit x->0
(in our case),
the series (cut after n terms) always gives the correct asymptotic
expression/limit.
So if "x" is small, we might get lucky to get accurate answer within
our precision.
But I would expect that if you want many digits, eventually you will
not be able to do it
with such a series.
> The complexity in hypsum is mostly intended to take
> care of increasing the precision when parameters are close to negative
> integers and/or there is significant cancellation. Convergence
> acceleration is only used for 3F2, 4F3, etc. on the unit circle.
I see. I saw your blog post:
http://fredrikj.net/blog/2010/07/euler-maclaurin-summation-of-hypergeometric-series/
describing it.
Ah I see, thanks.
>
> In general, you want to use the convergent series for small x and the
> asymptotic series for large x. What to do in between when the
> convergent series has too much cancellation is a very difficult
> problem, unless you accept the overhead of switching to multiprecision
> arithmetic. The DLMF (
http://dlmf.nist.gov/13.29) suggests using
> something called "exponentially-improved expansions". I have not tried
> using them, so I can't say how well they work, but they are probably
> well worth investigating in your case.
I've seen those too, but then I went into mpmath and you didn't use them,
but now I can see, that you just increase the precision and that helps in many
cases. In Fortran, one can easily switch to quadruple precision. It's
just a lot slower.
So maybe for the difficult cases, switching to quadruple might do the job.
Thanks for the tips. So as I can see it, I first need to implement 2F0 for small
arguments using the asymptotic series and check that it converges.
Then implement 1F1 and 0F1 for small "x" directly and in terms
of 2F0 for large "x". For 0F1 this should work. For 1F1 I might hit
some cancellation problems, so I'll have to see --- so probably implementing
hypercomb() will be needed.
I can see, that hypsum is calling for example the MPF_hypsum in Sage.
This function works at a set precision, correct? And returns the "magn",
which you use later to determine if you need to rerun it with higher precision.
I am still having problems understanding how you detect, that too much
cancellation has occurred in ctx_mp.py:
zv, have_complex, magnitude = summator(coeffs, v, prec, wp, \
epsshift, mag_dict, **kwargs)
cancel = -magnitude
jumps_resolved = True
if extraprec < max_total_jump:
for n in mag_dict.values():
if (n is None) or (n < prec):
jumps_resolved = False
break
accurate = (cancel < extraprec-25-5 or not accurate_small)
if jumps_resolved:
if accurate:
break
the magnitude is returned from Sage (for example) by the following code:
MPF_set_fixed(a, SRE, wp, prec, ROUND_N)
if mpz_sgn(SRE):
magn = mpz_get_si(a.exp) + <long>mpz_bitcount(a.man)
else:
magn = -wp
what exactly is it? The SRE seems to be the final sum, which is
assigned to "a" (the return value)
and magn is somehow the number of bits of the number, but I don't
understand how this can
detect any cancellation. How can I detect cancellation
using just double precision floating point numbers?
I noticed that cancellation typically occurs when the individual terms
become (temporarily) big,
which reduces accuracy. So maybe I can just check the max absolute
size of the term,
relative to the final answer. If the final answer is let's say 0.1,
but it contains terms of order 1e6
that cancel out then I am in trouble. If on the other hand the final
answer is 1e10, then I should be fine.
Ondrej