Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
Function: sumpos Section: sums C-Name: sumpos0 Prototype: V=GED0,L,p Help: sumpos(X=a,expr,{flag=0}): sum of positive (or negative) series expr, the formal variable X starting at a. flag is optional, and can be 0: default, or 1: uses a slightly different method using Zagier's polynomials. Wrapper: (,G) Description: (gen,gen,?0):gen:prec sumpos(${2 cookie}, ${2 wrapper}, $1, $prec) (gen,gen,1):gen:prec sumpos2(${2 cookie}, ${2 wrapper}, $1, $prec) Doc: numerical summation of the series \var{expr}, which must be a series of terms having the same sign, the formal variable $X$ starting at $a$. The algorithm uses Van Wijngaarden's trick for converting such a series into an alternating one, then \tet{sumalt}. For regular functions, the function \kbd{sumnum} is in general much faster once the initializations have been made using \kbd{sumnuminit}. Contrary to \kbd{sumnum}, \kbd{sumpos} allows functions defined only at integers: \bprog ? sumnum(n = 0, 1/n!) *** at top-level: sumnum(n=1,1/n!) *** ^--- *** incorrect type in gtos [integer expected] (t_FRAC). ? sumpos(n = 0, 1/n!) - exp(1) %2 = -1.0862155548773347717 E-33 @eprog\noindent On the other hand, when the function accepts general real numbers, it is usually advantageous to replace $n$ by \kbd{$n$ * 1.0} in the sumpos call in particular when rational functions are involved: \bprog ? \p500 ? sumpos(n = 0, n^7 / (n^9+n+1)); time = 6,108 ms. ? sumpos(n = 0, n *= 1.; n^7 / (n^9+n+1)); time = 2,788 ms. ? sumnumrat(n^7 / (n^9+n+1), 0); time = 4 ms. @eprog\noindent In the last example, \kbd{sumnumrat} is of course much faster but it only applies to rational functions. The routine is heuristic and assumes that \var{expr} is more or less a decreasing function of $X$. In particular, the result will be completely wrong if \var{expr} is 0 too often. We do not check either that all terms have the same sign: as \tet{sumalt}, this function should be used to try and guess the value of an infinite sum. If $\fl=1$, use \kbd{sumalt}$(,1)$ instead of \kbd{sumalt}$(,0)$, see \secref{se:sumalt}. Requiring more stringent analytic properties for rigorous use, but allowing to compute fewer series terms. To reach accuracy $10^{-p}$, both algorithms require $O(p^2)$ space; furthermore, assuming the terms decrease polynomially (in $O(n^{-C})$), both need to compute $O(p^2)$ terms. The \kbd{sumpos}$(,1)$ variant has a smaller implied constant (roughly 1.5 times smaller). Since the \kbd{sumalt}$(,1)$ overhead is now small compared to the time needed to compute series terms, this last variant should be about 1.5 faster. On the other hand, the achieved accuracy may be much worse: as for \tet{sumalt}, since conditions for rigorous use are hard to check, the routine is best used heuristically. \synt{sumpos}{void *E, GEN (*eval)(void*,GEN),GEN a,long prec}. Also available is \tet{sumpos2} with the same arguments ($\fl = 1$).