Pari/GP Reference Documentation | Contents - Global index - GP keyboard shortcuts |
Catalan Euler I Pi abs acos acosh agm airy arg asin asinh atan atanh besselh1 besselh2 besseli besselj besseljh besseljzero besselk besseln bessely besselyzero cos cosh cotan cotanh dilog eint1 ellE ellK erfc eta exp expm1 gamma gammah gammamellininv gammamellininvasymp gammamellininvinit hypergeom hyperu incgam incgamc lambertw lerchphi lerchzeta lngamma log log1p polylog polylogmult psi rootsof1 sin sinc sinh sqr sqrt sqrtn tan tanh teichmuller theta thetanullk weber zeta zetahurwitz zetamult zetamultall zetamultconvert zetamultdual | |
Since the values of transcendental functions cannot be exactly represented, these functions will always return an inexact object: a real number, a complex number, a p-adic number or a power series. All these objects have a certain finite precision. As a general rule, which of course in some cases may have exceptions, transcendental functions operate in the following way:
* If the argument is either a real number or an inexact complex number
(like
? \p 15 realprecision = 19 significant digits (15 digits displayed) ? x = Pi/4 %1 = 0.785398163397448 ? \p 50 realprecision = 57 significant digits (50 digits displayed) ? sin(x) %2 = 0.7071067811865475244 Note that even if the argument is real, the result may be complex (e.g. acos(2.0) or acosh(0.0)). See each individual function help for the definition of the branch cuts and choice of principal value.
* If the argument is either an integer, a rational, an exact complex
number or a quadratic number, it is first converted to a real
or complex number using the current precision, which can be
view and manipulated using the defaults
* in decimal digits: use
* in bits: use After this conversion, the computation proceeds as above for real or complex arguments.
In library mode, the Some accuracies attainable on 32-bit machines cannot be attained on 64-bit machines for parity reasons. For example, an accuracy of 28 decimal digits on 32-bit machines corresponds to prec having the value 5, for a mantissa of 3 x 32 = 96 bits. But this cannot be attained on 64-bit machines: we can attain either 64 or 128 bits, but values in between.
* If the argument is a polmod (representing an algebraic number),
then the function is evaluated for every possible complex embedding of that
algebraic number. A column vector of results is returned, with one component
for each complex embedding. Therefore, the number of components equals
the degree of the
* If the argument is an intmod or a p-adic, at present only a
few functions like
Note that in the case of a 2-adic number,
Remark. If we wanted to be strictly consistent with
the PARI philosophy, we should have x*y = (4 mod 8) and
* If the argument is a polynomial, a power series or a rational function,
it is, if necessary, first converted to a power series using the current
series precision, held in the default
Under
x = gtoser(x, gvar(x), seriesprec)
where the number of significant terms * If the argument is a vector or a matrix, the result is the componentwise evaluation of the function. In particular, transcendental functions on square matrices, are not built-in. For this you can use the following technique, which is neither very efficient nor numerical stable, but is often good enough provided we restrict to diagonalizable matrices:
mateval(f, M) = { my([L, H] = mateigen(M, 1)); H * matdiagonal(f(L)) * H^(-1); } ? A = [13,2;10,14]; ? a = mateval(sqrt, A) /* approximates sqrt{A} */ %2 = [3.5522847498307933... 0.27614237491539669...] [1.3807118745769834... 3.69035593728849174...] ? exponent(a^2 - A) %3 = -123 \\ OK ? b = mateval(exp, A); ? exponent(mateval(log, b) - A) %5 = -115 \\ tolerable
The absolute error depends on the condition number of the base
change matrix H and on the largest |f(λ)|, where λ runs
through the eigenvalues. If M is real symmetric, you may use
Of course when the input is not diagonalizable, this function produces junk:
? mateval(sqrt, [0,1;0,0]) %6 = \\ oops ... [0.E-57 0] [ 0 0]
| |
Catalan | |
Catalan's constant G = ∑n >= 0((-1)n)/((2n+1)2)
= 0.91596....
Note that
The library syntax is
| |
Euler | |
Euler's constant γ = 0.57721.... Note that
The library syntax is
| |
I | |
The complex number sqrt{-1}.
The library syntax is
| |
Pi | |
The constant π (3.14159...). Note that
The library syntax is
| |
abs(x) | |
Absolute value of x (modulus if x is complex).
Rational functions are not allowed. Contrary to most transcendental
functions, an exact argument is not converted to a real number before
applying
? abs(-1) %1 = 1 ? abs(3/7 + 4/7*I) %2 = 5/7 ? abs(1 + I) %3 = 1.414213562373095048801688724 If x is a polynomial, returns -x if the leading coefficient is real and negative else returns x. For a power series, the constant coefficient is considered instead.
The library syntax is
| |
acos(x) | |
Principal branch of cos-1(x) = -i log (x + isqrt{1-x2}). In particular, Re(acos(x)) ∈ [0,π] and if x ∈ ℝ and |x| > 1, then acos(x) is complex. The branch cut is in two pieces: ]- oo ,-1] , continuous with quadrant II, and [1,+ oo [, continuous with quadrant IV. We have acos(x) = π/2 - asin(x) for all x.
The library syntax is
| |
acosh(x) | |
Principal branch of cosh-1(x) = 2 log(sqrt{(x+1)/2} + sqrt{(x-1)/2}). In particular, Re(acosh(x)) ≥ 0 and Im(acosh(x)) ∈ ]-π,π]; if x ∈ ℝ and x < 1, then acosh(x) is complex.
The library syntax is
| |
agm(x, y) | |
Arithmetic-geometric mean of x and y. In the case of complex or negative numbers, the optimal AGM is returned (the largest in absolute value over all choices of the signs of the square roots). p-adic or power series arguments are also allowed. Note that a p-adic agm exists only if x/y is congruent to 1 modulo p (modulo 16 for p = 2). x and y cannot both be vectors or matrices.
The library syntax is
| |
airy(z) | |
Airy [Ai,Bi] functions of argument z.
? [A,B] = airy(1); ? A %2 = 0.13529241631288141552414742351546630617 ? B %3 = 1.2074235949528712594363788170282869954
The library syntax is
| |
arg(x) | |
Argument of the complex number x, such that -π < arg(x) ≤ π.
The library syntax is
| |
asin(x) | |
Principal branch of sin-1(x) = -i log(ix + sqrt{1 - x2}). In particular, Re(asin(x)) ∈ [-π/2,π/2] and if x ∈ ℝ and |x| > 1 then asin(x) is complex. The branch cut is in two pieces: ]- oo ,-1], continuous with quadrant II, and [1,+ oo [ continuous with quadrant IV. The function satisfies i asin(x) = asinh(ix).
The library syntax is
| |
asinh(x) | |
Principal branch of sinh-1(x) = log(x + sqrt{1+x2}). In particular Im(asinh(x)) ∈ [-π/2,π/2]. The branch cut is in two pieces: ]-i oo ,-i], continuous with quadrant III and [+i,+i oo [, continuous with quadrant I.
The library syntax is
| |
atan(x) | |
Principal branch of tan-1(x) = log ((1+ix)/(1-ix)) / 2i. In particular the real part of atan(x) belongs to ]-π/2,π/2[. The branch cut is in two pieces: ]-i oo ,-i[, continuous with quadrant IV, and ]i,+i oo [ continuous with quadrant II. The function satisfies atan(x) = -iatanh(ix) for all x ! = ± i.
The library syntax is
| |
atanh(x) | |
Principal branch of tanh-1(x) = log ((1+x)/(1-x)) / 2. In particular the imaginary part of atanh(x) belongs to [-π/2,π/2]; if x ∈ ℝ and |x| > 1 then atanh(x) is complex.
The library syntax is
| |
besselh1(nu, x) | |
H1-Bessel function of index nu and argument x.
The library syntax is
| |
besselh2(nu, x) | |
H2-Bessel function of index nu and argument x.
The library syntax is
| |
besseli(nu, x) | |
I-Bessel function of index nu and argument x. If x converts to a power series, the initial factor (x/2)ν/Γ(ν+1) is omitted (since it cannot be represented in PARI when ν is not integral).
The library syntax is
| |
besselj(nu, x) | |
J-Bessel function of index nu and argument x. If x converts to a power series, the initial factor (x/2)ν/Γ(ν+1) is omitted (since it cannot be represented in PARI when ν is not integral).
The library syntax is
| |
besseljh(n, x) | |
J-Bessel function of half integral index.
More precisely,
The library syntax is
| |
besseljzero(nu, {k = 1}) | |
k-th zero of the J-Bessel function of index nu, close to π(ν/2 + k - 1/4), usually noted jν,k.
? besseljzero(0) \\ {first zero of J0} %1 = 2.4048255576957727686216318793264546431 ? besselj(0, %) %2 = 7.1951595399463653939930598011247182898 E-41 ? besseljzero(0, 2) \\ {second zero} %3 = 5.5200781102863106495966041128130274252 ? besseljzero(I) \\ {also works for complex orders, here Ji} %4 = 2.5377... + 1.4753...*I The function uses a Newton iteration due to Temme. If ν is real and nonnegative, the result is guaranteed and the function really returns the k-th positive zero of Jν. For general ν, the result is not well defined, given by the Newton iteration with π(ν/2 + k - 1/4) as a starting value. (N.B. Using this method for large real ν would give completely different results than the jν,k unless k is large enough.)
The library syntax is
| |
besselk(nu, x) | |
K-Bessel function of index nu and argument x.
The library syntax is
| |
besseln(nu, x) | |
Deprecated alias for
The library syntax is
| |
bessely(nu, x) | |
Y-Bessel function of index nu and argument x.
The library syntax is
| |
besselyzero(nu, {k = 1}) | |
k-th zero of the Y-Bessel function of index nu, close to π(ν/2 + k - 3/4), usually noted yν,k.
? besselyzero(0) \\ {first zero of Y0} %1 = 0.89357696627916752158488710205833824123 ? bessely(0, %) %2 = 1.8708573650996561952 E-39 ? besselyzero(0, 2) \\ {second zero} %3 = 3.9576784193148578683756771869174012814 ? besselyzero(I) \\ {also works for complex orders, here Yi} %4 = 1.03930... + 1.3266...*I The function uses a Newton iteration due to Temme. If ν is real and nonnegative, the result is guaranteed and the function really returns the k-th positive zero of Yν. For general ν, the result is not well defined, given by Newton iteration with π(ν/2 + k - 3/4) as a starting value. (N.B. Using this method for large real ν would give completely different results than the yν,k unless k is large enough.)
The library syntax is
| |
cos(x) | |
Cosine of x. Note that, for real x, cosine and sine can be obtained simultaneously as
cs(x) = my(z = exp(I*x)); [real(z), imag(z)]; and for general complex x as
cs2(x) = my(z = exp(I*x), u = 1/z); [(z+u)/2, (z-u)/2]; Note that the latter function suffers from catastrophic cancellation when z2 ~ ±1.
The library syntax is
| |
cosh(x) | |
Hyperbolic cosine of x.
The library syntax is
| |
cotan(x) | |
Cotangent of x.
The library syntax is
| |
cotanh(x) | |
Hyperbolic cotangent of x.
The library syntax is
| |
dilog(x) | |
Principal branch of the dilogarithm of x, i.e. analytic continuation of the power series Li2(x) = ∑n ≥ 1xn/n2.
The library syntax is
| |
eint1(x, {n}) | |
Exponential integral ∫x oo (e-t)/(t)dt =
If n is present, we must have x > 0; the function returns the
n-dimensional vector [
The library syntax is
| |
ellE(k) | |
Complete elliptic integral of the second kind E(k) = ∫0π/2(1-k2sin(t)2)1/2dt for the complex parameter k using the agm. In particular, the perimeter of an ellipse of semi-major and semi-minor axes a and b is given by
e = sqrt(1 - (b/a)^2); \\ eccentricity 4 * a * ellE(e) \\ perimeter
The library syntax is
| |
ellK(k) | |
Complete elliptic integral of the first kind K(k) = ∫0π/2(1-k2sin(t)2)-1/2dt for the complex parameter k using the agm.
The library syntax is
| |
erfc(x) | |
Complementary error function, analytic continuation of
(2/sqrtπ)∫x oo e-t^{2}dt
= {sign(x)}
? erfc(0) %1 = 1.0000000000000000000000000000000000000 ? erfc(1) %2 = 0.15729920705028513065877936491739074071 ? erfc(1+I) %3 = -0.31615128169794764488027108024367036903 - 0.19045346923783468628410886196916244244*I
The library syntax is
| |
eta(z, {flag = 0}) | |
Variants of Dedekind's η function. If flag = 0, return ∏n = 1 oo (1-qn), where q depends on x in the following way: * q = e2iπ x if x is a complex number (which must then have positive imaginary part); notice that the factor q1/24 is missing!
* q = x if x is a If flag is nonzero, x is converted to a complex number and we return the true η function, q1/24∏n = 1 oo (1-qn), where q = e2iπ x.
The library syntax is
Also available is
| |
exp(x) | |
Exponential of x. p-adic arguments with positive valuation are accepted.
The library syntax is
| |
expm1(x) | |
Return exp(x)-1, computed in a way that is also accurate
when the real part of x is near 0.
A naive direct computation would suffer from catastrophic cancellation;
PARI's direct computation of exp(x) alleviates this well known problem at
the expense of computing exp(x) to a higher accuracy when x is small.
Using
? default(realprecision, 10000); x = 1e-100; ? a = expm1(x); time = 4 ms. ? b = exp(x)-1; time = 4 ms. ? default(realprecision, 10040); x = 1e-100; ? c = expm1(x); \\ reference point ? abs(a-c)/c \\ relative error in expm1(x) %7 = 1.4027986153764843997 E-10019 ? abs(b-c)/c \\ relative error in exp(x)-1 %8 = 1.7907031188259675794 E-9919
As the example above shows, when x is near 0,
The library syntax is
| |
gamma(s) | |
For s a complex number, evaluates Euler's gamma function, which is the analytic continuation of Γ(s) = ∫0 oo ts-1exp(-t)dt, Re(s) > 0. Error if s is a nonpositive integer, where Γ has a (simple) pole.
? gamma(5) \\ Γ(n) = (n-1)! for a positive integer n %1 = 24.000000000000000000000000000000000000 ? gamma(0) *** at top-level: gamma(0) *** ^ — — -- *** gamma: domain error in gamma: argument = nonpositive integer ? gamma(x + O(x^3)) %2 = x^-1 - 0.57721566490153286060651209008240243104 + O(x)
For s a
? gamma(1/4 + O(5^10)) %1= 1 + 4*5 + 3*5^4 + 5^6 + 5^7 + 4*5^9 + O(5^10) ? algdep(%,4) %2 = x^4 + 4*x^2 + 5
The library syntax is
| |
gammah(x) | |
Gamma function evaluated at the argument x+1/2.
The library syntax is
| |
gammamellininv(G, t, {m = 0}) | |
Returns the value at t of the inverse Mellin transform
G initialized by
? G = gammamellininvinit([0]); ? gammamellininv(G, 2) - 2*exp(-Pi*2^2) %2 = -4.484155085839414627 E-44 The shortcut
gammamellininv(A,t,m) for
gammamellininv(gammamellininvinit(A,m), t) is available.
The library syntax is
| |
gammamellininvasymp(A, n, {m = 0}) | |
Return the first n terms of the asymptotic expansion at infinity
of the m-th derivative K(m)(t) of the inverse Mellin transform of the
function
f(s) = Γℝ(s+a1)...Γℝ(s+ad) ,
where
The library syntax is
| |
gammamellininvinit(A, {m = 0}) | |
Initialize data for the computation by Caveat. Contrary to the PARI convention, this function guarantees an absolute (rather than relative) error bound. For instance, the inverse Mellin transform of Γℝ(s) is 2exp(-π z2):
? G = gammamellininvinit([0]); ? gammamellininv(G, 2) - 2*exp(-Pi*2^2) %2 = -4.484155085839414627 E-44 The inverse Mellin transform of Γℝ(s+1) is 2 zexp(-π z2), and its second derivative is 4π z exp(-π z2)(2π z2 - 3):
? G = gammamellininvinit([1], 2); ? a(z) = 4*Pi*z*exp(-Pi*z^2)*(2*Pi*z^2-3); ? b(z) = gammamellininv(G,z); ? t(z) = b(z) - a(z); ? t(3/2) %3 = -1.4693679385278593850 E-39
The library syntax is
| |
hypergeom({N}, {D}, z) | |
General hypergeometric function, where This function implements hypergeometric functions pFq((ai)1 ≤ i ≤ p,(bj)1 ≤ j ≤ q;z) = ∑n ≥ 0(∏1 ≤ i ≤ p(ai)n)/(∏1 ≤ j ≤ q(bj)n) (zn)/(n!) , where (a)n = a(a+1)...(a+n-1) is the rising Pochhammer symbol. For this to make sense, none of the bj must be a negative or zero integer. The corresponding general GP command is
hypergeom([a1,a2,...,ap], [b1,b2,...,bq], z) Whenever p = 1 or q = 1, a one-element vector can be replaced by the element it contains. Whenever p = 0 or q = 0, an empty vector can be omitted. For instance hypergeom(,b,z) computes 0F1(;b;z). The non-archimedean cases (z a p-adic or power series) are handled trivially. We now discuss the case of a complex z; we distinguish three kinds of such functions according to their radius of convergence R: * q ≥ p: R = oo . * q = p-1: R = 1. Nonetheless, by integral representations, pFq can be analytically continued outside the disc of convergence. * q ≤ p-2: R = 0. By integral representations, one can make sense of the function in a suitable domain, by analytic continuation. The list of implemented functions and their domain of validity in our implementation is as follows:
For other inputs: if R = oo or R = 1 and |z| < 1- ϵ is not too close to the circle of convergence, we simply sum the series.
? hypergeom([3,2], 3.4, 0.7) \\ 2F1(3,2; 3.4; 0.7) %1 = 7.9999999999999999999999999999999999999 ? a=5/3; T1=hypergeom([1,1,1],[a,a],1) \\ 3F2(1,1,1; a,a; 1) %2 = 3.1958592952314032651578713968927593818 ? T2=hypergeom([2,1,1],[a+1,a+1],1) %3 = 1.6752931349345765309211012564734179541 ? T3=hypergeom([2*a-1,1,1],[a+1,a+1],1) %4 = 1.9721037126267142061807688820853354440 ? T1 + (a-1)^2/(a^2*(2*a-3)) * (T2-2*(a-1)*T3) \\ - gamma(a)^2/((2*a-3)*gamma(2*a-2)) %5 = -1.880790961315660013 E-37 \\ ~ 0 This identity is due to Bercu.
The library syntax is
| |
hyperu(a, b, z) | |
U-confluent hypergeometric function with complex parameters a, b, z. Note that 2F0(a,b,z) = (-z)-aU(a, a+1-b, -1/z),
? hyperu(1, 3/2, I) %1 = 0.23219... - 0.80952...*I ? -I * hypergeom([1, 1+1-3/2], [], -1/I) %2 = 0.23219... - 0.80952...*I
The library syntax is
| |
incgam(s, x, {g}) | |
Incomplete gamma function ∫x oo e-tts-1dt, extended by analytic continuation to all complex x, s not both 0. The relative error is bounded in terms of the precision of s (the accuracy of x is ignored when determining the output precision). When g is given, assume that g = Γ(s). For small |x|, this will speed up the computation.
The library syntax is
| |
incgamc(s, x) | |
Complementary incomplete gamma function. The arguments x and s are complex numbers such that s is not a pole of Γ and |x|/(|s|+1) is not much larger than 1 (otherwise the convergence is very slow). The result returned is ∫0× e-tts-1dt.
The library syntax is
| |
lambertw(y, {branch = 0}) | |
Lambert W function, solution of the implicit equation xe× = y.
* For real inputs y:
If * For p-adic inputs, p odd: give a solution of xexp(x) = y if y has positive valuation, of log(x)+x = log(y) otherwise. * For 2-adic inputs: give a solution of xexp(x) = y if y has valuation > 1, of log(x)+x = log(y) otherwise.
Caveat.
Complex values of y are also supported but experimental. The other
branches Wk for k not equal to 0 or -1 (set For k ≥ 1, W-1-k(x) = Wk(x), and Im(Wk(x)) is close to (π/2)(4k-sign(x)).
The library syntax is
| |
lerchphi(z, s, a) | |
Lerch transcendent Φ(z,s,a) = ∑n ≥ 0zn(n+a)-s and analytically continued, for reasonable values of the arguments.
The library syntax is
| |
lerchzeta(s, a, lam) | |
Lerch zeta function L(s,a,λ) = ∑n ≥ 0e2π iλ n(n+a)-s and analytically continued, for reasonable values of the arguments.
The library syntax is
| |
lngamma(x) | |
Principal branch of the logarithm of the gamma function of x. This
function is analytic on the complex plane with nonpositive integers
removed, and can have much larger arguments than
For x a power series such that x(0) is not a pole of
? lngamma(1+x+O(x^2)) %1 = -0.57721566490153286060651209008240243104*x + O(x^2) ? lngamma(x+O(x^2)) *** at top-level: lngamma(x+O(x^2)) *** ^ — — — — — -- *** lngamma: domain error in lngamma: valuation != 0 ? lngamma(-1+x+O(x^2)) *** lngamma: Warning: normalizing a series with 0 leading term. *** at top-level: lngamma(-1+x+O(x^2)) *** ^ — — — — — — -- *** lngamma: domain error in intformal: residue(series, pole) != 0
For x a
? lngamma(5+O(5^7)) %2 = 4*5^2 + 4*5^3 + 5^4 + 2*5^5 + O(5^6) ? log(gamma(5+O(5^7))) %3 = 4*5^2 + 4*5^3 + 5^4 + 2*5^5 + O(5^6) ? lngamma(1/5+O(5^4)) %4 = 4*5^-1 + 4 + 2*5 + 5^2 + 5^3 + O(5^4) ? gamma(1/5+O(5^4)) *** at top-level: gamma(1/5+O(5^4)) *** ^ — — — — — -- *** gamma: domain error in gamma: vp(x) < 0
The library syntax is
| |
log(x) | |
Principal branch of the natural logarithm of x ∈ ℂ*, i.e. such that Im(log(x)) ∈ ]-π,π]. The branch cut lies along the negative real axis, continuous with quadrant 2, i.e. such that limb → 0+ log (a+bi) = log a for a ∈ ℝ*. The result is complex (with imaginary part equal to π) if x ∈ ℝ and x < 0. In general, the algorithm uses the formula log(x) ~ (π)/(2agm(1, 4/s)) - m log 2, if s = x 2m is large enough. (The result is exact to B bits provided s > 2B/2.) At low accuracies, the series expansion near 1 is used. p-adic arguments are also accepted for x, with the convention that log(p) = 0. Hence in particular exp(log(x))/x is not in general equal to 1 but to a (p-1)-th root of unity (or ±1 if p = 2) times a power of p.
The library syntax is
| |
log1p(x) | |
Return log(1+x), computed in a way that is also accurate
when the real part of x is near 0. This is the reciprocal function
of
? default(realprecision, 10000); x = Pi*1e-100; ? (expm1(log1p(x)) - x) / x %2 = -7.668242895059371866 E-10019 ? (log1p(expm1(x)) - x) / x %3 = -7.668242895059371866 E-10019 When x is small, this function is both faster and more accurate than log(1+x):
? \p38 ? x = 1e-20; ? localprec(100); c = log1p(x); \\ reference point ? a = log1p(x); abs((a - c)/c) %6 = 0.E-38 ? b = log(1+x); abs((b - c)/c) \\ slightly less accurate %7 = 1.5930919111324522770 E-38 ? for (i=1,10^5,log1p(x)) time = 81 ms. ? for (i=1,10^5,log(1+x)) time = 100 ms. \\ slower, too
The library syntax is
| |
polylog(m, x, {flag = 0}) | |
One of the different polylogarithms, depending on flag: If flag = 0 or is omitted: m-th polylogarithm of x, i.e. analytic continuation of the power series Lim(x) = ∑n ≥ 1xn/nm (x < 1). Uses the functional equation linking the values at x and 1/x to restrict to the case |x| ≤ 1, then the power series when |x|2 ≤ 1/2, and the power series expansion in log(x) otherwise. Using flag, computes a modified m-th polylogarithm of x. We use Zagier's notations; let Rem denote Re or Im depending on whether m is odd or even: If flag = 1: compute ~ Dm(x), defined for |x| ≤ 1 by Rem(∑k = 0m-1 ((-log|x|)k)/(k!)Lim-k(x) +((-log|x|)m-1)/(m!)log|1-x|). If flag = 2: compute Dm(x), defined for |x| ≤ 1 by Rem(∑k = 0m-1((-log|x|)k)/(k!)Lim-k(x) -(1)/(2)((-log|x|)m)/(m!)). If flag = 3: compute Pm(x), defined for |x| ≤ 1 by Rem(∑k = 0m-1(2kBk)/(k!) (log|x|)kLim-k(x) -(2m-1Bm)/(m!)(log|x|)m). These three functions satisfy the functional equation fm(1/x) = (-1)m-1fm(x).
The library syntax is
| |
polylogmult(s, {z}, {t = 0}) | |
For s a vector of positive integers and z a vector of complex numbers of the same length, returns the multiple polylogarithm value (MPV) ζ(s1,..., sr; z1,...,zr) = ∑n_{1 > ... > nr > 0} ∏1 ≤ i ≤ rzini/nisi. If z is omitted, assume z = [1,...,1], i.e., Multiple Zeta Value. More generally, return Yamamoto's interpolation between ordinary multiple polylogarithms (t = 0) and star polylogarithms (t = 1, using the condition n1 ≥ ... ≥ nr > 0), evaluated at t. We must have |z1...zi| ≤ 1 for all i, and if s1 = 1 we must have z1 ! = 1.
? 8*polylogmult([2,1],[-1,1]) - zeta(3) %1 = 0.E-38 Warning. The algorithm used converges when the zi are ± 1. It may not converge as some zi ! = 1 becomes too close to 1, even at roots of 1 of moderate order:
? polylogmult([2,1], (99+20*I)/101 * [1,1]) *** polylogmult: sorry, polylogmult in this range is not yet implemented. ? polylogmult([2,1], exp(I*Pi/20)* [1,1]) *** polylogmult: sorry, polylogmult in this range is not yet implemented. More precisely, if yi := 1 / (z1...zi) and v := mini < j; y_{i ! = 1} |(1 - yi) yj| > 1/4 then the algorithm computes the value up to a 2-b absolute error in O(k2N) operations on floating point numbers of O(N) bits, where k = ∑i si is the weight and N = b / log2 (4v).
The library syntax is
| |
psi(x, {der}) | |
The ψ-function of x, i.e. the logarithmic derivative
Γ'(x)/Γ(x). If der is set, return the der-th derivative.
For s a
The library syntax is
| |
rootsof1(N) | |
Return the column vector v of all complex N-th roots of 1, where N is a positive integer. In other words, v[k] = exp(2I(k-1)π/N) for k = 1,..., N. Rational components (e.g., the roots ±1 and ± I) are given exactly, not as floating point numbers:
? rootsof1(4) %1 = [1, I, -1, -I]~ ? rootsof1(3) %2 = [1, -1/2 + 0.866025...*I, -1/2 - 0.866025...*I]~
The library syntax is
| |
sin(x) | |
Sine of x. Note that, for real x, cosine and sine can be obtained simultaneously as
cs(x) = my(z = exp(I*x)); [real(z), imag(z)]; and for general complex x as
cs2(x) = my(z = exp(I*x), u = 1/z); [(z+u)/2, (z-u)/2]; Note that the latter function suffers from catastrophic cancellation when z2 ~ ±1.
The library syntax is
| |
sinc(x) | |
Cardinal sine of x, i.e. sin(x)/x if x ! = 0, 1 otherwise.
Note that this function also allows to compute
(1-cos(x)) / x2 =
The library syntax is
| |
sinh(x) | |
Hyperbolic sine of x.
The library syntax is
| |
sqr(x) | |
Square of x. This operation is not completely straightforward, i.e. identical to x * x, since it can usually be computed more efficiently (roughly one-half of the elementary multiplications can be saved). Also, squaring a 2-adic number increases its precision. For example,
? (1 + O(2^4))^2 %1 = 1 + O(2^5) ? (1 + O(2^4)) * (1 + O(2^4)) %2 = 1 + O(2^4) Note that this function is also called whenever one multiplies two objects which are known to be identical, e.g. they are the value of the same variable, or we are computing a power.
? x = (1 + O(2^4)); x * x %3 = 1 + O(2^5) ? (1 + O(2^4))^4 %4 = 1 + O(2^6)
(note the difference between
The library syntax is
| |
sqrt(x) | |
Principal branch of the square root of x, defined as sqrt{x} = exp(log x / 2). In particular, we have Arg(sqrt(x)) ∈ ]-π/2, π/2], and if x ∈ ℝ and x < 0, then the result is complex with positive imaginary part.
Intmod a prime p,
The library syntax is
| |
sqrtn(x, n, {&z}) | |
Principal branch of the nth root of x, i.e. such that Arg(sqrtn(x)) ∈ ]-π/n, π/n]. Intmod a prime and p-adics are allowed as arguments. If z is present, it is set to a suitable root of unity allowing to recover all the other roots. If it was not possible, z is set to zero. In the case this argument is present and no nth root exist, 0 is returned instead of raising an error.
? sqrtn(Mod(2,7), 2) %1 = Mod(3, 7) ? sqrtn(Mod(2,7), 2, &z); z %2 = Mod(6, 7) ? sqrtn(Mod(2,7), 3) *** at top-level: sqrtn(Mod(2,7),3) *** ^ — — — — — -- *** sqrtn: nth-root does not exist in gsqrtn. ? sqrtn(Mod(2,7), 3, &z) %2 = 0 ? z %3 = 0 The following script computes all roots in all possible cases:
sqrtnall(x,n)= { my(V,r,z,r2); r = sqrtn(x,n, &z); if (!z, error("Impossible case in sqrtn")); if (type(x) == "t_INTMOD" || type(x)=="t_PADIC", r2 = r*z; n = 1; while (r2!=r, r2*=z;n++)); V = vector(n); V[1] = r; for(i=2, n, V[i] = V[i-1]*z); V } addhelp(sqrtnall,"sqrtnall(x,n):compute the vector of nth-roots of x");
The library syntax is
| |
tan(x) | |
Tangent of x.
The library syntax is
| |
tanh(x) | |
Hyperbolic tangent of x.
The library syntax is
| |
teichmuller(x, {tab}) | |
Teichmüller character of the p-adic number x, i.e. the unique
(p-1)-th root of unity congruent to x / pvp(x) modulo p.
If x is of the form [p,n], for a prime p and integer n,
return the lifts to ℤ of the images of i + O(pn) for
i = 1,..., p-1, i.e. all roots of 1 ordered by residue class modulo
p. Such a vector can be fed back to
? z = teichmuller(2 + O(101^5)) %1 = 2 + 83*101 + 18*101^2 + 69*101^3 + 62*101^4 + O(101^5) ? z^100 %2 = 1 + O(101^5) ? T = teichmuller([101, 5]); ? teichmuller(2 + O(101^5), T) %4 = 2 + 83*101 + 18*101^2 + 69*101^3 + 62*101^4 + O(101^5)
As a rule of thumb, if more than
p / 2(log2(p) +
? p = 101; n = 100; T = teichmuller([p,n]); \\ instantaneous ? for(i=1,10^3, vector(p-1, i, teichmuller(i+O(p^n), T))) time = 60 ms. ? for(i=1,10^3, vector(p-1, i, teichmuller(i+O(p^n)))) time = 1,293 ms. ? 1 + 2*(log(p)/log(2) + hammingweight(p)) %8 = 22.316[...] Here the precomputation induces a speedup by a factor 1293/ 60 ~ 21.5.
Caveat.
If the accuracy of
? Tlow = teichmuller([101, 2]); \\ lower accuracy ! ? teichmuller(2 + O(101^5), Tlow) %10 = 2 + 83*101 + O(101^5) \\ no longer a root of 1 ? Thigh = teichmuller([101, 10]); \\ higher accuracy ? teichmuller(2 + O(101^5), Thigh) %12 = 2 + 83*101 + 18*101^2 + 69*101^3 + 62*101^4 + O(101^5)
The library syntax is
Also available are the functions
| |
theta(q, z) | |
Jacobi sine theta-function θ1(z, q) = 2q1/4 ∑n ≥ 0 (-1)n qn(n+1) sin((2n+1)z).
The library syntax is
| |
thetanullk(q, k) | |
k-th derivative at z = 0 of
The library syntax is
| |
weber(x, {flag = 0}) | |
One of Weber's three f functions.
If flag = 0, returns
f(x) = exp(-iπ/24).η((x+1)/2)/η(x) {such that}
j = (f24-16)3/f24,
where j is the elliptic j-invariant (see the function
The library syntax is
| |
zeta(s) | |
For s ! = 1 a complex number, Riemann's zeta function ζ(s) = ∑n ≥ 1n-s, computed using the Euler-Maclaurin summation formula, except when s is of type integer, in which case it is computed using Bernoulli numbers for s ≤ 0 or s > 0 and even, and using modular forms for s > 0 and odd. Power series are also allowed:
? zeta(2) - Pi^2/6 %1 = 0.E-38 ? zeta(1+x+O(x^3)) %2 = 1.0000000000000000000000000000000000000*x^-1 + \ 0.57721566490153286060651209008240243104 + O(x) For s ! = 1 a p-adic number, Kubota-Leopoldt zeta function at s, that is the unique continuous p-adic function on the p-adic integers that interpolates the values of (1 - p-k) ζ(k) at negative integers k such that k = 1 (mod p-1) (resp. k is odd) if p is odd (resp. p = 2). Power series are not allowed in this case.
? zeta(-3+O(5^10)) %1 = 4*5^-1 + 4 + 3*5 + 4*5^3 + 4*5^5 + 4*5^7 + O(5^9))))) ? (1-5^3) * zeta(-3) %2 = -1.0333333333333333333333333333333333333 ? bestappr(%) %3 = -31/30 ? zeta(-3+O(5^10)) - (-31/30) %4 = O(5^9)
The library syntax is
| |
zetahurwitz(s, x, {der = 0}) | |
Hurwitz zeta function ζ(s,x) = ∑n ≥ 0(n+x)-s and
analytically continued, with s ! = 1 and x not a negative or zero
integer. Note that ζ(s,1) = ζ(s). s can also be a polynomial,
rational function, or power series. If
? zetahurwitz(Pi,Pi) %1 = 0.056155444497585099925180502385781494484 ? zetahurwitz(2,1) - zeta(2) %2 = -2.350988701644575016 E-38 ? zetahurwitz(Pi,3) - (zeta(Pi)-1-1/2^Pi) %3 = -2.2040519077917890774 E-39 ? zetahurwitz(-7/2,1) - zeta(-7/2) %4 = -2.295887403949780289 E-41 ? zetahurwitz(-2.3,Pi+I*log(2)) %5 = -5.1928369229555125820137832704455696057\ - 6.1349660138824147237884128986232049582*I ? zetahurwitz(-1+x^2+O(x^3),1) %6 = -0.083333333333333333333333333333333333333\ - 0.16542114370045092921391966024278064276*x^2 + O(x^3) ? zetahurwitz(1+x+O(x^4),2) %7 = 1.0000000000000000000000000000000000000*x^-1\ - 0.42278433509846713939348790991759756896\ + 0.072815845483676724860586375874901319138*x + O(x^2) ? zetahurwitz(2,1,2) \\ zeta''(2) %8 = 1.9892802342989010234208586874215163815 The derivative can be used to compute Barnes' multiple gamma functions. For instance:
? mygamma(z)=exp(zetahurwitz(0,z,1)-zeta'(0)); /* Alternate way to compute the gamma function */ ? BarnesG(z)=exp(-zetahurwitz(-1,z,1)+(z-1)*lngamma(z)+zeta'(-1)); /* Barnes G function, satisfying G(z+1)=gamma(z)*G(z): */ ? BarnesG(6)/BarnesG(5) % = 24.000000000000000000000000000000000002
The library syntax is
| |
zetamult(s, {t = 0}) | |
For s a vector of positive integers such that s[1] ≥ 2,
returns the multiple zeta value (MZV)
ζ(s1,..., sk) = ∑n_{1 > ... > nk > 0}
n1-s1...nk-sk
of length k and weight ∑i si.
More generally, return Yamamoto's t-MZV interpolation evaluated at t:
for t = 0, this is the ordinary MZV; for t = 1, we obtain the MZSV
star value, with ≥ instead of strict inequalities;
and of course, for t =
? zetamult([2,1]) - zeta(3) \\ Euler's identity %1 = 0.E-38 ? zetamult([2,1], 1) \\ star value %2 = 2.4041138063191885707994763230228999815 ? zetamult([2,1], 'x) %3 = 1.20205[...]*x + 1.20205[...] If the bit precision is B, this function runs in time Õ(k(B+k)2) if t = 0, and Õ(kB3) otherwise.
In addition to the above format (
The library syntax is
| |
zetamultall(k, {flag = 0}) | |
List of all multiple zeta values (MZVs) for weight s1 +...+ sr
up to k. Binary digits of flag mean : 0 = star values if set;
1 = values up to to duality if set (see
With the default value flag = 0, the function returns a vector with 2k-1-1
components whose i-th entry is the MZV of
? Z = zetamultall(5); #Z \\ 2^4 - 1 MZVs of weight <= 5 %1 = 15 ? Z[10] %2 = 0.22881039760335375976874614894168879193 ? zetamultconvert(10) %3 = Vecsmall([3, 2]) \\ {index 10 corresponds to ζ(3,2)} ? zetamult(%) \\ double check %4 = 0.22881039760335375976874614894168879193 ? zetamult(10) \\ we can use the index directly %5 = 0.22881039760335375976874614894168879193 If we use flag bits 1 and 2, we avoid unnecessary computations and copying, saving a potential factor 4: half the values are in lower weight and computing up to duality save another rough factor 2. Unfortunately, the indexing now no longer corresponds to the new shorter vector of MZVs:
? Z = zetamultall(5, 2); #Z \\ up to duality %6 = 9 ? Z = zetamultall(5, 2); #Z \\ only weight 5 %7 = 8 ? Z = zetamultall(5, 2 + 4); #Z \\ both %8 = 4 So how to recover the value attached to index 10 ? Flag bit 3 returns the actual indices used:
? [Z, M] = zetamultall(5, 2 + 8); M \\ other indices were not included %9 = Vecsmall([1, 2, 4, 5, 6, 8, 9, 10, 12]) ? Z[8] \\ index m = 10 is now in M[8] %10 = 0.22881039760335375976874614894168879193 ? [Z, M] = zetamultall(5, 2 + 4 + 8); M %11 = Vecsmall([8, 9, 10, 12]) ? Z[3] \\ index m = 10 is now in M[3] %12 = 0.22881039760335375976874614894168879193 The following construction automates the above programmatically, looking up the MZVs of index 10 ( = ζ(3,2)) in all cases, without inspecting the various index sets M visually:
? Z[vecsearch(M, 10)] \\ works in all the above settings %13 = 0.22881039760335375976874614894168879193
The library syntax is
| |
zetamultconvert(a, {flag = 1}) | |
? zetamultconvert(10) %1 = Vecsmall([3, 2]) ? zetamultconvert(13) %2 = Vecsmall([2, 2, 1]) ? zetamultconvert(10, 0) %3 = Vecsmall([0, 0, 1, 0, 1]) ? zetamultconvert(13, 0) %4 = Vecsmall([0, 1, 0, 1, 1])
The last two lines imply that [3,2] and [2,2,1]
are dual (reverse order of bits and swap 0 and 1 in
? zetamult([3,2]) %5 = 0.22881039760335375976874614894168879193 ? zetamult([2,2,1]) %6 = 0.22881039760335375976874614894168879193
The library syntax is
| |
zetamultdual(s) | |
s being either an
? zetamultdual([4]) %1 = Vecsmall([2, 1, 1]) ? zetamultdual(%) %2 = Vecsmall([4]) ? zetamult(%1) - zetamult(%2) %3 = 0.E-38
In
? zetamultconvert([4], 0) %4 = Vecsmall([0, 0, 0, 1]) ? zetamultconvert([2,1,1], 0) %5 = Vecsmall([0, 1, 1, 1])
The library syntax is
| |