Pari/GP Reference Documentation  Contents - Index - Meta commands

Polynomials and power series


O   deriv   eval   factorpadic   intformal   padicappr   polcoeff   polcyclo   poldegree   poldisc   poldiscreduced   polhensellift   polinterpolate   polisirreducible   pollead   pollegendre   polrecip   polresultant   polroots   polrootsmod   polrootspadic   polsturm   polsubcyclo   polsylvestermatrix   polsym   poltchebi   polzagier   serconvol   serlaplace   serreverse   subst   taylor   thue   thueinit  
 
O(a  

^b): p-adic (if a is an integer greater or equal to 2) or power series zero (in all other cases), with precision given by b.

The library syntax is ggrandocp(a,b), where b is a long.

deriv(x,{v})  

derivative of x with respect to the main variable if v is omitted, and with respect to v otherwise. x can be any type except polmod. The derivative of a scalar type is zero, and the derivative of a vector or matrix is done componentwise. One can use x' as a shortcut if the derivative is with respect to the main variable of x.

The library syntax is deriv(x,v), where v is a long, and an omitted v is coded as -1.

eval(x)  

replaces in x the formal variables by the values that have been assigned to them after the creation of x. This is mainly useful in GP, and not in library mode. Do not confuse this with substitution (see subst). Applying this function to a character string yields the output from the corresponding GP command, as if directly input from the keyboard (see Section (??)).

The library syntax is geval(x). The more basic functions poleval(q,x), qfeval(q,x), and hqfeval(q,x) evaluate q at x, where q is respectively assumed to be a polynomial, a quadratic form (a symmetric matrix), or an Hermitian form (an Hermitian complex matrix).

factorpadic(pol,p,r,{flag = 0})  

p-adic factorization of the polynomial pol to precision r, the result being a two-column matrix as in factor. The factors are normalized so that their leading coefficient is a power of p. r must be strictly larger than the p-adic valuation of the discriminant of pol for the result to make any sense. The method used is a modified version of the round 4 algorithm of Zassenhaus.

If flag = 1, use an algorithm due to Buchmann and Lenstra, which is usually less efficient.

The library syntax is factorpadic4(pol,p,r), where r is a long integer.

intformal(x,{v})  

formal integration of x with respect to the main variable if v is omitted, with respect to the variable v otherwise. Since PARI does not know about "abstract" logarithms (they are immediately evaluated, if only to a power series), logarithmic terms in the result will yield an error. x can be of any type. When x is a rational function, it is assumed that the base ring is an integral domain of characteristic zero.

The library syntax is integ(x,v), where v is a long and an omitted v is coded as -1.

padicappr(pol,a)  

vector of p-adic roots of the polynomial pol congruent to the p-adic number a modulo p (or modulo 4 if p = 2), and with the same p-adic precision as a. The number a can be an ordinary p-adic number (type t_PADIC, i.e.an element of Q_p) or can be an element of a finite extension of Q_p, in which case it is of type t_POLMOD, where at least one of the coefficients of the polmod is a p-adic number. In this case, the result is the vector of roots belonging to the same extension of Q_p as a.

The library syntax is apprgen9(pol,a), but if a is known to be simply a p-adic number (type t_PADIC), the syntax apprgen(pol,a) can be used.

polcoeff(x,s,{v})  

coefficient of degree s of the polynomial x, with respect to the main variable if v is omitted, with respect to v otherwise.

The library syntax is polcoeff0(x,s,v), where v is a long and an omitted v is coded as -1. Also available is truecoeff(x,v).

poldegree(x,{v})  

degree of the polynomial x in the main variable if v is omitted, in the variable v otherwise. This is to be understood as follows. When x is a polynomial or a rational function, it gives the degree of x, the degree of 0 being -1 by convention. When x is a non-zero scalar, it gives 0, and when x is a zero scalar, it gives -1. Return an error otherwise.

The library syntax is poldegree(x,v), where v and the result are longs (and an omitted v is coded as -1). Also available is degree(x), which is equivalent to poldegree(x,-1).

polcyclo(n,{v = x})  

n-th cyclotomic polynomial, in variable v (x by default). The integer n must be positive.

The library syntax is cyclo(n,v), where n and v are long integers (v is a variable number, usually obtained through varn).

poldisc(pol,{v})  

discriminant of the polynomial pol in the main variable is v is omitted, in v otherwise. The algorithm used is the subresultant algorithm.

The library syntax is poldisc0(x,v). Also available is discsr(x), equivalent to poldisc0(x,-1).

poldiscreduced(f)  

reduced discriminant vector of the (integral, monic) polynomial f. This is the vector of elementary divisors of Z[alpha]/f'(alpha)Z[alpha], where alpha is a root of the polynomial f. The components of the result are all positive, and their product is equal to the absolute value of the discriminant off.

The library syntax is reduceddiscsmith(x).

polhensellift(x, y, p, e)  

given a vector y of polynomials that are pairwise relatively prime modulo the prime p, and whose product is congruent to x modulo p, lift the elements of y to polynomials whose product is congruent to x modulo p^e.

The library syntax is polhensellift(x,y,p,e) where e must be a long.

polinterpolate(xa,{ya},{v = x},{&e})  

given the data vectors xa and ya of the same length n (xa containing the x-coordinates, and ya the corresponding y-coordinates), this function finds the interpolating polynomial passing through these points and evaluates it atv. If ya is omitted, return the polynomial interpolating the (i,xa[i]). If present, e will contain an error estimate on the returned value.

The library syntax is polint(xa,ya,v,&e), where e will contain an error estimate on the returned value.

polisirreducible(pol)  

pol being a polynomial (univariate in the present version 2.1.1), returns 1 if pol is non-constant and irreducible, 0 otherwise. Irreducibility is checked over the smallest base field over which pol seems to be defined.

The library syntax is gisirreducible(pol).

pollead(x,{v})  

leading coefficient of the polynomial or power series x. This is computed with respect to the main variable of x if v is omitted, with respect to the variable v otherwise.

The library syntax is pollead(x,v), where v is a long and an omitted v is coded as -1. Also available is leadingcoeff(x).

pollegendre(n,{v = x})  

creates the n^{th} Legendre polynomial, in variable v.

The library syntax is legendre(n), where x is a long.

polrecip(pol)  

reciprocal polynomial of pol, i.e.the coefficients are in reverse order. pol must be a polynomial.

The library syntax is polrecip(x).

polresultant(x,y,{v},{flag = 0})  

resultant of the two polynomials x and y with exact entries, with respect to the main variables of x and y if v is omitted, with respect to the variable v otherwise. The algorithm used is the subresultant algorithm by default.

If flag = 1, uses the determinant of Sylvester's matrix instead (here x and y may have non-exact coefficients).

If flag = 2, uses Ducos's modified subresultant algorithm. It should be much faster than the default if the coefficient ring is complicated (e.g multivariate polynomials or huge coefficients), and slightly slower otherwise.

The library syntax is polresultant0(x,y,v,flag), where v is a long and an omitted v is coded as -1. Also available are subres(x,y) (flag = 0) and resultant2(x,y) (flag = 1).

polroots(pol,{flag = 0})  

complex roots of the polynomial pol, given as a column vector where each root is repeated according to its multiplicity. The precision is given as for transcendental functions: under GP it is kept in the variable realprecision and is transparent to the user, but it must be explicitly given as a second argument in library mode.

The algorithm used is a modification of A.Sch¨nhage's remarkable root-finding algorithm, due to and implemented by X.Gourdon. Barring bugs, it is guaranteed to converge and to give the roots to the required accuracy.

If flag = 1, use a variant of the Newton-Raphson method, which is not guaranteed to converge, but is rather fast. If you get the messages "too many iterations in roots" or "INTERNAL ERROR: incorrect result in roots", use the default function (i.e.no flag or flag = 0). This used to be the default root-finding function in PARI until version 1.39.06.

The library syntax is roots(pol,prec) or rootsold(pol,prec).

polrootsmod(pol,p,{flag = 0})  

row vector of roots modulo p of the polynomial pol. The particular non-prime value p = 4 is accepted, mainly for 2-adic computations. Multiple roots are not repeated.

If p < 100, you may try setting flag = 1, which uses a naive search. In this case, multiple roots are repeated with their order of multiplicity.

The library syntax is rootmod(pol,p) (flag = 0) or rootmod2(pol,p) (flag = 1).

polrootspadic(pol,p,r)  

row vector of p-adic roots of the polynomial pol with p-adic precision equal to r. Multiple roots are not repeated. p is assumed to be a prime.

The library syntax is rootpadic(pol,p,r), where r is a long.

polsturm(pol,{a},{b})  

number of real roots of the real polynomial pol in the interval ]a,b], using Sturm's algorithm. a (resp.b) is taken to be - oo (resp.+ oo ) if omitted.

The library syntax is sturmpart(pol,a,b). Use NULL to omit an argument. sturm (pol) is equivalent to sturmpart (pol,NULL,NULL). The result is a long.

polsubcyclo(n,d,{v = x})  

gives a polynomial (in variable v) defining the sub-Abelian extension of degree d of the cyclotomic field Q(zeta_n), where d | phi(n). (Z/nZ)^* has to be cyclic (i.e.n = 2, 4, p^k or 2p^k for an odd prime p). The function galoissubcyclo covers the general case.

The library syntax is subcyclo(n,d,v), where v is a variable number.

polsylvestermatrix(x,y)  

forms the Sylvester matrix corresponding to the two polynomials x and y, where the coefficients of the polynomials are put in the columns of the matrix (which is the natural direction for solving equations afterwards). The use of this matrix can be essential when dealing with polynomials with inexact entries, since polynomial Euclidean division doesn't make much sense in this case.

The library syntax is sylvestermatrix(x,y).

polsym(x,n)  

creates the vector of the symmetric powers of the roots of the polynomial x up to power n, using Newton's formula.

The library syntax is polsym(x).

poltchebi(n,{v = x})  

creates the n^{th} Chebyshev polynomial, in variable v.

The library syntax is tchebi(n,v), where n and v are long integers (v is a variable number).

polzagier(n,m)  

creates Zagier's polynomial P_{n,m} used in the functions sumalt and sumpos (with flag = 1). The exact definition can be found in a forthcoming paper. One must have m <= n.

The library syntax is polzagreel(n,m,prec) if the result is only wanted as a polynomial with real coefficients to the precision prec, or polzag(n,m) if the result is wanted exactly, where n and m are longs.

serconvol(x,y)  

convolution (or Hadamard product) of the two power series x and y; in other words if x = sum a_k*X^k and y = sum b_k*X^k then serconvol(x,y) = sum a_k*b_k*X^k.

The library syntax is convol(x,y).

serlaplace(x)  

x must be a power series with only non-negative exponents. If x = sum (a_k/k!)*X^k then the result is sum a_k*X^k.

The library syntax is laplace(x).

serreverse(x)  

reverse power series (i.e.x^{-1}, not 1/x) of x. x must be a power series whose valuation is exactly equal to one.

The library syntax is recip(x).

subst(x,y,z)  

replace the simple variable y by the argument z in the "polynomial" expression x. Every type is allowed for x, but if it is not a genuine polynomial (or power series, or rational function), the substitution will be done as if the scalar components were polynomials of degree one. In particular, beware that:

? subst(1, x, [1,2; 3,4])
 %1 =
 [1 0]
 
 [0 1]
 
 ? subst(1, x, Mat([0,1]))
   ***   forbidden substitution by a non square matrix

If x is a power series, z must be either a polynomial, a power series, or a rational function. y must be a simple variable name.

The library syntax is gsubst(x,v,z), where v is the number of the variable y.

taylor(x,y)  

Taylor expansion around 0 of x with respect to the simple variable y. x can be of any reasonable type, for example a rational function. The number of terms of the expansion is transparent to the user under GP, but must be given as a second argument in library mode.

The library syntax is tayl(x,y,n), where the long integer n is the desired number of terms in the expansion.

thue(tnf,a,{sol})  

solves the equation P(x,y) = a in integers x and y, where tnf was created with thueinit(P). sol, if present, contains the solutions of Norm(x) = a modulo units of positive norm in the number field defined by P (as computed by bnfisintnorm). If tnf was computed without assuming GRH (flag = 1 in thueinit), the result is unconditional. For instance, here's how to solve the Thue equation x^{13} - 5y^{13} = - 4:

? tnf = thueinit(x^13 - 5);
 ? thue(tnf, -4)
 %1 = [[1, 1]]

Hence, assuming GRH, the only solution is x = 1, y = 1.

The library syntax is thue(tnf,a,sol), where an omitted sol is coded as NULL.

thueinit(P,{flag = 0})  

initializes the tnf corresponding to P. It is meant to be used in conjunction with thue to solve Thue equations P(x,y) = a, where a is an integer. If flag is non-zero, certify the result unconditionnaly, Otherwise, assume GRH, this being much faster of course.

The library syntax is thueinit(P,flag,prec).