Current Path : /usr/local/lib/perl5/site_perl/5.8.9/mach/Math/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //usr/local/lib/perl5/site_perl/5.8.9/mach/Math/libPARI.pod |
=head1 NAME libPARI - Functions and Operations Available in PARI and GP =head1 DESCRIPTION X<Label se:functions> The functions and operators available in PARI and in the GP/PARI calculator are numerous and everexpanding. Here is a description of the ones available in version B<2.2.0>. It should be noted that many of these functions accept quite different types as arguments, but others are more restricted. The list of acceptable types will be given for each function or class of functions. Except when stated otherwise, it is understood that a function or operation which should make natural sense is legal. In this chapter, we will describe the functions according to a rough classification. The general entry looks something like: B<foo>C<(x,{I<flag> = 0})>: short description. X<foo>The library syntax is B<foo>C<(x,I<flag>)>. This means that the GP function C<foo> has one mandatory argument C<x>, and an optional one, C<I<flag>>, whose default value is 0. (The C<{}> should not be typed, it is just a convenient notation we will use throughout to denote optional arguments.) That is, you can type C<foo(x,2)>, or C<foo(x)>, which is then understood to mean C<foo(x,0)>. As well, a comma or closing parenthesis, where an optional argument should have been, signals to GP it should use the default. Thus, the syntax C<foo(x,)> is also accepted as a synonym for our last expression. When a function has more than one optional argument, the argument list is filled with user supplied values, in order. When none are left, the defaults are used instead. Thus, assuming that C<foo>'s prototype had been S< >C< B<foo>({x = 1},{y = 2},{z = 3}), > typing in C<foo(6,4)> would give you C<foo(6,4,3)>. In the rare case when you want to set some far away argument, and leave the defaults in between as they stand, you can use the ``empty arg'' trick alluded to above: C<foo(6,,1)> would yield C<foo(6,2,1)>. By the way, C<foo()> by itself yields C<foo(1,2,3)> as was to be expected. In this rather special case of a function having no mandatory argument, you can even omit the C<()>: a standalone C<foo> would be enough (though we do not recommend it for your scripts, for the sake of clarity). In defining GP syntax, we strove to put optional arguments at the end of the argument list (of course, since they would not make sense otherwise), and in order of decreasing usefulness so that, most of the time, you will be able to ignore them. Finally, an optional argument (between braces) followed by a star, like C<{I<x>}*>, means that any number of such arguments (possibly none) can be given. This is in particular used by the various C<print> routines. B<Flags>. A X<flag>I<flag> is an argument which, rather than conveying actual information to the routine, intructs it to change its default behaviour, e.g.S< >return more or less information. All such flags are optional, and will be called I<flag> in the function descriptions to follow. There are two different kind of flags \item generic: all valid values for the flag are individually described (``If I<flag> is equal to C<1>, then...''). \item binary:X<binary flag> use customary binary notation as a compact way to represent many toggles with just one integer. Let C<(p_0,...,p_n)> be a list of switches (i.e.S< >of properties which take either the value C<0> orS< >C<1>), the number C<2^3 + 2^5 = 40> means that C<p_3> and C<p_5> are set (that is, set to C<1>), and none of the others are (that is, they are set to C<0>). This is announced as ``The binary digits of C<I<flag>> mean 1: C<p_0>, 2: C<p_1>, 4: C<p_2>'', and so on, using the available consecutive powers ofS< >C<2>. B<Mnemonics for flags>. Numeric flags as mentionned above are obscure, error-prone, and quite rigid: should the authors want to adopt a new flag numbering scheme (for instance when noticing flags with the same meaning but different numeric values across a set of routines), it would break backward compatibility. The only advantage of explicit numeric values is that they are fast to type, so their use is only advised when using the calculator C<gp>. As an alternative, one can replace a numeric flag by a character string containing symbolic identifiers. For a generic flag, the mnemonic corresponding to the numeric identifier is given after it as in fun(x, {flag = 0} ): If flag is equal to 1 = AGM, use an agm formula\dots which means that one can use indifferently C<fun(x, 1)> or C<fun(x, AGM)>. For a binary flag, mnemonics corresponding to the various toggles are given after each of them. They can be negated by prepending C<no_> to the mnemonic, or by removing such a prefix. These toggles are grouped together using any punctuation character (such as C<','> or C<';'>). For instance (taken from description of C<X<ploth>ploth(X = a,b,I<expr>,{I<flag> = 0},{n = 0})>) Binary digits of flags mean: C<1 = Parametric>, C<2 = Recursive>,... so that, instead of C<1>, one could use the mnemonic C<"Parametric; no_Recursive">, or simply C<"Parametric"> since C<Recursive> is unset by default (default value of C<I<flag>> is C<0>, i.e.S< >everything unset). B<Pointers>.\varsidx{pointer} If a parameter in the function prototype is prefixed with a & sign, as in B<foo>C<(x,&e)> it means that, besides the normal return value, the function may assign a value to C<e> as a side effect. When passing the argument, the & sign has to be typed in explicitly. As of version B<2.2.0>, this X<pointer>I<pointer> argument is optional for all documented functions, hence the & will always appear between brackets as in C<Z_issquare>C<(x,{&e})>. B<About library programming>. the I<library> function C<foo>, as defined at the beginning of this section, is seen to have two mandatory arguments, C<x> and I<flag>: no PARI mathematical function has been implemented so as to accept a variable number of arguments, so all arguments are mandatory when programming with the library (often, variants are provided corresponding to the various flag values). When not mentioned otherwise, the result and arguments of a function are assumed implicitly to be of type C<GEN>. Most other functions return an object of type C<long> integer in C (see ChapterS< >4). The variable or parameter names I<prec> and I<flag> always denote C<long> integers. The X<entree>C<entree> type is used by the library to implement iterators (loops, sums, integrals, etc.) when a formal variable has to successively assume a number of values in a given set. When programming with the library, it is easier and much more efficient to code loops and the like directly. Hence this type is not documented, although it does appear in a few library function prototypes below. See L<Label se:sums> for more details. =head1 Standard monadic or dyadic operators =head2 +C</>- The expressions C<+>C<x> and C<->C<x> refer to monadic operators (the first does nothing, the second negates C<x>). X<gneg>The library syntax is B<gneg>C<(x)> for C<->C<x>. =head2 +, C<-> The expression C<x> C<+> C<y> is the X<sum>sum and C<x> C<-> C<y> is the X<difference>difference of C<x> and C<y>. Among the prominent impossibilities are addition/subtraction between a scalar type and a vector or a matrix, between vector/matrices of incompatible sizes and between an intmod and a real number. X<gadd>The library syntax is B<gadd>C<(x,y)> C<x> C<+> C<y>, C< B<gsub>(x,y)>X<gsub> for C<x> C<-> C<y>. =head2 * The expression C<x> C<*> C<y> is the X<product>product of C<x> and C<y>. Among the prominent impossibilities are multiplication between vector/matrices of incompatible sizes, between an intmod and a real number. Note that because of vector and matrix operations, C<*> is not necessarily commutative. Note also that since multiplication between two column or two row vectors is not allowed, to obtain the X<scalar product>scalar product of two vectors of the same length, you must multiply a line vector by a column vector, if necessary by transposing one of the vectors (using the operator C<~> or the function C<mattranspose>, see L<Label se:linear_algebra>). If C<x> and C<y> are binary quadratic forms, compose them. See also C<qfbnucomp> and C<qfbnupow>. X<gmul>The library syntax is B<gmul>C<(x,y)> for C<x> C<*> C<y>. Also available is C< B<gsqr>(x)>X<gsqr> for C<x> C<*> C<x> (faster of course!). =head2 / The expression C<x> C</> C<y> is the X<quotient>quotient of C<x> and C<y>. In addition to the impossibilities for multiplication, note that if the divisor is a matrix, it must be an invertible square matrix, and in that case the result is C<x*y^{-1}>. Furthermore note that the result is as exact as possible: in particular, division of two integers always gives a rational number (which may be an integer if the quotient is exact) and \emph{not} the Euclidean quotient (see C<x> C<\> C<y> for that), and similarly the quotient of two polynomials is a rational function in general. To obtain the approximate real value of the quotient of two integers, add C<0.> to the result; to obtain the approximate C<p>-adic value of the quotient of two integers, add C<O(p^k)> to the result; finally, to obtain the X<Taylor series>Taylor series expansion of the quotient of two polynomials, add C<O(X^k)> to the result or use the C<taylor> function (see L<Label se:taylor>). X<Label se:gdiv> X<gdiv>The library syntax is B<gdiv>C<(x,y)> for C<x> C</> C<y>. =head2 \ The expression C<x \y> is the X<Euclidean quotient>Euclidean quotient of C<x> and C<y>. If C<y> is a real scalar, this is defined as C<floor(x/y)> if C<y E<gt> 0>, and C<ceil(x/y)> if C<y E<lt> 0> and the division is not exact. Hence the remainder C<x - (x\y)*y> is in C<[0, |y|[>. Note that when C<y> is an integer and C<x> a polynomial, C<y> is first promoted to a polynomial of degree C<0>. When C<x> is a vector or matrix, the operator is applied componentwise. X<gdivent>The library syntax is B<gdivent>C<(x,y)> for C<x> C<\> C<y>. =head2 \/ The expression C<x> C<\/> C<y> evaluates to the rounded X<Euclidean quotient>Euclidean quotient of C<x> and C<y>. This is the same as C<x \y> except for scalar division: the quotient is such that the corresponding remainder is smallest in absolute value and in case of a tie the quotient closest to C<+ oo > is chosen (hence the remainder would belong to C<]-|y|/2, |y|/2]>). When C<x> is a vector or matrix, the operator is applied componentwise. X<gdivround>The library syntax is B<gdivround>C<(x,y)> for C<x> C<\/> C<y>. =head2 % The expression C<x % y> evaluates to the modular X<Euclidean remainder>Euclidean remainder of C<x> and C<y>, which we now define. If C<y> is an integer, this is the smallest non-negative integer congruent to C<x> modulo C<y>. If C<y> is a polynomial, this is the polynomial of smallest degree congruent to C<x> modulo C<y>. When C<y> is a non-integral real number, C<x%y> is defined as C<x - (x\y)*y>. This coincides with the definition for C<y> integer if and only if C<x> is an integer, but still belongs to C<[0, |y|[>. For instance: ? (1/2) % 3 %1 = 2 ? 0.5 % 3 *** forbidden division t_REAL % t_INT. ? (1/2) % 3.0 %2 = 1/2 Note that when C<y> is an integer and C<x> a polynomial, C<y> is first promoted to a polynomial of degree C<0>. When C<x> is a vector or matrix, the operator is applied componentwise. X<gmod>The library syntax is B<gmod>C<(x,y)> for C<x> C<%> C<y>. =head2 X<divrem>divremC<(x,y,{v})> creates a column vector with two components, the first being the Euclidean quotient (C<x \y>), the second the Euclidean remainder (C<x - (x\y)*y>), of the division of C<x> by C<y>. This avoids the need to do two divisions if one needs both the quotient and the remainder. If C<v> is present, and C<x>, C<y> are multivariate polynomials, divide with respect to the variable C<v>. Beware that C<divrem(x,y)[2]> is in general not the same as C<x % y>; there is no operator to obtain it in GP: ? divrem(1/2, 3)[2] %1 = 1/2 ? (1/2) % 3 %2 = 2 ? divrem(Mod(2,9), 3)[2] *** forbidden division t_INTMOD \ t_INT. ? Mod(2,9) % 6 %3 = Mod(2,3) X<divrem>The library syntax is B<divrem>C<(x,y,v)>,where C<v> is a C<long>. Also available as C< B<gdiventres>(x,y)>X<gdiventres> when C<v> is not needed. =head2 ^ The expression C<x^n> is X<powering>powering. If the exponent is an integer, then exact operations are performed using binary (left-shift) powering techniques. In particular, in this case C<x> cannot be a vector or matrix unless it is a square matrix (invertible if the exponent is negative). If C<x> is a C<p>-adic number, its precision will increase if C<v_p(n) E<gt> 0>. Powering a binary quadratic form (types C<t_QFI> and C<t_QFR>) returns a reduced representative of the class, provided the input is reduced. In particular, C<x^1> is identical to C<x>. PARI is able to rewrite the multiplication C<x * x> of two \emph{identical} objects as C<x^2>, or C<sqr(x)>. Here, identical means the operands are two different labels referencing the same chunk of memory; no equality test is performed. This is no longer true when more than two arguments are involved. If the exponent is not of type integer, this is treated as a transcendental function (see L<Label se:trans>), and in particular has the effect of componentwise powering on vector or matrices. As an exception, if the exponent is a rational number C<p/q> and C<x> an integer modulo a prime or a C<p>-adic number, return a solution C<y> of C<y^q = x^p> if it exists. Currently, C<q> must not have large prime factors. Beware that ? Mod(7,19)^(1/2) %1 = Mod(11, 19) /* is any square root */ ? sqrt(Mod(7,19)) %2 = Mod(8, 19) /* is the smallest square root */ ? Mod(7,19)^(3/5) %3 = Mod(1, 19) ? %3^(5/3) %4 = Mod(1, 19) /* Mod(7,19) is just another cubic root */ If the exponent is a negative integer, an X<inverse>inverse must be computed. For non-invertible C<t_INTMOD>, this will fail and implicitly exhibit a non trivial factor of the modulus: ? Mod(4,6)^(-1) *** impossible inverse modulo: Mod(2, 6). (Here, a factor 2 is obtained directly. In general, take the gcd of the representative and the modulus.) This is most useful when performing complicated operations modulo an integer C<N> whose factorization is unknown. Either the computation succeeds and all is well, or a factor C<d> is discovered and the computation may be restarted modulo C<d> or C<N/d>. For non-invertible C<t_POLMOD>, this will fail without exhibiting a factor. ? Mod(x^2, x^3-x)^(-1) *** non-invertible polynomial in RgXQ_inv. ? a = Mod(3,4)*y^3 + Mod(1,4); b = y^6+y^5+y^4+y^3+y^2+y+1; ? Mod(a, b)^(-1); *** non-invertible polynomial in RgXQ_inv. In fact the latter polynomial is invertible, but the algorithm used (subresultant) assumes the base ring is a domain. If it is not the case, as here for C<B<I<Z>>/4B<I<Z>>>, a result will be correct but chances are an error will occur first. In this specific case, one should work with C<2>-adics. In general, one can try the following approach ? inversemod(a, b) = { local(m); m = polsylvestermatrix(polrecip(a), polrecip(b)); m = matinverseimage(m, matid(#m)[,1]); Polrev( vecextract(m, Str("..", poldegree(b))), variable(b) ) } ? inversemod(a,b) %2 = Mod(2,4)*y^5 + Mod(3,4)*y^3 + Mod(1,4)*y^2 + Mod(3,4)*y + Mod(2,4) This is not guaranteed to work either since it must invert pivots. See L<Label se:linear_algebra>. X<gpow>The library syntax is B<gpow>C<(x,n,I<prec>)> for C<x^n>. =head2 X<bittest>bittestC<(x,n)> outputs the C<n^{th}> bit of C<x> starting from the right (i.e.S< >the coefficient of C<2^n> in the binary expansion of C<x>). The result is 0 or 1. To extract several bits at once as a vector, pass a vector for C<n>. See L<Label se:bitand> for the behaviour at negative arguments. X<bittest>The library syntax is B<bittest>C<(x,n)>, where C<n> and the result are C<long>s. =head2 X<shift>shiftC<(x,n)> or C<x> C<E<lt>E<lt> > C<n> ( = C<x> C<E<gt>E<gt> > C<(-n)>) shifts C<x> componentwise left by C<n> bits if C<n E<gt>= 0> and right by C<|n|> bits if C<n E<lt> 0>. A left shift by C<n> corresponds to multiplication by C<2^n>. A right shift of an integer C<x> by C<|n|> corresponds to a Euclidean division of C<x> by C<2^{|n|}> with a remainder of the same sign as C<x>, hence is not the same (in general) as C<x \ 2^n>. X<gshift>The library syntax is B<gshift>C<(x,n)> where C<n> is a C<long>. =head2 X<shiftmul>shiftmulC<(x,n)> multiplies C<x> by C<2^n>. The difference with C<shift> is that when C<n E<lt> 0>, ordinary division takes place, hence for example if C<x> is an integer the result may be a fraction, while for shifts Euclidean division takes place when C<n E<lt> 0> hence if C<x> is an integer the result is still an integer. X<gmul2n>The library syntax is B<gmul2n>C<(x,n)> where C<n> is a C<long>. =head2 Comparison and boolean operators X<boolean operators>The six standard X<comparison operators>comparison operators C<E<lt>= >, C<E<lt> >, C<E<gt>= >, C<E<gt> >, C< == >, C<! = > are available in GP, and in library mode under the names X<gle>C<gle>, X<glt>C<glt>, X<gge>C<gge>, X<ggt>C<ggt>, X<geq>C<geq>, X<gne>C<gne> respectively. The library syntax is C<I<co>(x,y)>, where I<co> is the comparison operator. The result is 1 (as a C<GEN>) if the comparison is true, 0 (as a C<GEN>) if it is false. For the purpose of comparison, C<t_STR> objects are strictly larger than any other non-string type; two C<t_STR> objects are compared using the standard lexicographic order. The standard boolean functions C<||> (X<inclusive or>inclusive or), C<&&> (X<and>and)X<or> and C<!> (X<not>not) are also available, and the library syntax is C< B<gor>(x,y)>X<gor>, C< B<gand>(x,y)>X<gand> and C< B<gnot>(x)>X<gnot> respectively. In library mode, it is in fact usually preferable to use the two basic functions which are C< B<gcmp>(x,y)>X<gcmp> which gives the sign (1, 0, or -1) of C<x-y>, where C<x> and C<y> must be in B<I<R>>, and C< B<gequal>(x,y)>X<gequal> which can be applied to any two PARI objects C<x> and C<y> and gives 1 (i.e.S< >true) if they are equal (but not necessarily identical), 0 (i.e.S< >false) otherwise. Comparisons to special constants are implemented and should be used instead of C<gequal>: C< B<gcmp0>(x)>X<gcmp0> (C<x == 0> ?), C< B<gcmp1>(x)>X<gcmp1> (C<x == 1> ?), and C< B<gcmp_1>(x)>X<gcmp_1> (C<x == -1> ?). Note that C<gcmp0(x)> tests whether C<x> is equal to zero, even if C<x> is not an exact object. To test whether C<x> is an exact object which is equal to zero, one must use C< B<isexactzero>(x)>X<isexactzero>. Also note that the C<gcmp> and C<gequal> functions return a C-integer, and \emph{not} a C<GEN> like C<gle> etc. GP accepts the following synonyms for some of the above functions: since we thought it might easily lead to confusion, we don't use the customary C operators for bitwise C<and> or bitwise C<or> (use X<bitand>C<bitand> or X<bitor>C<bitor>), hence C<|> and C<&> are accepted asX<bitwise and>X<bitwise or> synonyms of C<||> and C<&&> respectively. Also, C<E<lt> E<gt> > is accepted as a synonym for C<! = >. On the other hand, C< = > is definitely \emph{not} a synonym for C< == > since it is the assignment statement. =head2 X<lex>lexC<(x,y)> gives the result of a lexicographic comparison between C<x> and C<y> (as C<-1>, C<0> or C<1>). This is to be interpreted in quite a wide sense: It is admissible to compare objects of different types (scalars, vectors, matrices), provided the scalars can be compared, as well as vectors/matrices of different lengths. The comparison is recursive. In case all components are equal up to the smallest length of the operands, the more complex is considered to be larger. More precisely, the longest is the largest; when lengths are equal, we have matrix C< E<gt> > vector C< E<gt> > scalar. For example: ? lex([1,3], [1,2,5]) %1 = 1 ? lex([1,3], [1,3,-1]) %2 = -1 ? lex([1], [[1]]) %3 = -1 ? lex([1], [1]~) %4 = 0 X<lexcmp>The library syntax is B<lexcmp>C<(x,y)>. =head2 X<sign>signC<(x)> X<sign>sign (C<0>, C<1> or C<-1>) of C<x>, which must be of type integer, real or fraction. X<gsigne>The library syntax is B<gsigne>C<(x)>. The result is a C<long>. =head2 X<max>maxC<(x,y)> and C< B<min>(x,y)>X<min> creates the maximum and minimum of C<x> and C<y> when they can be compared. X<gmax>The library syntax is B<gmax>C<(x,y)> and C< B<gmin>(x,y)>X<gmin>. =head2 X<vecmax>vecmaxC<(x)> if C<x> is a vector or a matrix, returns the maximum of the elements of C<x>, otherwise returns a copy of C<x>. Error if C<x> is empty. X<vecmax>The library syntax is B<vecmax>C<(x)>. =head2 X<vecmin>vecminC<(x)> if C<x> is a vector or a matrix, returns the minimum of the elements of C<x>, otherwise returns a copy of C<x>. Error if C<x> is empty. X<vecmin>The library syntax is B<vecmin>C<(x)>. =head1 Conversions and similar elementary functions or commands X<Label se:conversion> Many of the conversion functions are rounding or truncating operations. In this case, if the argument is a rational function, the result is the Euclidean quotient of the numerator by the denominator, and if the argument is a vector or a matrix, the operation is done componentwise. This will not be restated for every function. =head2 X<Col>ColC<({x = []})> transforms the object C<x> into a column vector. The vector will be with one component only, except when C<x> is a vector or a quadratic form (in which case the resulting vector is simply the initial object considered as a column vector), a matrix (the column of row vectors comprising the matrix is returned), a character string (a column of individual characters is returned), but more importantly when C<x> is a polynomial or a power series. In the case of a polynomial, the coefficients of the vector start with the leading coefficient of the polynomial, while for power series only the significant coefficients are taken into account, but this time by increasing order of degree. X<gtocol>The library syntax is B<gtocol>C<(x)>. =head2 X<List>ListC<({x = []})> transforms a (row or column) vector C<x> into a list. The only other way to create a C<t_LIST> is to use the function C<listcreate>. This is useless in library mode. =head2 X<Mat>MatC<({x = []})> transforms the object C<x> into a matrix. If C<x> is already a matrix, a copy of C<x> is created. If C<x> is not a vector or a matrix, this creates a C<1 x 1> matrix. If C<x> is a row (resp. column) vector, this creates a 1-row (resp. 1-column) matrix, \emph{unless} all elements are column (resp.S< >row) vectors of the same length, in which case the vectors are concatenated sideways and the associated big matrix is returned. ? Mat(x + 1) %1 = [x + 1] ? Vec( matid(3) ) %2 = [[1, 0, 0]~, [0, 1, 0]~, [0, 0, 1]~] ? Mat(%) %3 = [1 0 0] [0 1 0] [0 0 1] ? Col( [1,2; 3,4] ) %4 = [[1, 2], [3, 4]]~ ? Mat(%) %5 = [1 2] [3 4] X<gtomat>The library syntax is B<gtomat>C<(x)>. =head2 X<Mod>ModC<(x,y,{I<flag> = 0})> X<Label se:Mod> creates the PARI object C<(x mod y)>, i.e.S< >an intmod or a polmod. C<y> must be an integer or a polynomial. If C<y> is an integer, C<x> must be an integer, a rational number, or a C<p>-adic number compatible with the modulus C<y>. If C<y> is a polynomial, C<x> must be a scalar (which is not a polmod), a polynomial, a rational function, or a power series. This function is not the same as C<x> C<%> C<y>, the result of which is an integer or a polynomial. C<I<flag>> is obsolete and should not be used. X<gmodulo>The library syntax is B<gmodulo>C<(x,y)>. =head2 X<Pol>PolC<(x,{v = x})> transforms the object C<x> into a polynomial with main variable C<v>. If C<x> is a scalar, this gives a constant polynomial. If C<x> is a power series, the effect is identical to C<truncate> (see there), i.e.S< >it chops off the C<O(X^k)>. If C<x> is a vector, this function creates the polynomial whose coefficients are given in C<x>, with C<x[1]> being the leading coefficient (which can be zero). B<Warning:> this is \emph{not} a substitution function. It will not transform an object containing variables of higher priority thanS< >C<v>. ? Pol(x + y, y) *** Pol: variable must have higher priority in gtopoly. X<gtopoly>The library syntax is B<gtopoly>C<(x,v)>, where C<v> is a variable number. =head2 X<Polrev>PolrevC<(x,{v = x})> transform the object C<x> into a polynomial with main variable C<v>. If C<x> is a scalar, this gives a constant polynomial. If C<x> is a power series, the effect is identical to C<truncate> (see there), i.e.S< >it chops off the C<O(X^k)>. If C<x> is a vector, this function creates the polynomial whose coefficients are given in C<x>, with C<x[1]> being the constant term. Note that this is the reverse of C<Pol> if C<x> is a vector, otherwise it is identical to C<Pol>. X<gtopolyrev>The library syntax is B<gtopolyrev>C<(x,v)>, where C<v> is a variable number. =head2 X<Qfb>QfbC<(a,b,c,{D = 0.})> creates the binary quadratic form C<ax^2+bxy+cy^2>. If C<b^2-4ac E<gt> 0>, initialize X<Shanks>Shanks' distance function to C<D>. Negative definite forms are not implemented, use their positive definite counterpart instead. X<Qfb0>The library syntax is B<Qfb0>C<(a,b,c,D,I<prec>)>. Also available are C< B<qfi>(a,b,c)>X<qfi> (when C<b^2-4ac E<lt> 0>), and C< B<qfr>(a,b,c,d)>X<qfr> (when C<b^2-4ac E<gt> 0>).X<binary quadratic form> =head2 X<Ser>SerC<(x,{v = x})> transforms the object C<x> into a power series with main variable C<v> (C<x> by default). If C<x> is a scalar, this gives a constant power series with precision given by the default C<serieslength> (corresponding to the C global variable C<precdl>). If C<x> is a polynomial, the precision is the greatest of C<precdl> and the degree of the polynomial. If C<x> is a vector, the precision is similarly given, and the coefficients of the vector are understood to be the coefficients of the power series starting from the constant term (i.e.S< >the reverse of the function C<Pol>). The warning given for C<Pol> also applies here: this is not a substitution function. X<gtoser>The library syntax is B<gtoser>C<(x,v)>, where C<v> is a variable number (i.e.S< >a C integer). =head2 X<Set>SetC<({x = []})> converts C<x> into a set, i.e.S< >into a row vector of character strings, with strictly increasing entries with respect to lexicographic ordering. The components of C<x> are put in canonical form (type C<t_STR>) so as to be easily sorted. To recover an ordinary C<GEN> from such an element, you can apply X<eval>C<eval> to it. X<gtoset>The library syntax is B<gtoset>C<(x)>. =head2 X<Str>StrC<({x}*)> converts its argument list into a single character string (type C<t_STR>, the empty string if C<x> is omitted). To recover an ordinary C<GEN> from a string, apply C<eval> to it. The arguments of C<Str> are evaluated in string context, see L<Label se:strings>. ? x2 = 0; i = 2; Str(x, i) %1 = "x2" ? eval(%) %2 = 0 This function is mostly useless in library mode. Use the pair X<strtoGEN>C<strtoGEN>/X<GENtostr>C<GENtostr> to convert between C<GEN> and C<char*>. The latter returns a malloced string, which should be freed after usage. =head2 X<Strchr>StrchrC<(x)> converts C<x> to a string, translating each integer into a character. ? Strchr(97) %1 = "a" ? Vecsmall("hello world") %2 = Vecsmall([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]) ? Strchr(%) %3 = "hello world" =head2 X<Strexpand>StrexpandC<({x}*)> converts its argument list into a single character string (type C<t_STR>, the empty string if C<x> is omitted). Then performe X<environment expansion>environment expansion, see L<Label se:envir>. This feature can be used to read X<environment variable>environment variable values. ? Strexpand("$HOME/doc") %1 = "/home/pari/doc" The individual arguments are read in string context, see L<Label se:strings>. =head2 X<Strtex>StrtexC<({x}*)> translates its arguments to TeX format, and concatenates the results into a single character string (type C<t_STR>, the empty string if C<x> is omitted). The individual arguments are read in string context, see L<Label se:strings>. =head2 X<Vec>VecC<({x = []})> transforms the object C<x> into a row vector. The vector will be with one component only, except when C<x> is a vector or a quadratic form (in which case the resulting vector is simply the initial object considered as a row vector), a matrix (the vector of columns comprising the matrix is return), a character string (a vector of individual characters is returned), but more importantly when C<x> is a polynomial or a power series. In the case of a polynomial, the coefficients of the vector start with the leading coefficient of the polynomial, while for power series only the significant coefficients are taken into account, but this time by increasing order of degree. X<gtovec>The library syntax is B<gtovec>C<(x)>. =head2 X<Vecsmall>VecsmallC<({x = []})> transforms the object C<x> into a row vector of type C<t_VECSMALL>. This acts as C<Vec>, but only on a limited set of objects (the result must be representable as a vector of small integers). In particular, polynomials and power series are forbidden. If C<x> is a character string, a vector of individual characters in ASCII encoding is returned (X<Strchr>C<Strchr> yields back the character string). X<gtovecsmall>The library syntax is B<gtovecsmall>C<(x)>. =head2 X<binary>binaryC<(x)> outputs the vector of the binary digits of C<|x|>. Here C<x> can be an integer, a real number (in which case the result has two components, one for the integer part, one for the fractional part) or a vector/matrix. X<binaire>The library syntax is B<binaire>C<(x)>. =head2 X<bitand>bitandC<(x,y)> X<Label se:bitand> bitwise X<and>C<and> X<bitwise and>of two integers C<x> and C<y>, that is the integer S< >C<F<sum>_i (x_iS< >andS< >y_i) 2^i> Negative numbers behave C<2>-adically, i.e.S< >the result is the C<2>-adic limit of C<bitand>C<(x_n,y_n)>, where C<x_n> and C<y_n> are non-negative integers tending to C<x> and C<y> respectively. (The result is an ordinary integer, possibly negative.) ? bitand(5, 3) %1 = 1 ? bitand(-5, 3) %2 = 3 ? bitand(-5, -3) %3 = -7 X<gbitand>The library syntax is B<gbitand>C<(x,y)>. =head2 X<bitneg>bitnegC<(x,{n = -1})> X<bitwise negation>bitwise negation of an integer C<x>, truncated to C<n> bits, that is the integer S< >C<F<sum>_{i = 0}^{n-1} not(x_i) 2^i> The special case C<n = -1> means no truncation: an infinite sequence of leading C<1> is then represented as a negative number. See L<Label se:bitand> for the behaviour for negative arguments. X<gbitneg>The library syntax is B<gbitneg>C<(x)>. =head2 X<bitnegimply>bitnegimplyC<(x,y)> bitwise negated imply of two integers C<x> and C<y> (or C<not> C<(x ==E<gt> y)>), that is the integer S< >C<F<sum> (x_iS< >and not(y_i)) 2^i> See L<Label se:bitand> for the behaviour for negative arguments. X<gbitnegimply>The library syntax is B<gbitnegimply>C<(x,y)>. =head2 X<bitor>bitorC<(x,y)> X<bitwise inclusive or>bitwise (inclusive) X<or>C<or> of two integers C<x> and C<y>, that is the integer S< >C<F<sum> (x_iS< >orS< >y_i) 2^i> See L<Label se:bitand> for the behaviour for negative arguments. X<gbitor>The library syntax is B<gbitor>C<(x,y)>. =head2 X<bittest>bittestC<(x,n)> outputs the C<n^{th}> bit of C<|x|> starting from the right (i.e.S< >the coefficient of C<2^n> in the binary expansion of C<x>). The result is 0 or 1. To extract several bits at once as a vector, pass a vector for C<n>. X<bittest>The library syntax is B<bittest>C<(x,n)>, where C<n> and the result are C<long>s. =head2 X<bitxor>bitxorC<(x,y)> bitwise (exclusive) X<or>C<or> X<bitwise exclusive or>of two integers C<x> and C<y>, that is the integer S< >C<F<sum> (x_iS< >xorS< >y_i) 2^i> See L<Label se:bitand> for the behaviour for negative arguments. X<gbitxor>The library syntax is B<gbitxor>C<(x,y)>. =head2 X<ceil>ceilC<(x)> ceiling of C<x>. When C<x> is in B<I<R>>, the result is the smallest integer greater than or equal to C<x>. Applied to a rational function, C<ceil(x)> returns the euclidian quotient of the numerator by the denominator. X<gceil>The library syntax is B<gceil>C<(x)>. =head2 X<centerlift>centerliftC<(x,{v})> lifts an element C<x = a mod n> of C<B<I<Z>>/nB<I<Z>>> to C<a> in B<I<Z>>, and similarly lifts a polmod to a polynomial. This is the same as X<lift>C<lift> except that in the particular case of elements of C<B<I<Z>>/nB<I<Z>>>, the lift C<y> is such that C<-n/2 E<lt> y E<lt>= n/2>. If C<x> is of type fraction, complex, quadratic, polynomial, power series, rational function, vector or matrix, the lift is done for each coefficient. Reals are forbidden. X<centerlift0>The library syntax is B<centerlift0>C<(x,v)>, where C<v> is a C<long> and an omitted C<v> is coded as C<-1>. Also available is C< B<centerlift>(x)>X<centerlift> = C<centerlift0(x,-1)>. =head2 X<changevar>changevarC<(x,y)> creates a copy of the object C<x> where its variables are modified according to the permutation specified by the vector C<y>. For example, assume that the variables have been introduced in the order C<x>, C<a>, C<b>, C<c>. Then, if C<y> is the vector C<[x,c,a,b]>, the variable C<a> will be replaced by C<c>, C<b> by C<a>, and C<c> by C<b>, C<x> being unchanged. Note that the permutation must be completely specified, e.g.S< >C<[c,a,b]> would not work, since this would replace C<x> by C<c>, and leave C<a> and C<b> unchanged (as well as C<c> which is the fourth variable of the initial list). In particular, the new variable names must be distinct. X<changevar>The library syntax is B<changevar>C<(x,y)>. =head2 components of a PARI object There are essentially three ways to extract the X<components>components from a PARI object. The first and most general, is the function C< B<component>(x,n)>X<component> which extracts the C<n^{th}>-component of C<x>. This is to be understood as follows: every PARI type has one or two initial X<code words>code words. The components are counted, starting at 1, after these code words. In particular if C<x> is a vector, this is indeed the C<n^{th}>-component of C<x>, if C<x> is a matrix, the C<n^{th}> column, if C<x> is a polynomial, the C<n^{th}> coefficient (i.e.S< >of degree C<n-1>), and for power series, the C<n^{th}> significant coefficient. The use of the function C<component> implies the knowledge of the structure of the different PARI types, which can be recalled by typing C<\t> under C<gp>. X<compo>The library syntax is B<compo>C<(x,n)>, where C<n> is a C<long>. The two other methods are more natural but more restricted. The function C< B<polcoeff>(x,n)>X<polcoeff> gives the coefficient of degree C<n> of the polynomial or power series C<x>, with respect to the main variable of C<x> (to check variable ordering, or to change it, use the function X<reorder>C<reorder>, see L<Label se:reorder>). In particular if C<n> is less than the valuation of C<x> or in the case of a polynomial, greater than the degree, the result is zero (contrary to C<compo> which would send an error message). If C<x> is a power series and C<n> is greater than the largest significant degree, then an error message is issued. For greater flexibility, vector or matrix types are also accepted for C<x>, and the meaning is then identical with that of C<compo>. Finally note that a scalar type is considered by C<polcoeff> as a polynomial of degree zero. X<truecoeff>The library syntax is B<truecoeff>C<(x,n)>. The third method is specific to vectors or matrices in GP. If C<x> is a (row or column) vector, then X<x[n]>C<x[n]> represents the C<n^{th}> component of C<x>, i.e.S< >C<compo(x,n)>. It is more natural and shorter to write. If C<x> is a matrix, X<x[m,n]>C<x[m,n]> represents the coefficient of row C<m> and column C<n> of the matrix, X<x[m,]>C<x[m,]> represents the C<m^{th}> \emph{row} of C<x>, and X<x[,n]>C<x[,n]> represents the C<n^{th}> \emph{column} of C<x>. Finally note that in library mode, the macros X<gcoeff>B<gcoeff> and X<gmael>B<gmael> are available as direct accessors to a C<GEN component>. See Chapter 4 for details. =head2 X<conj>conjC<(x)> conjugate of C<x>. The meaning of this is clear, except that for real quadratic numbers, it means conjugation in the real quadratic field. This function has no effect on integers, reals, intmods, fractions or C<p>-adics. The only forbidden type is polmod (see C<conjvec> for this). X<gconj>The library syntax is B<gconj>C<(x)>. =head2 X<conjvec>conjvecC<(x)> conjugate vector representation of C<x>. If C<x> is a polmod, equal to C<Mod>C<(a,q)>, this gives a vector of length C<degree(q)> containing the complex embeddings of the polmod if C<q> has integral or rational coefficients, and the conjugates of the polmod if C<q> has some intmod coefficients. The order is the same as that of the C<polroots> functions. If C<x> is an integer or a rational number, the result isS< >C<x>. If C<x> is a (row or column) vector, the result is a matrix whose columns are the conjugate vectors of the individual elements of C<x>. X<conjvec>The library syntax is B<conjvec>C<(x,I<prec>)>. =head2 X<denominator>denominatorC<(x)> denominator of C<x>. The meaning of this is clear when C<x> is a rational number or function. If C<x> is an integer or a polynomial, it is treated as a rational number of function, respectively, and the result is equal to C<1>. For polynomials, you probably want to use denominator( content(x) ) instead. As for modular objects, C<t_INTMOD> and C<t_PADIC> have denominator C<1>, and the denominator of a C<t_POLMOD> is the denominator of its (minimal degree) polynomial representative. If C<x> is a recursive structure, for instance a vector or matrix, the lcm of the denominators of its components (a common denominator) is computed. This also applies for C<t_COMPLEX>s and C<t_QUAD>s. B<Warning:> multivariate objects are created according to variable priorities, with possibly surprising side effects (C<x/y> is a polynomial, but C<y/x> is a rational function). See L<Label se:priority>. X<denom>The library syntax is B<denom>C<(x)>. =head2 X<floor>floorC<(x)> floor of C<x>. When C<x> is in B<I<R>>, the result is the largest integer smaller than or equal to C<x>. Applied to a rational function, C<floor(x)> returns the euclidian quotient of the numerator by the denominator. X<gfloor>The library syntax is B<gfloor>C<(x)>. =head2 X<frac>fracC<(x)> fractional part of C<x>. Identical to C<x-floor(x)>. If C<x> is real, the result is in C<[0,1[>. X<gfrac>The library syntax is B<gfrac>C<(x)>. =head2 X<imag>imagC<(x)> imaginary part of C<x>. When C<x> is a quadratic number, this is the coefficient of C<F<omega>> in the ``canonical'' integral basis C<(1,F<omega>)>. X<gimag>The library syntax is B<gimag>C<(x)>. This returns a copy of the imaginary part. The internal routine X<imag_i>C<imag_i> is faster, since it returns the pointer and skips the copy. =head2 X<length>lengthC<(x)> number of non-code words in C<x> really used (i.e.S< >the effective length minus 2 for integers and polynomials). In particular, the degree of a polynomial is equal to its length minus 1. If C<x> has type C<t_STR>, output number of letters. X<glength>The library syntax is B<glength>C<(x)> and the result is a C long. =head2 X<lift>liftC<(x,{v})> lifts an element C<x = a mod n> of C<B<I<Z>>/nB<I<Z>>> to C<a> in B<I<Z>>, and similarly lifts a polmod to a polynomial if C<v> is omitted. Otherwise, lifts only polmods whose modulus has main variable C<v> (if C<v> does not occur in C<x>, lifts only intmods). If C<x> is of recursive (non modular) type, the lift is done coefficientwise. For C<p>-adics, this routine acts as X<truncate>C<truncate>. It is not allowed to have C<x> of type C<t_REAL>. ? lift(Mod(5,3)) %1 = 2 ? lift(3 + O(3^9)) %2 = 3 ? lift(Mod(x,x^2+1)) %3 = x ? lift(x * Mod(1,3) + Mod(2,3)) %4 = x + 2 ? lift(x * Mod(y,y^2+1) + Mod(2,3)) %5 = y*x + Mod(2, 3) \\ do you understand this one ? ? lift(x * Mod(y,y^2+1) + Mod(2,3), x) %6 = Mod(y, y^2+1) * x + Mod(2, y^2+1) X<lift0>The library syntax is B<lift0>C<(x,v)>, where C<v> is a C<long> and an omitted C<v> is coded as C<-1>. Also available is C< B<lift>(x)>X<lift> = C<lift0(x,-1)>. =head2 X<norm>normC<(x)> algebraic norm of C<x>, i.e.S< >the product of C<x> with its conjugate (no square roots are taken), or conjugates for polmods. For vectors and matrices, the norm is taken componentwise and hence is not the C<L^2>-norm (see C<norml2>). Note that the norm of an element of B<I<R>> is its square, so as to be compatible with the complex norm. X<gnorm>The library syntax is B<gnorm>C<(x)>. =head2 X<norml2>norml2C<(x)> square of the C<L^2>-norm of C<x>. More precisely, if C<x> is a scalar, C<norml2(x)> is defined to be C<x * conj(x)>. If C<x> is a (row or column) vector or a matrix, C<norml2(x)> is defined recursively as C<F<sum>_i norml2(x_i)>, where C<(x_i)> run through the components of C<x>. In particular, this yields the usual C<F<sum> |x_i|^2> (resp.S< >C<F<sum> |x_{i,j}|^2>) if C<x> is a vector (resp.S< >matrix) with complex components. ? norml2( [ 1, 2, 3 ] ) \\ vector %1 = 14 ? norml2( [ 1, 2; 3, 4] ) \\ matrix %1 = 30 ? norml2( I + x ) %3 = x^2 + 1 ? norml2( [ [1,2], [3,4], 5, 6 ] ) \\ recursively defined %4 = 91 X<gnorml2>The library syntax is B<gnorml2>C<(x)>. =head2 X<numerator>numeratorC<(x)> numerator of C<x>. The meaning of this is clear when C<x> is a rational number or function. If C<x> is an integer or a polynomial, it is treated as a rational number of function, respectively, and the result is C<x> itself. For polynomials, you probably want to use numerator( content(x) ) instead. In other cases, C<numerator(x)> is defined to be C<denominator(x)*x>. This is the case when C<x> is a vector or a matrix, but also for C<t_COMPLEX> or C<t_QUAD>. In particular since a C<t_PADIC> or C<t_INTMOD> has denominator C<1>, its numerator is itself. B<Warning:> multivariate objects are created according to variable priorities, with possibly surprising side effects (C<x/y> is a polynomial, but C<y/x> is a rational function). See L<Label se:priority>. X<numer>The library syntax is B<numer>C<(x)>. =head2 X<numtoperm>numtopermC<(n,k)> generates the C<k>-th permutation (as a row vector of length C<n>) of the numbers C<1> to C<n>. The number C<k> is taken modulo C<n!>, i.e.S< >inverse function of X<permtonum>C<permtonum>. X<numtoperm>The library syntax is B<numtoperm>C<(n,k)>, where C<n> is a C<long>. =head2 X<padicprec>padicprecC<(x,p)> absolute C<p>-adic precision of the object C<x>. This is the minimum precision of the components of C<x>. The result is C<VERYBIGINT> (C<2^{31}-1> for 32-bit machines or C<2^{63}-1> for 64-bit machines) if C<x> is an exact object. X<padicprec>The library syntax is B<padicprec>C<(x,p)> and the result is a C<long> integer. =head2 X<permtonum>permtonumC<(x)> given a permutation C<x> on C<n> elements, gives the number C<k> such that C<x = numtoperm(n,k)>, i.e.S< >inverse function of X<numtoperm>C<numtoperm>. X<permtonum>The library syntax is B<permtonum>C<(x)>. =head2 X<precision>precisionC<(x,{n})> gives the precision in decimal digits of the PARI object C<x>. If C<x> is an exact object, the largest single precision integer is returned. If C<n> is not omitted, creates a new object equal to C<x> with a new precision C<n>. This is to be understood as follows: For exact types, no change. For C<x> a vector or a matrix, the operation is done componentwise. For real C<x>, C<n> is the number of desired significant \emph{decimal} digits. If C<n> is smaller than the precision of C<x>, C<x> is truncated, otherwise C<x> is extended with zeros. For C<x> a C<p>-adic or a power series, C<n> is the desired number of significant C<p>-adic or C<X>-adic digits, where C<X> is the main variable of C<x>. Note that the function C<precision> never changes the type of the result. In particular it is not possible to use it to obtain a polynomial from a power series. For that, see C<truncate>. X<precision0>The library syntax is B<precision0>C<(x,n)>, where C<n> is a C<long>. Also available are C< B<ggprecision>(x)>X<ggprecision> (result is a C<GEN>) and C< B<gprec>(x,n)>X<gprec>, where C<n> is a C<long>. =head2 X<random>randomC<({N = 2^{31}})> returns a random integer between C<0> and C<N-1>. C<N> is an integer, which can be arbitrary large. This is an internal PARI function and does not depend on the system's random number generator. The resulting integer is obtained by means of linear congruences and will not be well distributed in arithmetic progressions. The random seed may be obtained via X<getrand>C<getrand>, and reset using X<setrand>C<setrand>. Note that C<random(2^31)> is \emph{not} equivalent to C<random()>, although both return an integer between C<0> and C<2^{31}-1>. In fact, calling C<random> with an argument generates a number of random words (32bit or 64bit depending on the architecture), rescaled to the desired interval. The default uses directly a 31-bit generator. B<Important technical note:> the implementation of this function is incorrect unless C<N> is a power of C<2> (integers less than the bound are not equally likely, some may not even occur). It is kept for backward compatibility only, and has been rewritten from scratch in the 2.4.x unstable series. Use the following script for a correct version: RANDOM(N) = { local(n, L); L = 1; while (L < N, L <<= 1;); /* L/2 < N <= L, L power of 2 */ until(n < N, n = random(L)); n } X<genrand>The library syntax is B<genrand>C<(N)>. Also available are X<pari_rand>C<pari_rand>C<()> which returns a random C<unsigned long> (32bit or 64bit depending on the architecture), and X<pari_rand31>C<pari_rand31>C<()> which returns a 31bit C<long> integer. =head2 X<real>realC<(x)> real part of C<x>. In the case where C<x> is a quadratic number, this is the coefficient of C<1> in the ``canonical'' integral basis C<(1,F<omega>)>. X<greal>The library syntax is B<greal>C<(x)>. This returns a copy of the real part. The internal routine X<real_i>C<real_i> is faster, since it returns the pointer and skips the copy. =head2 X<round>roundC<(x,{&e})> If C<x> is in B<I<R>>, rounds C<x> to the nearest integer and sets C<e> to the number of error bits, that is the binary exponent of the difference between the original and the rounded value (the ``fractional part''). If the exponent of C<x> is too large compared to its precision (i.e.S< >C<e E<gt> 0>), the result is undefined and an error occurs if C<e> was not given. B<Important remark:> note that, contrary to the other truncation functions, this function operates on every coefficient at every level of a PARI object. For example S< >C<truncate((2.4*X^2-1.7)/(X)) = 2.4*X,> whereas S< >C<round((2.4*X^2-1.7)/(X)) = (2*X^2-2)/(X).> An important use of C<round> is to get exact results after a long approximate computation, when theory tells you that the coefficients must be integers. X<grndtoi>The library syntax is B<grndtoi>C<(x,&e)>, where C<e> is a C<long> integer. Also available is C< B<ground>(x)>X<ground>. =head2 X<simplify>simplifyC<(x)> this function simplifies C<x> as much as it can. Specifically, a complex or quadratic number whose imaginary part is an exact 0 (i.e.S< >not an approximate one as a C<O(3)> or C<0.E-28>) is converted to its real part, and a polynomial of degree C<0> is converted to its constant term. Simplifications occur recursively. This function is especially useful before using arithmetic functions, which expect integer arguments: ? x = 1 + y - y %1 = 1 ? divisors(x) *** divisors: not an integer argument in an arithmetic function ? type(x) %2 = "t_POL" ? type(simplify(x)) %3 = "t_INT" Note that GP results are simplified as above before they are stored in the history. (Unless you disable automatic simplification with C<\y>, that is.) In particular ? type(%1) %4 = "t_INT" X<simplify>The library syntax is B<simplify>C<(x)>. =head2 X<sizebyte>sizebyteC<(x)> outputs the total number of bytes occupied by the tree representing the PARI object C<x>. X<taille2>The library syntax is B<taille2>C<(x)> which returns a C<long>; C< B<taille>(x)>X<taille> returns the number of \emph{words} instead. =head2 X<sizedigit>sizedigitC<(x)> outputs a quick bound for the number of decimal digits of (the components of) C<x>, off by at most C<1>. If you want the exact value, you can use C<#Str(x)>, which is slower. X<sizedigit>The library syntax is B<sizedigit>C<(x)> which returns a C<long>. =head2 X<truncate>truncateC<(x,{&e})> truncates C<x> and sets C<e> to the number of error bits. When C<x> is in B<I<R>>, this means that the part after the decimal point is chopped away, C<e> is the binary exponent of the difference between the original and the truncated value (the ``fractional part''). If the exponent of C<x> is too large compared to its precision (i.e.S< >C<e E<gt> 0>), the result is undefined and an error occurs if C<e> was not given. The function applies componentwise on vector / matrices; C<e> is then the maximal number of error bits. If C<x> is a rational function, the result is the ``integer part'' (Euclidean quotient of numerator by denominator) and C<e> is not set. Note a very special use of C<truncate>: when applied to a power series, it transforms it into a polynomial or a rational function with denominator a power of C<X>, by chopping away the C<O(X^k)>. Similarly, when applied to a C<p>-adic number, it transforms it into an integer or a rational number by chopping away the C<O(p^k)>. X<gcvtoi>The library syntax is B<gcvtoi>C<(x,&e)>, where C<e> is a C<long> integer. Also available is C< B<gtrunc>(x)>X<gtrunc>. =head2 X<valuation>valuationC<(x,p)> X<Label se:valuation> computes the highest exponent of C<p> dividing C<x>. If C<p> is of type integer, C<x> must be an integer, an intmod whose modulus is divisible by C<p>, a fraction, a C<q>-adic number with C<q = p>, or a polynomial or power series in which case the valuation is the minimum of the valuation of the coefficients. If C<p> is of type polynomial, C<x> must be of type polynomial or rational function, and also a power series if C<x> is a monomial. Finally, the valuation of a vector, complex or quadratic number is the minimum of the component valuations. If C<x = 0>, the result is C<VERYBIGINT> (C<2^{31}-1> for 32-bit machines or C<2^{63}-1> for 64-bit machines) if C<x> is an exact object. If C<x> is a C<p>-adic numbers or power series, the result is the exponent of the zero. Any other type combinations gives an error. X<ggval>The library syntax is B<ggval>C<(x,p)>, and the result is a C<long>. =head2 X<variable>variableC<(x)> gives the main variable of the object C<x>, and C<p> if C<x> is a C<p>-adic number. Gives an error if C<x> has no variable associated to it. Note that this function is useful only in GP, since in library mode the function C<gvar> is more appropriate. X<gpolvar>The library syntax is B<gpolvar>C<(x)>. However, in library mode, this function should not be used. Instead, test whether C<x> is a C<p>-adic (type C<t_PADIC>), in which case C<p> is in C<x[2]>, or call the function C< B<gvar>(x)>X<gvar> which returns the variable \emph{number} of C<x> if it exists, C<BIGINT> otherwise. =head1 Transcendental functions X<Label se:trans> As a general rule, which of course in some cases may have exceptions, transcendental functions operate in the following way: \item If the argument is either an integer, a real, a rational, a complex or a quadratic number, it is, if necessary, first converted to a real (or complex) number using the current X<precision>precision held in the default C<realprecision>. Note that only exact arguments are converted, while inexact arguments such as reals are not. In GP this is transparent to the user, but when programming in library mode, care must be taken to supply a meaningful parameter I<prec> as the last argument of the function if the first argument is an exact object. This parameter is ignored if the argument is inexact. Note that in library mode the precision argument I<prec> is a word count including codewords, i.e.S< >represents the length in words of a real number, while under C<gp> the precision (which is changed by the metacommand C<\p> or using C<default(realprecision,...)>) is the number of significant decimal digits. Note that some accuracies attainable on 32-bit machines cannot be attained on 64-bit machines for parity reasons. For example the default C<gp> accuracy is 28 decimal digits on 32-bit machines, corresponding to I<prec> having the value 5, but this cannot be attained on 64-bit machines. After possible conversion, the function is computed. Note that even if the argument is real, the result may be complex (e.g.S< >C<acos(2.0)> or C<acosh(0.0)>). Note also that the principal branch is always chosen. \item If the argument is an intmod or a C<p>-adic, at present only a few functions like C<sqrt> (square root), C<sqr> (square), C<log>, C<exp>, powering, C<teichmuller> (TeichmE<uuml>ller character) and C<agm> (arithmetic-geometric mean) are implemented. Note that in the case of a C<2>-adic number, C<sqr(x)> may not be identical to C<x*x>: for example if C<x = 1+O(2^5)> and C<y = 1+O(2^5)> then C<x*y = 1+O(2^5)> while C<sqr(x) = 1+O(2^6)>. Here, C<x * x> yields the same result as C<sqr(x)> since the two operands are known to be \emph{identical}. The same statement holds true for C<p>-adics raised to the power C<n>, where C<v_p(n) E<gt> 0>. B<Remark:> note that if we wanted to be strictly consistent with the PARI philosophy, we should have C<x*y = (4 mod 8)> and C<sqr(x) = (4 mod 32)> when both C<x> and C<y> are congruent to C<2> modulo C<4>. However, since intmod is an exact object, PARI assumes that the modulus must not change, and the result is hence C<(0 mod 4)> in both cases. On the other hand, C<p>-adics are not exact objects, hence are treated differently. \item If the argument is a polynomial, power series or rational function, it is, if necessary, first converted to a power series using the current precision held in the variable X<precdl>C<precdl>. Under C<gp> this again is transparent to the user. When programming in library mode, however, the global variable C<precdl> must be set before calling the function if the argument has an exact type (i.e.S< >not a power series). Here C<precdl> is not an argument of the function, but a global variable. Then the Taylor series expansion of the function around C<X = 0> (where C<X> is the main variable) is computed to a number of terms depending on the number of terms of the argument and the function being computed. \item 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, which are not implemented in the present version B<2.2.0>, will have a different name if they are implemented some day. =head2 ^ If C<y> is not of type integer, C<x^y> has the same effect as C<exp(y*log(x))>. It can be applied to C<p>-adic numbers as well as to the more usual types.X<powering> X<gpow>The library syntax is B<gpow>C<(x,y,I<prec>)>. =head2 Euler Euler's constant C<F<gamma> = 0.57721...>. Note that C<Euler> is one of the few special reserved names which cannot be used for variables (the others are C<I> and C<Pi>, as well as all function names). X<Label se:euler> X<mpeuler>The library syntax is B<mpeuler>C<(I<prec>)> where C<I<prec>> \emph{must} be given. Note that this creates C<F<gamma>> on the PARI stack, but a copy is also created on the heap for quicker computations next time the function is called. =head2 I the complex number C< F<sqrt> {-1}>. The library syntax is the global variable C<gi> (of type C<GEN>). =head2 Pi the constant C<F<Pi>> (C<3.14159...>).X<Label se:pi> X<mppi>The library syntax is B<mppi>C<(I<prec>)> where C<I<prec>> \emph{must} be given. Note that this creates C<F<Pi>> on the PARI stack, but a copy is also created on the heap for quicker computations next time the function is called. =head2 X<abs>absC<(x)> absolute value of C<x> (modulus if C<x> is complex). Rational functions are not allowed. Contrary to most transcendental functions, an exact argument is \emph{not} converted to a real number before applying C<abs> and an exact result is returned if possible. ? abs(-1) %1 = 1 ? abs(3/7 + 4/7*I) %2 = 5/7 ? abs(1 + I) %3 = 1.414213562373095048801688724 If C<x> is a polynomial, returns C<-x> if the leading coefficient is real and negative else returns C<x>. For a power series, the constant coefficient is considered instead. X<gabs>The library syntax is B<gabs>C<(x,I<prec>)>. =head2 X<acos>acosC<(x)> principal branch of C<cos^{-1}(x)>, i.e.S< >such that C<Re(acos(x)) belongs to [0,F<Pi>]>. If C<x belongs to B<I<R>>> and C<|x| E<gt> 1>, then C<acos(x)> is complex. X<gacos>The library syntax is B<gacos>C<(x,I<prec>)>. =head2 X<acosh>acoshC<(x)> principal branch of C<cosh^{-1}(x)>, i.e.S< >such that C<Im(acosh(x)) belongs to [0,F<Pi>]>. If C<x belongs to B<I<R>>> and C<x E<lt> 1>, then C<acosh(x)> is complex. X<gach>The library syntax is B<gach>C<(x,I<prec>)>. =head2 X<agm>agmC<(x,y)> arithmetic-geometric mean of C<x> and C<y>. In the case of complex or negative numbers, the principal square root is always chosen. C<p>-adic or power series arguments are also allowed. Note that a C<p>-adic agm exists only if C<x/y> is congruent to 1 modulo C<p> (modulo 16 for C<p = 2>). C<x> and C<y> cannot both be vectors or matrices. X<agm>The library syntax is B<agm>C<(x,y,I<prec>)>. =head2 X<arg>argC<(x)> argument of the complex number C<x>, such that C<-F<Pi> E<lt> arg(x) E<lt>= F<Pi>>. X<garg>The library syntax is B<garg>C<(x,I<prec>)>. =head2 X<asin>asinC<(x)> principal branch of C<sin^{-1}(x)>, i.e.S< >such that C<Re(asin(x)) belongs to [-F<Pi>/2,F<Pi>/2]>. If C<x belongs to B<I<R>>> and C<|x| E<gt> 1> then C<asin(x)> is complex. X<gasin>The library syntax is B<gasin>C<(x,I<prec>)>. =head2 X<asinh>asinhC<(x)> principal branch of C<sinh^{-1}(x)>, i.e.S< >such that C<Im(asinh(x)) belongs to [-F<Pi>/2,F<Pi>/2]>. X<gash>The library syntax is B<gash>C<(x,I<prec>)>. =head2 X<atan>atanC<(x)> principal branch of C<tan^{-1}(x)>, i.e.S< >such that C<Re(atan(x)) belongs to ]-F<Pi>/2,F<Pi>/2[>. X<gatan>The library syntax is B<gatan>C<(x,I<prec>)>. =head2 X<atanh>atanhC<(x)> principal branch of C<tanh^{-1}(x)>, i.e.S< >such that C<Im(atanh(x)) belongs to ]-F<Pi>/2,F<Pi>/2]>. If C<x belongs to B<I<R>>> and C<|x| E<gt> 1> then C<atanh(x)> is complex. X<gath>The library syntax is B<gath>C<(x,I<prec>)>. =head2 X<bernfrac>bernfracC<(x)> Bernoulli numberX<Bernoulli numbers> C<B_x>, where C<B_0 = 1>, C<B_1 = -1/2>, C<B_2 = 1/6>,..., expressed as a rational number. The argument C<x> should be of type integer. X<bernfrac>The library syntax is B<bernfrac>C<(x)>. =head2 X<bernreal>bernrealC<(x)> Bernoulli numberX<Bernoulli numbers> C<B_x>, as C<bernfrac>, but C<B_x> is returned as a real number (with the current precision). X<bernreal>The library syntax is B<bernreal>C<(x,I<prec>)>. =head2 X<bernvec>bernvecC<(x)> creates a vector containing, as rational numbers, the X<Bernoulli numbers>Bernoulli numbers C<B_0>, C<B_2>,..., C<B_{2x}>. This routine is obsolete. Use C<bernfrac> instead each time you need a Bernoulli number in exact form. B<Note:> this routine is implemented using repeated independent calls to C<bernfrac>, which is faster than the standard recursion in exact arithmetic. It is only kept for backward compatibility: it is not faster than individual calls to C<bernfrac>, its output uses a lot of memory space, and coping with the index shift is awkward. X<bernvec>The library syntax is B<bernvec>C<(x)>. =head2 X<besselh1>besselh1C<(I<nu>,x)> C<H^1>-Bessel function of index I<nu> and argument C<x>. X<hbessel1>The library syntax is B<hbessel1>C<(I<nu>,x,I<prec>)>. =head2 X<besselh2>besselh2C<(I<nu>,x)> C<H^2>-Bessel function of index I<nu> and argument C<x>. X<hbessel2>The library syntax is B<hbessel2>C<(I<nu>,x,I<prec>)>. =head2 X<besseli>besseliC<(I<nu>,x)> C<I>-Bessel function of index I<nu> and argument C<x>. If C<x> converts to a power series, the initial factor C<(x/2)^F<nu>/F<Gamma>(F<nu>+1)> is omitted (since it cannot be represented in PARI when C<F<nu>> is not integral). X<ibessel>The library syntax is B<ibessel>C<(I<nu>,x,I<prec>)>. =head2 X<besselj>besseljC<(I<nu>,x)> C<J>-Bessel function of index I<nu> and argument C<x>. If C<x> converts to a power series, the initial factor C<(x/2)^F<nu>/F<Gamma>(F<nu>+1)> is omitted (since it cannot be represented in PARI when C<F<nu>> is not integral). X<jbessel>The library syntax is B<jbessel>C<(I<nu>,x,I<prec>)>. =head2 X<besseljh>besseljhC<(n,x)> C<J>-Bessel function of half integral index. More precisely, C<besseljh(n,x)> computes C<J_{n+1/2}(x)> where C<n> must be of type integer, and C<x> is any element of B<I<C>>. In the present version B<2.2.0>, this function is not very accurate when C<x> is small. X<jbesselh>The library syntax is B<jbesselh>C<(n,x,I<prec>)>. =head2 X<besselk>besselkC<(I<nu>,x,{I<flag> = 0})> C<K>-Bessel function of index I<nu> (which can be complex) and argument C<x>. Only real and positive arguments C<x> are allowed in the present version B<2.2.0>. If C<I<flag>> is equal to 1, uses another implementation of this function which is faster when C<x\gg 1>. X<kbessel>The library syntax is B<kbessel>C<(I<nu>,x,I<prec>)> and C< B<kbessel2>(I<nu>,x,I<prec>)>X<kbessel2> respectively. =head2 X<besseln>besselnC<(I<nu>,x)> C<N>-Bessel function of index I<nu> and argument C<x>. X<nbessel>The library syntax is B<nbessel>C<(I<nu>,x,I<prec>)>. =head2 X<cos>cosC<(x)> cosine of C<x>. X<gcos>The library syntax is B<gcos>C<(x,I<prec>)>. =head2 X<cosh>coshC<(x)> hyperbolic cosine of C<x>. X<gch>The library syntax is B<gch>C<(x,I<prec>)>. =head2 X<cotan>cotanC<(x)> cotangent of C<x>. X<gcotan>The library syntax is B<gcotan>C<(x,I<prec>)>. =head2 X<dilog>dilogC<(x)> principal branch of the dilogarithm of C<x>, i.e.S< >analytic continuation of the power series C< F<log> _2(x) = F<sum>_{n E<gt>= 1}x^n/n^2>. X<dilog>The library syntax is B<dilog>C<(x,I<prec>)>. =head2 X<eint1>eint1C<(x,{n})> exponential integral C<F<int>_x^ oo (e^{-t})/(t)dt> (C<x belongs to B<I<R>>>) If C<n> is present, outputs the C<n>-dimensional vector C<[eint1(x),...,eint1(nx)]> (C<x E<gt>= 0>). This is faster than repeatedly calling C<eint1(i * x)>. X<veceint1>The library syntax is B<veceint1>C<(x,n,prec)>. Also available is C< B<eint1>(x,prec)>X<eint1>. =head2 X<erfc>erfcC<(x)> complementary error function C<(2/ F<sqrt> F<Pi>)F<int>_x^ oo e^{-t^2}dt> (C<x belongs to B<I<R>>>). X<erfc>The library syntax is B<erfc>C<(x,I<prec>)>. =head2 X<eta>etaC<(x,{I<flag> = 0})> X<Dedekind>Dedekind's C<F<eta>> function, without the C<q^{1/24}>. This means the following: if C<x> is a complex number with positive imaginary part, the result is C<F<prod>_{n = 1}^ oo (1-q^n)>, where C<q = e^{2iF<Pi> x}>. If C<x> is a power series (or can be converted to a power series) with positive valuation, the result is C<F<prod>_{n = 1}^ oo (1-x^n)>. If C<I<flag> = 1> and C<x> can be converted to a complex number (i.e.S< >is not a power series), computes the true C<F<eta>> function, including the leading C<q^{1/24}>. X<eta>The library syntax is B<eta>C<(x,I<prec>)>. =head2 X<exp>expC<(x)> exponential of C<x>. C<p>-adic arguments with positive valuation are accepted. X<gexp>The library syntax is B<gexp>C<(x,I<prec>)>. =head2 X<gammah>gammahC<(x)> gamma function evaluated at the argument C<x+1/2>. X<ggamd>The library syntax is B<ggamd>C<(x,I<prec>)>. =head2 X<gamma>gammaC<(x)> gamma function of C<x>. X<ggamma>The library syntax is B<ggamma>C<(x,I<prec>)>. =head2 X<hyperu>hyperuC<(a,b,x)> C<U>-confluent hypergeometric function with parameters C<a> and C<b>. The parameters C<a> and C<b> can be complex but the present implementation requires C<x> to be positive. X<hyperu>The library syntax is B<hyperu>C<(a,b,x,I<prec>)>. =head2 X<incgam>incgamC<(s,x,{y})> incomplete gamma function. The argument C<x> and C<s> are complex numbers (C<x> must be a positive real number if C<s = 0>). The result returned is C<F<int>_x^ oo e^{-t}t^{s-1}dt>. When C<y> is given, assume (of course without checking!) that C<y = F<Gamma>(s)>. For small C<x>, this will speed up the computation. X<incgam>The library syntax is B<incgam>C<(s,x,I<prec>)> and C< B<incgam0>(s,x,y,prec)>X<incgam0>, respectively (an omitted C<y> is coded as C<NULL>). =head2 X<incgamc>incgamcC<(s,x)> complementary incomplete gamma function. The arguments C<x> and C<s> are complex numbers such that C<s> is not a pole of C<F<Gamma>> and C<|x|/(|s|+1)> is not much larger than 1 (otherwise the convergence is very slow). The result returned is C<F<int>_0^x e^{-t}t^{s-1}dt>. X<incgamc>The library syntax is B<incgamc>C<(s,x,I<prec>)>. =head2 X<log>logC<(x)> principal branch of the natural logarithm of C<x>, i.e.S< >such that C<Im(log(x)) belongs to ]-F<Pi>,F<Pi>]>. The result is complex (with imaginary part equal to C<F<Pi>>) if C<x belongs to B<I<R>>> and C<x E<lt> 0>. In general, the algorithm uses the formula S< >C< F<log> (x) ~ (F<Pi>)/(2agm(1, 4/s)) - m F<log> 2, > if C<s = x 2^m> is large enough. (The result is exact to C<B> bits provided C<s E<gt> 2^{B/2}>.) At low accuracies, the series expansion near C<1> is used. C<p>-adic arguments are also accepted for C<x>, with the convention that C< F<log> (p) = 0>. Hence in particular C< F<exp> ( F<log> (x))/x> is not in general equal to 1 but to a C<(p-1)>-th root of unity (or C<F<+->1> if C<p = 2>) times a power of C<p>. X<glog>The library syntax is B<glog>C<(x,I<prec>)>. =head2 X<lngamma>lngammaC<(x)> principal branch of the logarithm of the gamma function of C<x>. This function is analytic on the complex plane with non-positive integers removed. Can have much larger arguments than C<gamma> itself. The C<p>-adic C<lngamma> function is not implemented. X<glngamma>The library syntax is B<glngamma>C<(x,I<prec>)>. =head2 X<polylog>polylogC<(m,x,{I<flag> = 0})> one of the different polylogarithms, depending on I<flag>: If C<I<flag> = 0> or is omitted: C<m^th> polylogarithm of C<x>, i.e.S< >analytic continuation of the power series C<Li_m(x) = F<sum>_{n E<gt>= 1}x^n/n^m> (C<x E<lt> 1>). Uses the functional equation linking the values at C<x> and C<1/x> to restrict to the case C<|x| E<lt>= 1>, then the power series when C<|x|^2 E<lt>= 1/2>, and the power series expansion in C< F<log> (x)> otherwise. Using C<I<flag>>, computes a modified C<m^th> polylogarithm of C<x>. We use Zagier's notations; let C< F<Re> _m> denotes C< F<Re> > or C< F<Im> > depending whether C<m> is odd or even: If C<I<flag> = 1>: compute C<~ D_m(x)>, defined for C<|x| E<lt>= 1> by S< >C< F<Re> _m(F<sum>_{k = 0}^{m-1} ((- F<log> |x|)^k)/(k!)Li_{m-k}(x) +((- F<log> |x|)^{m-1})/(m!) F<log> |1-x|).> If C<I<flag> = 2>: compute C<D_m(x)>, defined for C<|x| E<lt>= 1> by S< >C< F<Re> _m(F<sum>_{k = 0}^{m-1}((- F<log> |x|)^k)/(k!)Li_{m-k}(x) -(1)/(2)((- F<log> |x|)^m)/(m!)).> If C<I<flag> = 3>: compute C<P_m(x)>, defined for C<|x| E<lt>= 1> by S< >C< F<Re> _m(F<sum>_{k = 0}^{m-1}(2^kB_k)/(k!)( F<log> |x|)^kLi_{m-k}(x) -(2^{m-1}B_m)/(m!)( F<log> |x|)^m).> These three functions satisfy the functional equation C<f_m(1/x) = (-1)^{m-1}f_m(x)>. X<polylog0>The library syntax is B<polylog0>C<(m,x,I<flag>,I<prec>)>. =head2 X<psi>psiC<(x)> the C<F<psi>>-function of C<x>, i.e.S< >the logarithmic derivative C<F<Gamma>'(x)/F<Gamma>(x)>. X<gpsi>The library syntax is B<gpsi>C<(x,I<prec>)>. =head2 X<sin>sinC<(x)> sine of C<x>. X<gsin>The library syntax is B<gsin>C<(x,I<prec>)>. =head2 X<sinh>sinhC<(x)> hyperbolic sine of C<x>. X<gsh>The library syntax is B<gsh>C<(x,I<prec>)>. =head2 X<sqr>sqrC<(x)> square of C<x>. This operation is not completely straightforward, i.e.S< >identical to C<x * x>, since it can usually be computed more efficiently (roughly one-half of the elementary multiplications can be saved). Also, squaring a C<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 \emph{identical}, e.g.S< >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 C<%2> and C<%3> above). X<gsqr>The library syntax is B<gsqr>C<(x)>. =head2 X<sqrt>sqrtC<(x)> principal branch of the square root of C<x>, i.e.S< >such that C<Arg(sqrt(x)) belongs to ]-F<Pi>/2, F<Pi>/2]>, or in other words such that C< F<Re> (sqrt(x)) E<gt> 0> or C< F<Re> (sqrt(x)) = 0> and C< F<Im> (sqrt(x)) E<gt>= 0>. If C<x belongs to B<I<R>>> and C<x E<lt> 0>, then the result is complex with positive imaginary part. Intmod a prime and C<p>-adics are allowed as arguments. In that case, the square root (if it exists) which is returned is the one whose first C<p>-adic digit (or its unique C<p>-adic digit in the case of intmods) is in the interval C<[0,p/2]>. When the argument is an intmod a non-prime (or a non-prime-adic), the result is undefined. X<gsqrt>The library syntax is B<gsqrt>C<(x,I<prec>)>. =head2 X<sqrtn>sqrtnC<(x,n,{&z})> principal branch of the C<n>th root of C<x>, i.e.S< >such that C<Arg(sqrt(x)) belongs to ]-F<Pi>/n, F<Pi>/n]>. Intmod a prime and C<p>-adics are allowed as arguments. If C<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 square root exist, C<0> is returned instead or raising an error. ? sqrtn(Mod(2,7), 2) %1 = Mod(4, 7) ? sqrtn(Mod(2,7), 2, &z); z %2 = Mod(6, 7) ? 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)= { local(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"); X<gsqrtn>The library syntax is B<gsqrtn>C<(x,n,&z,I<prec>)>. =head2 X<tan>tanC<(x)> tangent of C<x>. X<gtan>The library syntax is B<gtan>C<(x,I<prec>)>. =head2 X<tanh>tanhC<(x)> hyperbolic tangent of C<x>. X<gth>The library syntax is B<gth>C<(x,I<prec>)>. =head2 X<teichmuller>teichmullerC<(x)> TeichmE<uuml>ller character of the C<p>-adic number C<x>, i.e. the unique C<(p-1)>-th root of unity congruent to C<x / p^{v_p(x)}> modulo C<p>. X<teich>The library syntax is B<teich>C<(x)>. =head2 X<theta>thetaC<(q,z)> Jacobi sine theta-function. X<theta>The library syntax is B<theta>C<(q,z,I<prec>)>. =head2 X<thetanullk>thetanullkC<(q,k)> C<k>-th derivative at C<z = 0> of C<theta(q,z)>. X<thetanullk>The library syntax is B<thetanullk>C<(q,k,I<prec>)>, where C<k> is a C<long>. =head2 X<weber>weberC<(x,{I<flag> = 0})> one of Weber's three C<f> functions. If C<I<flag> = 0>, returns S< >C<f(x) = F<exp> (-iF<Pi>/24).F<eta>((x+1)/2)/F<eta>(x) such that j = (f^{24}-16)^3/f^{24},> where C<j> is the elliptic C<j>-invariant (see the function C<ellj>). If C<I<flag> = 1>, returns S< >C<f_1(x) = F<eta>(x/2)/F<eta>(x) such that j = (f_1^{24}+16)^3/f_1^{24}.> Finally, if C<I<flag> = 2>, returns S< >C<f_2(x) = F<sqrt> {2}F<eta>(2x)/F<eta>(x) such that j = (f_2^{24}+16)^3/f_2^{24}.> Note the identities C<f^8 = f_1^8+f_2^8> and C<ff_1f_2 = F<sqrt> 2>. X<weber0>The library syntax is B<weber0>C<(x,I<flag>,prec)>. Associated to the various values of I<flag>, the following functions are also available: C< B<werberf>(x,prec)>X<werberf>, C< B<werberf1>(x,prec)>X<werberf1> or C< B<werberf2>(x,prec)>X<werberf2>. =head2 X<zeta>zetaC<(s)> For C<s> a complex number, Riemann's zeta function X<Riemann zeta-function> C<F<zeta>(s) = F<sum>_{n E<gt>= 1}n^{-s}>, computed using the X<Euler-Maclaurin>Euler-Maclaurin summation formula, except when C<s> is of type integer, in which case it is computed using Bernoulli numbersX<Bernoulli numbers> for C<s E<lt>= 0> or C<s E<gt> 0> and even, and using modular forms for C<s E<gt> 0> and odd. For C<s> a C<p>-adic number, Kubota-Leopoldt zeta function at C<s>, that is the unique continuous C<p>-adic function on the C<p>-adic integers that interpolates the values of C<(1 - p^{-k}) F<zeta>(k)> at negative integers C<k> such that C<k = 1 (mod p-1)> (resp. C<k> is odd) if C<p> is odd (resp. C<p = 2>). X<gzeta>The library syntax is B<gzeta>C<(s,I<prec>)>. =head1 Arithmetic functions X<Label se:arithmetic> These functions are by definition functions whose natural domain of definition is either B<I<Z>> (or C<B<I<Z>>_{ E<gt> 0}>), or sometimes polynomials over a base ring. Functions which concern polynomials exclusively will be explained in the next section. The way these functions are used is completely different from transcendental functions: in general only the types integer and polynomial are accepted as arguments. If a vector or matrix type is given, the function will be applied on each coefficient independently. In the present version B<2.2.0>, all arithmetic functions in the narrow sense of the wordS< >--- Euler's totientX<Euler totient function> function, the X<Moebius>Moebius function, the sums over divisors or powers of divisors etc.--- call, after trial division by small primes, the same versatile factoring machinery described under C<factorint>. It includes X<Shanks SQUFOF>Shanks SQUFOF, X<Pollard Rho>Pollard Rho, X<ECM>ECM and X<MPQS>MPQS stages, and has an early exit option for the functions X<moebius>B<moebius> and (the integer function underlying) X<issquarefree>B<issquarefree>. Note that it relies on a (fairly strong) probabilistic primality test, see C<ispseudoprime>. =head2 X<addprimes>addprimesC<({x = []})> adds the integers contained in the vector C<x> (or the single integer C<x>) to a special table of ``user-defined primes'', and returns that table. Whenever C<factor> is subsequently called, it will trial divise by the elements in this table. If C<x> is empty or omitted, just returns the current list of extra primes. The entries in C<x> are not checked for primality, and in fact they need only be positive integers. The algorithm makes sure that all elements in the table are pairwise coprime, so it may end up containing divisors of the input integers. It is a useful trick to add known composite numbers, which the function C<factor(x,0)> was not able to factor. In case the message ``impossible inverse modulo C<E<lt>>I<some INTMOD>C<E<gt>>'' shows up afterwards, you have just stumbled over a non-trivial factor. Note that the arithmetic functions in the narrow sense, like X<eulerphi>B<eulerphi>, do \emph{not} use this extra table. To remove primes from the list use C<removeprimes>. X<addprimes>The library syntax is B<addprimes>C<(x)>. =head2 X<bestappr>bestapprC<(x,A,{B})> if C<B> is omitted, finds the best rational approximation to C<x belongs to B<I<R>>> (or C<B<I<R>>[X]>, or C<B<I<R>>^n>,...) with denominator at most equal to C<A> using continued fractions. If C<B> is present, C<x> is assumed to be of type C<t_INTMOD> modulo C<M> (or a recursive combination of those), and the routine returns the unique fraction C<a/b> in coprime integers C<a E<lt>= A> and C<b E<lt>= B> which is congruent to C<x> modulo C<M>. If C<M E<lt>= 2AB>, uniqueness is not guaranteed and the function fails with an error message. If rational reconstruction is not possible (no such C<a/b> exists for at least one component of C<x>), returns C<-1>. X<bestappr0>The library syntax is B<bestappr0>C<(x,A,B)>. Also available is C< B<bestappr>(x,A)>X<bestappr> corresponding to an omitted C<B>. =head2 X<bezout>bezoutC<(x,y)> finds C<u> and C<v> minimal in a natural sense such that C<x*u+y*v = F<gcd>(x,y)>. The arguments must be both integers or both polynomials, and the result is a row vector with three components C<u>, C<v>, and C<F<gcd>(x,y)>. X<extended gcd> X<vecbezout>The library syntax is B<vecbezout>C<(x,y)> to get the vector, or C< B<gbezout>(x,y, &u, &v)>X<gbezout> which gives as result the address of the created gcd, and puts the addresses of the corresponding created objects into C<u> and C<v>. =head2 X<bezoutres>bezoutresC<(x,y)> as C<bezout>, with the resultant of C<x> and C<y> replacing the gcd. X<extended gcd> The algorithm uses (subresultant) assumes the base ring is a domain. X<vecbezoutres>The library syntax is B<vecbezoutres>C<(x,y)> to get the vector, or C< B<subresext>(x,y, &u, &v)>X<subresext> which gives as result the address of the created gcd, and puts the addresses of the corresponding created objects into C<u> and C<v>. =head2 X<bigomega>bigomegaC<(x)> number of prime divisors of C<|x|> counted with multiplicity. C<x> must be an integer. X<bigomega>The library syntax is B<bigomega>C<(x)>, the result is a C<long>. =head2 X<binomial>binomialC<(x,y)> X<binomial coefficient>binomial coefficient C<\binom{x}{y}>. Here C<y> must be an integer, but C<x> can be any PARI object. X<binomial>The library syntax is B<binomial>C<(x,y)>, where C<y> must be a C<long>. =head2 X<chinese>chineseC<(x,{y})> if C<x> and C<y> are both intmods or both polmods, creates (with the same type) a C<z> in the same residue class as C<x> and in the same residue class as C<y>, if it is possible. This function also allows vector and matrix arguments, in which case the operation is recursively applied to each component of the vector or matrix. For polynomial arguments, it is applied to each coefficient. If C<y> is omitted, and C<x> is a vector, C<chinese> is applied recursively to the components of C<x>, yielding a residue belonging to the same class as all components of C<x>. Finally C<chinese(x,x) = x> regardless of the type of C<x>; this allows vector arguments to contain other data, so long as they are identical in both vectors. X<chinese>The library syntax is B<chinese>C<(x,y)>. Also available is X<chinese1>C<chinese1>C<(x)>, corresponding to an ommitted C<y>. =head2 X<content>contentC<(x)> computes the gcd of all the coefficients of C<x>, when this gcd makes sense. This is the natural definition if C<x> is a polynomial (and by extension a power series) or a vector/matrix. This is in general a weaker notion than the \emph{ideal} generated by the coefficients: ? content(2*x+y) %1 = 1 \\ = gcd(2,y) over Q[y] If C<x> is a scalar, this simply returns the absolute value of C<x> if C<x> is rational (C<t_INT> or C<t_FRAC>), and either C<1> (inexact input) or C<x> (exact input) otherwise; the result should be identical to C<gcd(x, 0)>. The content of a rational function is the ratio of the contents of the numerator and the denominator. In recursive structures, if a matrix or vector \emph{coefficient} C<x> appears, the gcd is taken not with C<x>, but with its content: ? content([ [2], 4*matid(3) ]) %1 = 2 X<content>The library syntax is B<content>C<(x)>. =head2 X<contfrac>contfracC<(x,{b},{nmax})> creates the row vector whose components are the partial quotients of the X<continued fraction>continued fraction expansion of C<x>. That is a result C<[a_0,...,a_n]> means that C<x ~ a_0+1/(a_1+...+1/a_n)...)>. The output is normalized so that C<a_n ! = 1> (unless we also have C<n = 0>). The number of partial quotients C<n> is limited to C<nmax>. If C<x> is a real number, the expansion stops at the last significant partial quotient if C<nmax> is omitted. C<x> can also be a rational function or a power series. If a vector C<b> is supplied, the numerators will be equal to the coefficients of C<b> (instead of all equal to C<1> as above). The length of the result is then equal to the length of C<b>, unless a partial remainder is encountered which is equal to zero, in which case the expansion stops. In the case of real numbers, the stopping criterion is thus different from the one mentioned above since, if C<b> is too long, some partial quotients may not be significant. If C<b> is an integer, the command is understood as C<contfrac(x,nmax)>. X<contfrac0>The library syntax is B<contfrac0>C<(x,b,nmax)>. Also available are C< B<gboundcf>(x,nmax)>X<gboundcf>, C< B<gcf>(x)>X<gcf>, or C< B<gcf2>(b,x)>X<gcf2>, where C<nmax> is a C integer. =head2 X<contfracpnqn>contfracpnqnC<(x)> when C<x> is a vector or a one-row matrix, C<x> is considered as the list of partial quotients C<[a_0,a_1,...,a_n]> of a rational number, and the result is the 2 by 2 matrix C<[p_n,p_{n-1};q_n,q_{n-1}]> in the standard notation of continued fractions, so C<p_n/q_n = a_0+1/(a_1+...+1/a_n)...)>. If C<x> is a matrix with two rows C<[b_0,b_1,...,b_n]> and C<[a_0,a_1,...,a_n]>, this is then considered as a generalized continued fraction and we have similarly C<p_n/q_n = 1/b_0(a_0+b_1/(a_1+...+b_n/a_n)...)>. Note that in this case one usually has C<b_0 = 1>. X<pnqn>The library syntax is B<pnqn>C<(x)>. =head2 X<core>coreC<(n,{I<flag> = 0})> if C<n> is a non-zero integer written as C<n = df^2> with C<d> squarefree, returns C<d>. If C<I<flag>> is non-zero, returns the two-element row vector C<[d,f]>. X<core0>The library syntax is B<core0>C<(n,I<flag>)>. Also available are C< B<core>(n)>X<core> ( = C< B<core0>(n,0)>X<core0>) and C< B<core2>(n)>X<core2> ( = C< B<core0>(n,1)>X<core0>). =head2 X<coredisc>corediscC<(n,{I<flag>})> if C<n> is a non-zero integer written as C<n = df^2> with C<d> fundamental discriminant (including 1), returns C<d>. If C<I<flag>> is non-zero, returns the two-element row vector C<[d,f]>. Note that if C<n> is not congruent to 0 or 1 modulo 4, C<f> will be a half integer and not an integer. X<coredisc0>The library syntax is B<coredisc0>C<(n,I<flag>)>. Also available are C< B<coredisc>(n)>X<coredisc> ( = C< B<coredisc>(n,0)>X<coredisc>) and C< B<coredisc2>(n)>X<coredisc2> ( = C< B<coredisc>(n,1)>X<coredisc>). =head2 X<dirdiv>dirdivC<(x,y)> C<x> and C<y> being vectors of perhaps different lengths but with C<y[1] ! = 0> considered as X<Dirichlet series>Dirichlet series, computes the quotient of C<x> by C<y>, again as a vector. X<dirdiv>The library syntax is B<dirdiv>C<(x,y)>. =head2 X<direuler>direulerC<(p = a,b,I<expr>,{c})> computes the X<Dirichlet series>Dirichlet series associated to the X<Euler product>Euler product of expression I<expr> as C<p> ranges through the primes from C<a> to C<b>. I<expr> must be a polynomial or rational function in another variable than C<p> (say C<X>) and C<I<expr>(X)> is understood as the local factor C<I<expr>(p^{-s})>. The series is output as a vector of coefficients. If C<c> is present, output only the first C<c> coefficients in the series. The following command computes the X<sigma>B<sigma> function, associated to C<F<zeta>(s)F<zeta>(s-1)>: ? direuler(p=2, 10, 1/((1-X)*(1-p*X))) %1 = [1, 3, 4, 7, 6, 12, 8, 15, 13, 18] X<direuler>The library syntax is B<direuler>C<(void *E, GEN (*eval)(GEN,void*), GEN a, GEN b)> =head2 X<dirmul>dirmulC<(x,y)> C<x> and C<y> being vectors of perhaps different lengths considered as X<Dirichlet series>Dirichlet series, computes the product of C<x> by C<y>, again as a vector. X<dirmul>The library syntax is B<dirmul>C<(x,y)>. =head2 X<divisors>divisorsC<(x)> creates a row vector whose components are the divisors of C<x>. The factorization of C<x> (as output by X<factor>C<factor>) can be used instead. By definition, these divisors are the products of the irreducible factors of C<n>, as produced by C<factor(n)>, raised to appropriate powers (no negative exponent may occur in the factorization). If C<n> is an integer, they are the positive divisors, in increasing order. X<divisors>The library syntax is B<divisors>C<(x)>. =head2 X<eulerphi>eulerphiC<(x)> Euler's C<F<phi>> (totient)X<Euler totient function> function of C<|x|>, in other words C<|(B<I<Z>>/xB<I<Z>>)^*|>. C<x> must be of type integer. X<phi>The library syntax is B<phi>C<(x)>. =head2 X<factor>factorC<(x,{I<lim> = -1})> general factorization function. If C<x> is of type integer, rational, polynomial or rational function, the result is a two-column matrix, the first column being the irreducibles dividing C<x> (prime numbers or polynomials), and the second the exponents. If C<x> is a vector or a matrix, the factoring is done componentwise (hence the result is a vector or matrix of two-column matrices). By definition, C<0> is factored as C<0^1>. If C<x> is of type integer or rational, the factors are I<pseudoprimes> (see C<ispseudoprime>), and in general not rigorously proven primes. In fact, any factor which is C< E<lt>= 10^{13}> is a genuine prime number. Use C<isprime> to prove primality of other factors, as in fa = factor(2^2^7 +1) isprime( fa[,1] ) An argument I<lim> can be added, meaning that we look only for prime factors C<p E<lt> I<lim>>, or up to C<primelimit>, whichever is lowest (except when C<I<lim> = 0> where the effect is identical to setting C<I<lim> = primelimit>). In this case, the remaining part may actually be a proven composite! See X<factorint>C<factorint> for more information about the algorithms used. The polynomials or rational functions to be factored must have scalar coefficients. In particular PARI does \emph{not} know how to factor multivariate polynomials. See X<factormod>C<factormod> and X<factorff>C<factorff> for the algorithms used over finite fields, X<factornf>C<factornf> for the algorithms over number fields. Over B<I<Q>>, X<van Hoeij>van Hoeij's method is used, which is able to cope with hundreds of modular factors. Note that PARI tries to guess in a sensible way over which ring you want to factor. Note also that factorization of polynomials is done up to multiplication by a constant. In particular, the factors of rational polynomials will have integer coefficients, and the content of a polynomial or rational function is discarded and not included in the factorization. If needed, you can always ask for the content explicitly: ? factor(t^2 + 5/2*t + 1) %1 = [2*t + 1 1] [t + 2 1] ? content(t^2 + 5/2*t + 1) %2 = 1/2 See also X<factornf>C<factornf> and X<nffactor>C<nffactor>. X<factor0>The library syntax is B<factor0>C<(x,I<lim>)>, where I<lim> is a C integer. Also available are C< B<factor>(x)>X<factor> ( = C< B<factor0>(x,-1)>X<factor0>), C< B<smallfact>(x)>X<smallfact> ( = C< B<factor0>(x,0)>X<factor0>). =head2 X<factorback>factorbackC<(f,{e},{nf})> gives back the factored object corresponding to a factorization. The integer C<1> corresponds to the empty factorization. If the last argument is of number field type (e.g.S< >created by C<nfinit>), assume we are dealing with an ideal factorization in the number field. The resulting ideal product is given in HNF form. If C<e> is present, C<e> and C<f> must be vectors of the same length (C<e> being integral), and the corresponding factorization is the product of the C<f[i]^{e[i]}>. If not, and C<f> is vector, it is understood as in the preceding case with C<e> a vector of 1 (the product of the C<f[i]> is returned). Finally, C<f> can be a regular factorization, as produced with any C<factor> command. A few examples: ? factorback([2,2; 3,1]) %1 = 12 ? factorback([2,2], [3,1]) %2 = 12 ? factorback([5,2,3]) %3 = 30 ? factorback([2,2], [3,1], nfinit(x^3+2)) %4 = [16 0 0] [0 16 0] [0 0 16] ? nf = nfinit(x^2+1); fa = idealfactor(nf, 10) %5 = [[2, [1, 1]~, 2, 1, [1, 1]~] 2] [[5, [-2, 1]~, 1, 1, [2, 1]~] 1] [[5, [2, 1]~, 1, 1, [-2, 1]~] 1] ? factorback(fa) *** forbidden multiplication t_VEC * t_VEC. ? factorback(fa, nf) %6 = [10 0] [0 10] In the fourth example, C<2> and C<3> are interpreted as principal ideals in a cubic field. In the fifth one, C<factorback(fa)> is meaningless since we forgot to indicate the number field, and the entries in the first column of C<fa> can't be multiplied. X<factorback0>The library syntax is B<factorback0>C<(f,e,I<nf>)>, where an omitted C<I<nf>> or C<e> is entered as C<NULL>. Also available is X<factorback>C<factorback>C<(f,I<nf>)> (case C<e = NULL>) where an omitted C<I<nf>> is entered as C<NULL>. =head2 X<factorcantor>factorcantorC<(x,p)> factors the polynomial C<x> modulo the prime C<p>, using distinct degree plus X<Cantor-Zassenhaus>Cantor-ZassenhausX<Zassenhaus>. The coefficients of C<x> must be operation-compatible with C<B<I<Z>>/pB<I<Z>>>. The result is a two-column matrix, the first column being the irreducible polynomials dividing C<x>, and the second the exponents. If you want only the \emph{degrees} of the irreducible polynomials (for example for computing an C<L>-function), use C<factormod(x,p,1)>. Note that the C<factormod> algorithm is usually faster than C<factorcantor>. X<factcantor>The library syntax is B<factcantor>C<(x,p)>. =head2 X<factorff>factorffC<(x,p,a)> factors the polynomial C<x> in the field C<B<I<F>>_q> defined by the irreducible polynomial C<a> over C<B<I<F>>_p>. The coefficients of C<x> must be operation-compatible with C<B<I<Z>>/pB<I<Z>>>. The result is a two-column matrix: the first column contains the irreducible factors of C<x>, and the second their exponents. If all the coefficients of C<x> are in C<B<I<F>>_p>, a much faster algorithm is applied, using the computation of isomorphisms between finite fields. X<factorff>The library syntax is B<factorff>C<(x,p,a)>. =head2 X<factorial>factorialC<(x)> or C<x!> factorial of C<x>. The expression C<x!> gives a result which is an integer, while C<factorial(x)> gives a real number. X<mpfact>The library syntax is B<mpfact>C<(x)> for C<x!> and C< B<mpfactr>(x,prec)>X<mpfactr> for C<factorial(x)>. C<x> must be a C<long> integer and not a PARI integer. =head2 X<factorint>factorintC<(n,{I<flag> = 0})> factors the integer C<n> into a product of pseudoprimes (see C<ispseudoprime>), using a combination of the X<Shanks SQUFOF>Shanks SQUFOF and X<Pollard Rho>Pollard Rho method (with modifications due to Brent), X<Lenstra>Lenstra's X<ECM>ECM (with modifications by Montgomery), and X<MPQS>MPQS (the latter adapted from the X<LiDIA>LiDIA code with the kind permission of the LiDIA maintainers), as well as a search for pure powers with exponentsC< E<lt>= 10>. The output is a two-column matrix as for C<factor>. Use C<isprime> on the result if you want to guarantee primality. This gives direct access to the integer factoring engine called by most arithmetical functions. I<flag> is optional; its binary digits mean 1: avoid MPQS, 2: skip first stage ECM (we may still fall back to it later), 4: avoid Rho and SQUFOF, 8: don't run final ECM (as a result, a huge composite may be declared to be prime). Note that a (strong) probabilistic primality test is used; thus composites might (very rarely) not be detected. You are invited to play with the flag settings and watch the internals at work by using C<gp>'s X<debuglevel>C<debuglevel> default parameter (level 3 shows just the outline, 4 turns on time keeping, 5 and above show an increasing amount of internal details). If you see anything funny happening, please let us know. X<factorint>The library syntax is B<factorint>C<(n,I<flag>)>. =head2 X<factormod>factormodC<(x,p,{I<flag> = 0})> factors the polynomial C<x> modulo the prime integer C<p>, using X<Berlekamp>Berlekamp. The coefficients of C<x> must be operation-compatible with C<B<I<Z>>/pB<I<Z>>>. The result is a two-column matrix, the first column being the irreducible polynomials dividing C<x>, and the second the exponents. If C<I<flag>> is non-zero, outputs only the \emph{degrees} of the irreducible polynomials (for example, for computing an C<L>-function). A different algorithm for computing the mod C<p> factorization is C<factorcantor> which is sometimes faster. X<factormod>The library syntax is B<factormod>C<(x,p,I<flag>)>. Also available are C< B<factmod>(x,p)>X<factmod> (which is equivalent to C< B<factormod>(x,p,0)>X<factormod>) and C< B<simplefactmod>(x,p)>X<simplefactmod> ( = C< B<factormod>(x,p,1)>X<factormod>). =head2 X<fibonacci>fibonacciC<(x)> C<x^{th}> Fibonacci number. X<fibo>The library syntax is B<fibo>C<(x)>. C<x> must be a C<long>. =head2 X<ffinit>ffinitC<(p,n,{v = x})> computes a monic polynomial of degree C<n> which is irreducible over C<B<I<F>>_p>. For instance if C<P = ffinit(3,2,y)>, you can represent elements in C<B<I<F>>_{3^2}> as polmods modulo C<P>. This function uses a fast variant of Adleman-Lenstra's algorithm. X<ffinit>The library syntax is B<ffinit>C<(p,n,v)>, where C<v> is a variable number. =head2 X<gcd>gcdC<(x,{y})> creates the greatest common divisor of C<x> and C<y>. C<x> and C<y> can be of quite general types, for instance both rational numbers. If C<y> is omitted and C<x> is a vector, returns the C<gcd> of all components of C<x>, i.e.S< >this is equivalent to C<content(x)>. When C<x> and C<y> are both given and one of them is a vector/matrix type, the GCD is again taken recursively on each component, but in a different way. If C<y> is a vector, resp.S< >matrix, then the result has the same type as C<y>, and components equal to C<gcd(x, y[i])>, resp.S< >C<gcd(x, y[,i])>. Else if C<x> is a vector/matrix the result has the same type as C<x> and an analogous definition. Note that for these types, C<gcd> is not commutative. The algorithm used is a naive X<Euclid>Euclid except for the following inputs: \item integers: use modified right-shift binary (``plus-minus'' variant). \item univariate polynomials with coeffients in the same number field (in particular rational): use modular gcd algorithm. \item general polynomials: use the X<subresultant algorithm>subresultant algorithm if coefficient explosion is likely (exact, non modular, coefficients). X<ggcd>The library syntax is B<ggcd>C<(x,y)>. For general polynomial inputs, C< B<srgcd>(x,y)>X<srgcd> is also available. For univariate \emph{rational} polynomials, one also has C< B<modulargcd>(x,y)>X<modulargcd>. =head2 X<hilbert>hilbertC<(x,y,{p})> X<Hilbert symbol>Hilbert symbol of C<x> and C<y> modulo C<p>. If C<x> and C<y> are of type integer or fraction, an explicit third parameter C<p> must be supplied, C<p = 0> meaning the place at infinity. Otherwise, C<p> needs not be given, and C<x> and C<y> can be of compatible types integer, fraction, real, intmod a prime (result is undefined if the modulus is not prime), or C<p>-adic. X<hil>The library syntax is B<hil>C<(x,y,p)>. =head2 X<isfundamental>isfundamentalC<(x)> true (1) if C<x> is equal to 1 or to the discriminant of a quadratic field, false (0) otherwise. X<gisfundamental>The library syntax is B<gisfundamental>C<(x)>, but the simpler function C< B<isfundamental>(x)>X<isfundamental> which returns a C<long> should be used if C<x> is known to be of type integer. =head2 X<ispower>ispowerC<(x,{k}, {&n})> if C<k> is given, returns true (1) if C<x> is a C<k>-th power, false (0) if not. In this case, C<x> may be an integer or polynomial, a rational number or function, or an intmod a prime or C<p>-adic. If C<k> is omitted, only integers and fractions are allowed and the function returns the maximal C<k E<gt>= 2> such that C<x = n^k> is a perfect power, or 0 if no such C<k> exist; in particular C<ispower(-1)>, C<ispower(0)>, and C<ispower(1)> all return C<0>. If a third argument C<&n> is given and a C<k>-th root was computed in the process, then C<n> is set to that root. X<ispower>The library syntax is B<ispower>C<(x, k, &n)>, the result is a C<long>. Omitted C<k> or C<n> are coded as C<NULL>. =head2 X<isprime>isprimeC<(x,{I<flag> = 0})> true (1) if C<x> is a (proven) prime number, false (0) otherwise. This can be very slow when C<x> is indeed prime and has more than C<1000> digits, say. Use X<ispseudoprime>C<ispseudoprime> to quickly check for pseudo primality. See also C<factor>. If C<I<flag> = 0>, use a combination of Baillie-PSW pseudo primality test (see X<ispseudoprime>C<ispseudoprime>), Selfridge ``C<p-1>'' test if C<x-1> is smooth enough, and Adleman-Pomerance-Rumely-Cohen-Lenstra (APRCL) for general C<x>. If C<I<flag> = 1>, use Selfridge-Pocklington-Lehmer ``C<p-1>'' test and output a primality certificate as follows: return 0 if C<x> is composite, 1 if C<x> is small enough that passing Baillie-PSW test guarantees its primality (currently C<x E<lt> 10^{13}>), C<2> if C<x> is a large prime whose primality could only sensibly be proven (given the algorithms implemented in PARI) using the APRCL test. Otherwise (C<x> is large and C<x-1> is smooth) output a three column matrix as a primality certificate. The first column contains the prime factors C<p> of C<x-1>, the second the corresponding elements C<a_p> as in PropositionS< >8.3.1 in GTMS< >138, and the third the output of isprime(p,1). The algorithm fails if one of the pseudo-prime factors is not prime, which is exceedingly unlikely (and well worth a bug report). If C<I<flag> = 2>, use APRCL. X<gisprime>The library syntax is B<gisprime>C<(x,I<flag>)>, but the simpler function C< B<isprime>(x)>X<isprime> which returns a C<long> should be used if C<x> is known to be of type integer. =head2 X<ispseudoprime>ispseudoprimeC<(x,{I<flag>})> true (1) if C<x> is a strong pseudo prime (see below), false (0) otherwise. If this function returns false, C<x> is not prime; if, on the other hand it returns true, it is only highly likely that C<x> is a prime number. Use X<isprime>C<isprime> (which is of course much slower) to prove that C<x> is indeed prime. If C<I<flag> = 0>, checks whether C<x> is a Baillie-Pomerance-Selfridge-Wagstaff pseudo prime (strong Rabin-Miller pseudo prime for base C<2>, followed by strong Lucas test for the sequence C<(P,-1)>, C<P> smallest positive integer such that C<P^2 - 4> is not a square mod C<x>). There are no known composite numbers passing this test (in particular, all composites C< E<lt>= 10^{13}> are correctly detected), although it is expected that infinitely many such numbers exist. If C<I<flag> E<gt> 0>, checks whether C<x> is a strong Miller-Rabin pseudo prime for C<I<flag>> randomly chosen bases (with end-matching to catch square roots of C<-1>). X<gispseudoprime>The library syntax is B<gispseudoprime>C<(x,I<flag>)>, but the simpler function C< B<ispseudoprime>(x)>X<ispseudoprime> which returns a C<long> should be used if C<x> is known to be of type integer. =head2 X<issquare>issquareC<(x,{&n})> true (1) if C<x> is a square, false (0) if not. What ``being a square'' means depends on the type of C<x>: all C<t_COMPLEX> are squares, as well as all non-negative C<t_REAL>; for exact types such as C<t_INT>, C<t_FRAC> and C<t_INTMOD>, squares are numbers of the form C<s^2> with C<s> in B<I<Z>>, B<I<Q>> and C<B<I<Z>>/NB<I<Z>>> respectively. ? issquare(3) \\ as an integer %1 = 0 ? issquare(3.) \\ as a real number %2 = 1 ? issquare(Mod(7, 8)) \\ in Z/8Z %3 = 0 ? issquare( 5 + O(13^4) ) \\ in Q_13 %4 = 0 If C<n> is given and an exact square root had to be computed in the checking process, puts that square root in C<n>. This is the case when C<x> is a C<t_INT>, C<t_FRAC>, C<t_POL> or C<t_RFRAC> (or a vector of such objects): ? issquare(4, &n) %1 = 1 ? n %2 = 2 ? issquare([4, x^2], &n) %3 = [1, 1] \\ both are squares ? n %4 = [2, x] \\ the square roots This will \emph{not} work for C<t_INTMOD> (use quadratic reciprocity) or C<t_SER> (only check the leading coefficient). X<gissquarerem>The library syntax is B<gissquarerem>C<(x,&n)>. Also available is C< B<gissquare>(x)>X<gissquare>. =head2 X<issquarefree>issquarefreeC<(x)> true (1) if C<x> is squarefree, false (0) if not. Here C<x> can be an integer or a polynomial. X<gissquarefree>The library syntax is B<gissquarefree>C<(x)>, but the simpler function C< B<issquarefree>(x)>X<issquarefree> which returns a C<long> should be used if C<x> is known to be of type integer. This X<issquarefree>B<issquarefree> is just the square of the X<Moebius>Moebius function, and is computed as a multiplicative arithmetic function much like the latter. =head2 X<kronecker>kroneckerC<(x,y)> X<Kronecker symbol>Kronecker symbol C<(x|y)>, where C<x> and C<y> must be of type integer. By definition, this is the extension of X<Legendre symbol>Legendre symbol to C<B<I<Z>> x B<I<Z>>> by total multiplicativity in both arguments with the following special rules for C<y = 0, -1> or C<2>: \item C<(x|0) = 1> if C<|x |= 1> and C<0> otherwise. \item C<(x|-1) = 1> if C<x E<gt>= 0> and C<-1> otherwise. \item C<(x|2) = 0> if C<x> is even and C<1> if C<x = 1,-1 mod 8> and C<-1> if C<x = 3,-3 mod 8>. X<kronecker>The library syntax is B<kronecker>C<(x,y)>, the result (C<0> or C<F<+-> 1>) is a C<long>. =head2 X<lcm>lcmC<(x,{y})> least common multiple of C<x> and C<y>, i.e.S< >such that C<lcm(x,y)*F<gcd>(x,y) = abs(x*y)>. If C<y> is omitted and C<x> is a vector, returns the C<lcm> of all components of C<x>. When C<x> and C<y> are both given and one of them is a vector/matrix type, the LCM is again taken recursively on each component, but in a different way. If C<y> is a vector, resp.S< >matrix, then the result has the same type as C<y>, and components equal to C<lcm(x, y[i])>, resp.S< >C<lcm(x, y[,i])>. Else if C<x> is a vector/matrix the result has the same type as C<x> and an analogous definition. Note that for these types, C<lcm> is not commutative. Note that C<lcm(v)> is quite different from l = v[1]; for (i = 1, #v, l = lcm(l, v[i])) Indeed, C<lcm(v)> is a scalar, but C<l> may not be (if one of the C<v[i]> is a vector/matrix). The computation uses a divide-conquer tree and should be much more efficient, especially when using the GMP multiprecision kernel (and more subquadratic algorithms become available): ? v = vector(10^4, i, random); ? lcm(v); time = 323 ms. ? l = v[1]; for (i = 1, #v, l = lcm(l, v[i])) time = 833 ms. X<glcm>The library syntax is B<glcm>C<(x,y)>. =head2 X<moebius>moebiusC<(x)> X<Moebius>Moebius C<F<mu>>-function of C<|x|>. C<x> must be of type integer. X<mu>The library syntax is B<mu>C<(x)>, the result (C<0> or C<F<+-> 1>) is a C<long>. =head2 X<nextprime>nextprimeC<(x)> finds the smallest pseudoprime (see X<ispseudoprime>C<ispseudoprime>) greater than or equal to C<x>. C<x> can be of any real type. Note that if C<x> is a pseudoprime, this function returns C<x> and not the smallest pseudoprime strictly larger than C<x>. To rigorously prove that the result is prime, use C<isprime>. X<nextprime>The library syntax is B<nextprime>C<(x)>. =head2 X<numdiv>numdivC<(x)> number of divisors of C<|x|>. C<x> must be of type integer. X<numbdiv>The library syntax is B<numbdiv>C<(x)>. =head2 X<numbpart>numbpartC<(n)> gives the number of unrestricted partitions of C<n>, usually called C<p(n)> in the litterature; in other words the number of nonnegative integer solutions to C<a+2b+3c+.. .= n>. C<n> must be of type integer and C<1 E<lt>= n E<lt> 10^{15}>. The algorithm uses the Hardy-Ramanujan-Rademacher formula. X<numbpart>The library syntax is B<numbpart>C<(n)>. =head2 X<omega>omegaC<(x)> number of distinct prime divisors of C<|x|>. C<x> must be of type integer. X<omega>The library syntax is B<omega>C<(x)>, the result is a C<long>. =head2 X<precprime>precprimeC<(x)> finds the largest pseudoprime (see X<ispseudoprime>C<ispseudoprime>) less than or equal to C<x>. C<x> can be of any real type. Returns 0 if C<x E<lt>= 1>. Note that if C<x> is a prime, this function returns C<x> and not the largest prime strictly smaller than C<x>. To rigorously prove that the result is prime, use C<isprime>. X<precprime>The library syntax is B<precprime>C<(x)>. =head2 X<prime>primeC<(x)> the C<x^{th}> prime number, which must be among the precalculated primes. X<prime>The library syntax is B<prime>C<(x)>. C<x> must be a C<long>. =head2 X<primepi>primepiC<(x)> the prime counting function. Returns the number of primes C<p>, C<p E<lt>= x>. Uses a naive algorithm so that C<x> must be less than C<primelimit>. X<primepi>The library syntax is B<primepi>C<(x)>. =head2 X<primes>primesC<(x)> creates a row vector whose components are the first C<x> prime numbers, which must be among the precalculated primes. X<primes>The library syntax is B<primes>C<(x)>. C<x> must be a C<long>. =head2 X<qfbclassno>qfbclassnoC<(D,{I<flag> = 0})> ordinary class number of the quadratic order of discriminant C<D>. In the present version B<2.2.0>, a C<O(D^{1/2})> algorithm is used for C<D E<gt> 0> (using Euler product and the functional equation) so C<D> should not be too large, say C<D E<lt> 10^8>, for the time to be reasonable. On the other hand, for C<D E<lt> 0> one can reasonably compute C<qfbclassno(D)> for C<|D| E<lt> 10^{25}>, since the routine uses X<Shanks>Shanks's method which is in C<O(|D|^{1/4})>. For larger values of C<|D|>, see C<quadclassunit>. If C<I<flag> = 1>, compute the class number using X<Euler product>Euler products and the functional equation. However, it is in C<O(|D|^{1/2})>. B<Important warning.> For C<D E<lt> 0>, this function may give incorrect results when the class group has a low exponent (has many cyclic factors), because implementing X<Shanks>Shanks's method in full generality slows it down immensely. It is therefore strongly recommended to double-check results using either the version with C<I<flag> = 1> or the function C<quadclassunit>. B<Warning.> contrary to what its name implies, this routine does not compute the number of classes of binary primitive forms of discriminant C<D>, which is equal to the \emph{narrow} class number. The two notions are the same when C<D E<lt> 0> or the fundamental unit C<F<varepsilon>> has negative norm; when C<D E<gt> 0> and C<NF<varepsilon> E<gt> 0>, the number of classes of forms is twice the ordinary class number. This is a problem which we cannot fix for backward compatibility reasons. Use the following routine if you are only interested in the number of classes of forms: QFBclassno(D) = qfbclassno(D) * if (D < 0 || norm(quadunit(D)) < 0, 1, 2) Here are a few examples: ? qfbclassno(400000028) time = 3,140 ms. %1 = 1 ? quadclassunit(400000028).no time = 20 ms. \{ much faster} %2 = 1 ? qfbclassno(-400000028) time = 0 ms. %3 = 7253 \{ correct, and fast enough} ? quadclassunit(-400000028).no time = 0 ms. %4 = 7253 X<qfbclassno0>The library syntax is B<qfbclassno0>C<(D,I<flag>)>. Also available: C< B<classno>(D)>X<classno> ( = C< B<qfbclassno>(D)>X<qfbclassno>), C< B<classno2>(D)>X<classno2> ( = C< B<qfbclassno>(D,1)>X<qfbclassno>), and finally we have the function C< B<hclassno>(D)>X<hclassno> which computes the class number of an imaginary quadratic field by counting reduced forms, an C<O(|D|)> algorithm. See also C<qfbhclassno>. =head2 X<qfbcompraw>qfbcomprawC<(x,y)> X<composition>composition of the binary quadratic forms C<x> and C<y>, without X<reduction>reduction of the result. This is useful e.g.S< >to compute a generating element of an ideal. X<compraw>The library syntax is B<compraw>C<(x,y)>. =head2 X<qfbhclassno>qfbhclassnoC<(x)> X<Hurwitz class number>Hurwitz class number of C<x>, where C<x> is non-negative and congruent to 0 or 3 modulo 4. For C<x E<gt> 5. 10^5>, we assume the GRH, and use C<quadclassunit> with default parameters. X<hclassno>The library syntax is B<hclassno>C<(x)>. =head2 X<qfbnucomp>qfbnucompC<(x,y,l)> X<composition>composition of the primitive positive definite binary quadratic forms C<x> and C<y> (type C<t_QFI>) using the NUCOMP and NUDUPL algorithms of X<Shanks>Shanks, E<agrave> la Atkin. C<l> is any positive constant, but for optimal speed, one should take C<l = |D|^{1/4}>, where C<D> is the common discriminant of C<x> and C<y>. When C<x> and C<y> do not have the same discriminant, the result is undefined. The current implementation is straightforward and in general \emph{slower} than the generic routine (since the latter take advantadge of asymptotically fast operations and careful optimizations). X<nucomp>The library syntax is B<nucomp>C<(x,y,l)>. The auxiliary function C< B<nudupl>(x,l)>X<nudupl> can be used when C<x = y>. =head2 X<qfbnupow>qfbnupowC<(x,n)> C<n>-th power of the primitive positive definite binary quadratic form C<x> using X<Shanks>Shanks's NUCOMP and NUDUPL algorithms (see C<qfbnucomp>, in particular the final warning). X<nupow>The library syntax is B<nupow>C<(x,n)>. =head2 X<qfbpowraw>qfbpowrawC<(x,n)> C<n>-th power of the binary quadratic form C<x>, computed without doing any X<reduction>reduction (i.e.S< >using C<qfbcompraw>). Here C<n> must be non-negative and C<n E<lt> 2^{31}>. X<powraw>The library syntax is B<powraw>C<(x,n)> where C<n> must be a C<long> integer. =head2 X<qfbprimeform>qfbprimeformC<(x,p)> prime binary quadratic form of discriminant C<x> whose first coefficient is the prime number C<p>. By abuse of notation, C<p = F<+-> 1> is a valid special case which returns the unit form. Returns an error if C<x> is not a quadratic residue mod C<p>. In the case where C<x E<gt> 0>, C<p E<lt> 0> is allowed, and the ``distance'' component of the form is set equal to zero according to the current precision. (Note that negative definite C<t_QFI> are not implemented.) X<primeform>The library syntax is B<primeform>C<(x,p,I<prec>)>, where the third variable C<I<prec>> is a C<long>, but is only taken into account when C<x E<gt> 0>. =head2 X<qfbred>qfbredC<(x,{I<flag> = 0},{D},{I<isqrtD>},{I<sqrtD>})> reduces the binary quadratic form C<x> (updating Shanks's distance function if C<x> is indefinite). The binary digits of C<I<flag>> are toggles meaning S< >S< >1: perform a single X<reduction>reduction step S< >S< >2: don't update X<Shanks>Shanks's distance C<D>, I<isqrtD>, I<sqrtD>, if present, supply the values of the discriminant, C<\floor{ F<sqrt> {D}}>, and C< F<sqrt> {D}> respectively (no checking is done of these facts). If C<D E<lt> 0> these values are useless, and all references to Shanks's distance are irrelevant. X<qfbred0>The library syntax is B<qfbred0>C<(x,I<flag>,D,I<isqrtD>,I<sqrtD>)>. Use C<NULL> to omit any of C<D>, I<isqrtD>, I<sqrtD>. Also available are C< B<redimag>(x)>X<redimag> ( = C< B<qfbred>(x)>X<qfbred> where C<x> is definite), and for indefinite forms: C< B<redreal>(x)>X<redreal> ( = C< B<qfbred>(x)>X<qfbred>), C< B<rhoreal>(x)>X<rhoreal> ( = C< B<qfbred>(x,1)>X<qfbred>), C< B<redrealnod>(x,sq)>X<redrealnod> ( = C< B<qfbred>(x,2,,isqrtD)>X<qfbred>), C< B<rhorealnod>(x,sq)>X<rhorealnod> ( = C< B<qfbred>(x,3,,isqrtD)>X<qfbred>). =head2 X<qfbsolve>qfbsolveC<(Q,p)> Solve the equation C<Q(x,y) = p> over the integers, where C<Q> is a binary quadratic form and C<p> a prime number. Return C<[x,y]> as a two-components vector, or zero if there is no solution. Note that this function returns only one solution and not all the solutions. Let C<D = \disc Q>. The algorithm used runs in probabilistic polynomial time in C<p> (through the computation of a square root of C<D> modulo C<p>); it is polynomial time in C<D> if C<Q> is imaginary, but exponential time if C<Q> is real (through the computation of a full cycle of reduced forms). In the latter case, note that X<bnfisprincipal>C<bnfisprincipal> provides a solution in heuristic subexponential time in C<D> assuming the GRH. X<qfbsolve>The library syntax is B<qfbsolve>C<(Q,n)>. =head2 X<quadclassunit>quadclassunitC<(D,{I<flag> = 0},{I<tech> = []})> X<Buchmann-McCurley>Buchmann-McCurley's sub-exponential algorithm for computing the class group of a quadratic order of discriminant C<D>. This function should be used instead of X<qfbclassno>C<qfbclassno> or X<quadregula>C<quadregula> when C<D E<lt> -10^{25}>, C<D E<gt> 10^{10}>, or when the \emph{structure} is wanted. It is a special case of X<bnfinit>C<bnfinit>, which is slower, but more robust. If C<I<flag>> is non-zero \emph{and} C<D E<gt> 0>, computes the narrow class group and regulator, instead of the ordinary (or wide) ones. In the current version B<2.2.0>, this does not work at all: use the general function X<bnfnarrow>C<bnfnarrow>. Optional parameter I<tech> is a row vector of the form C<[c_1, c_2]>, where C<c_1 E<lt>= c_2> are positive real numbers which control the execution time and the stack size. For a given C<c_1>, set C<c_2 = c_1> to get maximum speed. To get a rigorous result under X<GRH>GRH, you must take C<c_2 E<gt>= 6>. Reasonable values for C<c_1> are between C<0.1> and C<2>. More precisely, the algorithm will \emph{assume} that prime ideals of norm less than C<c_2 ( F<log> |D|)^2> generate the class group, but the bulk of the work is done with prime ideals of norm less than C<c_1 ( F<log> |D|)^2>. A larger C<c_1> means that relations are easier to find, but more relations are needed and the linear algebra will be harder. The default is C<c_1 = c_2 = 0.2>, so the result is \emph{not} rigorously proven. The result is a vector C<v> with 3 components if C<D E<lt> 0>, and C<4> otherwise. The correspond respectively to \item C<v[1]>: the class number \item C<v[2]>: a vector giving the structure of the class group as a product of cyclic groups; \item C<v[3]>: a vector giving generators of those cyclic groups (as binary quadratic forms). \item C<v[4]>: (omitted if C<D E<lt> 0>) the regulator, computed to an accuracy which is the maximum of an internal accuracy determined by the program and the current default (note that once the regulator is known to a small accuracy it is trivial to compute it to very high accuracy, see the tutorial). X<quadclassunit0>The library syntax is B<quadclassunit0>C<(D,I<flag>,tech)>. Also available are C< B<buchimag>(D,c_1,c_2)>X<buchimag> and C< B<buchreal>(D,I<flag>,c_1,c_2)>X<buchreal>. =head2 X<quaddisc>quaddiscC<(x)> discriminant of the quadratic field C<B<I<Q>>( F<sqrt> {x})>, where C<x belongs to B<I<Q>>>. X<quaddisc>The library syntax is B<quaddisc>C<(x)>. =head2 X<quadhilbert>quadhilbertC<(D,{pq})> relative equation defining the X<Hilbert class field>Hilbert class field of the quadratic field of discriminant C<D>. If C<D E<lt> 0>, uses complex multiplication (X<Schertz>Schertz's variant). The technical component C<pq>, if supplied, is a vector C<[p,q]> where C<p>, C<q> are the prime numbers needed for the Schertz's method. More precisely, prime ideals above C<p> and C<q> should be non-principal and coprime to all reduced representatives of the class group. In addition, if one of these ideals has order C<2> in the class group, they should have the same class. Finally, for efficiency, C<F<gcd>(24,(p-1)(q-1))> should be as large as possible. The routine returns C<0> if C<[p,q]> is not suitable. If C<D E<gt> 0> X<Stark units>Stark units are used and (in rare cases) a vector of extensions may be returned whose compositum is the requested class field. See C<bnrstark> for details. X<quadhilbert>The library syntax is B<quadhilbert>C<(D,pq,I<prec>)>. =head2 X<quadgen>quadgenC<(D)> X<Label se:quadgen>creates the quadratic numberX<omega> C<F<omega> = (a+ F<sqrt> {D})/2> where C<a = 0> if C<x = 0 mod 4>, C<a = 1> if C<D = 1 mod 4>, so that C<(1,F<omega>)> is an integral basis for the quadratic order of discriminant C<D>. C<D> must be an integer congruent to 0 or 1 modulo 4, which is not a square. X<quadgen>The library syntax is B<quadgen>C<(x)>. =head2 X<quadpoly>quadpolyC<(D,{v = x})> creates the ``canonical'' quadratic polynomial (in the variable C<v>) corresponding to the discriminant C<D>, i.e.S< >the minimal polynomial of C<quadgen(D)>. C<D> must be an integer congruent to 0 or 1 modulo 4, which is not a square. X<quadpoly0>The library syntax is B<quadpoly0>C<(x,v)>. =head2 X<quadray>quadrayC<(D,f,{I<lambda>})> relative equation for the ray class field of conductor C<f> for the quadratic field of discriminant C<D> using analytic methods. A C<bnf> for C<x^2 - D> is also accepted in place of C<D>. For C<D E<lt> 0>, uses the C<F<sigma>> function. If supplied, I<lambda> is is the technical element C<F<lambda>> of C<bnf> necessary for Schertz's method. In that case, returns 0 if C<F<lambda>> is not suitable. For C<D E<gt> 0>, uses Stark's conjecture, and a vector of relative equations may be returned. See X<bnrstark>C<bnrstark> for more details. X<quadray>The library syntax is B<quadray>C<(D,f,lambda,prec)>, where an omitted C<lambda> is coded as C<NULL>. =head2 X<quadregulator>quadregulatorC<(x)> regulator of the quadratic field of positive discriminant C<x>. Returns an error if C<x> is not a discriminant (fundamental or not) or if C<x> is a square. See also C<quadclassunit> if C<x> is large. X<regula>The library syntax is B<regula>C<(x,I<prec>)>. =head2 X<quadunit>quadunitC<(D)> fundamental unitX<fundamental units> of the real quadratic field C<B<I<Q>>( F<sqrt> D)> where C<D> is the positive discriminant of the field. If C<D> is not a fundamental discriminant, this probably gives the fundamental unit of the corresponding order. C<D> must be an integer congruent to 0 or 1 modulo 4, which is not a square; the result is a quadratic number (see L<Label se:quadgen>). X<fundunit>The library syntax is B<fundunit>C<(x)>. =head2 X<removeprimes>removeprimesC<({x = []})> removes the primes listed in C<x> from the prime number table. In particular C<removeprimes(addprimes)> empties the extra prime table. C<x> can also be a single integer. List the current extra primes if C<x> is omitted. X<removeprimes>The library syntax is B<removeprimes>C<(x)>. =head2 X<sigma>sigmaC<(x,{k = 1})> sum of the C<k^{th}> powers of the positive divisors of C<|x|>. C<x> and C<k> must be of type integer. X<sumdiv>The library syntax is B<sumdiv>C<(x)> ( = C< B<sigma>(x)>X<sigma>) or C< B<gsumdivk>(x,k)>X<gsumdivk> ( = C< B<sigma>(x,k)>X<sigma>), where C<k> is a C long integer. =head2 X<sqrtint>sqrtintC<(x)> integer square root of C<x>, which must be a non-negative integer. The result is non-negative and rounded towards zero. X<sqrti>The library syntax is B<sqrti>C<(x)>. Also available is X<sqrtremi>C<sqrtremi>C<(x,&r)> which returns C<s> such that C<s^2 = x+r>, with C<0 E<lt>= r E<lt>= 2s>. =head2 X<zncoppersmith>zncoppersmithC<(P, N, X, {B = N})> finds all integers C<x_0> with C<|x_0| E<lt>= X> such that S< >C<F<gcd>(N, P(x_0)) E<gt>= B.> If C<N> is prime or a prime power, X<polrootsmod>C<polrootsmod> or X<polrootspadic>C<polrootspadic> will be much faster. C<X> must be smaller than C< F<exp> ( F<log> ^2 B / ( F<deg> (P) F<log> N))>. X<zncoppersmith>The library syntax is B<zncoppersmith>C<(P, N, X, B)>, where an omitted C<B> is coded as C<NULL>. =head2 X<znlog>znlogC<(x,g)> C<g> must be a primitive root mod a prime C<p>, and the result is the discrete log of C<x> in the multiplicative group C<(B<I<Z>>/pB<I<Z>>)^*>. This function uses a simple-minded combination of Pohlig-Hellman algorithm and Shanks baby-step/giant-step which requires C<O( F<sqrt> {q})> storage, where C<q> is the largest prime factor of C<p-1>. Hence it cannot be used when the largest prime divisor of C<p-1> is greater than about C<10^{13}>. X<znlog>The library syntax is B<znlog>C<(x,g)>. =head2 X<znorder>znorderC<(x,{I<o>})> C<x> must be an integer mod C<n>, and the result is the order of C<x> in the multiplicative group C<(B<I<Z>>/nB<I<Z>>)^*>. Returns an error if C<x> is not invertible. If optional parameter C<o> is given it is assumed to be a multiple of the order (used to limit the search space). X<znorder>The library syntax is B<znorder>C<(x,o)>, where an omitted C<o> is coded as C<NULL>. Also available is C< B<order>(x)>X<order>. =head2 X<znprimroot>znprimrootC<(n)> returns a primitive root (generator) of C<(B<I<Z>>/nB<I<Z>>)^*>, whenever this latter group is cyclic (C<n = 4> or C<n = 2p^k> or C<n = p^k>, where C<p> is an odd prime and C<k E<gt>= 0>). X<gener>The library syntax is B<gener>C<(x)>. =head2 X<znstar>znstarC<(n)> gives the structure of the multiplicative group C<(B<I<Z>>/nB<I<Z>>)^*> as a 3-component row vector C<v>, where C<v[1] = F<phi>(n)> is the order of that group, C<v[2]> is a C<k>-component row-vector C<d> of integers C<d[i]> such that C<d[i] E<gt> 1> and C<d[i] | d[i-1]> for C<i E<gt>= 2> and C<(B<I<Z>>/nB<I<Z>>)^* ~ F<prod>_{i = 1}^k(B<I<Z>>/d[i]B<I<Z>>)>, and C<v[3]> is a C<k>-component row vector giving generators of the image of the cyclic groups C<B<I<Z>>/d[i]B<I<Z>>>. X<znstar>The library syntax is B<znstar>C<(n)>. =head1 Functions related to elliptic curves We have implemented a number of functions which are useful for number theorists working on elliptic curves. We always use X<Tate>Tate's notations. The functions assume that the curve is given by a general Weierstrass modelX<Weierstrass equation> S< >C< y^2+a_1xy+a_3y = x^3+a_2x^2+a_4x+a_6, > where a priori the C<a_i> can be of any scalar type. This curve can be considered as a five-component vector C<E = [a1,a2,a3,a4,a6]>. Points on C<E> are represented as two-component vectors C<[x,y]>, except for the point at infinity, i.e.S< >the identity element of the group law, represented by the one-component vector C<[0]>. It is useful to have at one's disposal more information. This is given by the function X<ellinit>C<ellinit> (see there), which initalizes and returns an X<ell>I<ell> structure by default. If a specific flag is added, a shortened X<sell>I<sell>, for small X<ell>I<ell>, is returned, which is much faster to compute but contains less information. The following X<member functions>member functions are available to deal with the output of C<ellinit>, both I<ell> and I<sell>: S< > C<a1>--C<a6>, C<b2>--C<b8>, C<c4>--C<c6> : coefficients of the elliptic curve. S< > X<area>C<area> : volume of the complex lattice defining C<E>. S< > X<disc>C<disc> : discriminant of the curve. S< > X<j>C<j> : C<j>-invariant of the curve. S< > X<omega>C<omega> : C<[F<omega>_1,F<omega>_2]>, periods forming a basis of the complex lattice defining C<E> (C<F<omega>_1> is the S< > real period, and C<F<omega>_2/F<omega>_1> belongs to PoincarE<eacute>'s half-plane). S< > X<eta>C<eta> : quasi-periods C<[F<eta>_1, F<eta>_2]>, such that C<F<eta>_1F<omega>_2-F<eta>_2F<omega>_1 = iF<Pi>>. S< > X<roots>C<roots> : roots of the associated Weierstrass equation. S< > X<tate>C<tate> : C<[u^2,u,v]> in the notation of Tate. S< > X<w>C<w> : Mestre's C<w> (this is technical). The member functions C<area>, C<eta> and C<omega> are only available for curves over B<I<Q>>. Conversely, C<tate> and C<w> are only available for curves defined over C<B<I<Q>>_p>. The use of member functions is best described by an example: ? E = ellinit([0,0,0,0,1]); \\ The curve y^2 = x^3 + 1 ? E.a6 %2 = 1 ? E.c6 %3 = -864 ? E.disc %4 = -432 Some functions, in particular those relative to height computations (see C<ellheight>) require also that the curve be in minimal Weierstrass form, which is duly stressed in their description below. This is achieved by the function C<ellminimalmodel>. \emph{Using a non-minimal model in such a routine will yield a wrong result!} All functions related to elliptic curves share the prefix C<ell>, and the precise curve we are interested in is always the first argument, in either one of the three formats discussed above, unless otherwise specified. The requirements are given as the \emph{minimal} ones: any richer structure may replace the ones requested. For instance, in functions which have no use for the extra information given by an X<ell>I<ell> structure, the curve can be given either as a five-component vector, as an I<sell>, or as an I<ell>; if an I<sell> is requested, an I<ell> may equally be given. =head2 X<elladd>elladdC<(E,z1,z2)> sum of the points C<z1> and C<z2> on the elliptic curve corresponding to C<E>. X<addell>The library syntax is B<addell>C<(E,z1,z2)>. =head2 X<ellak>ellakC<(E,n)> computes the coefficient C<a_n> of the C<L>-function of the elliptic curve C<E>, i.e.S< >in principle coefficients of a newform of weight 2 assuming X<Taniyama-Weil conjecture>Taniyama-Weil conjecture (which is now known to hold in full generality thanks to the work of X<Breuil>Breuil, X<Conrad>Conrad, X<Diamond>Diamond, X<Taylor>Taylor and X<Wiles>Wiles). C<E> must be an I<sell> as output by C<ellinit>. For this function to work for every C<n> and not just those prime to the conductor, C<E> must be a minimal Weierstrass equation. If this is not the case, use the function C<ellminimalmodel> before using C<ellak>. X<akell>The library syntax is B<akell>C<(E,n)>. =head2 X<ellan>ellanC<(E,n)> computes the vector of the first C<n> C<a_k> corresponding to the elliptic curve C<E>. All comments in C<ellak> description remain valid. X<anell>The library syntax is B<anell>C<(E,n)>, where C<n> is a C integer. =head2 X<ellap>ellapC<(E,p,{I<flag> = 0})> computes the C<a_p> corresponding to the elliptic curve C<E> and the prime number C<p>. These are defined by the equation C<#E(B<I<F>>_p) = p+1 - a_p>, where C<#E(B<I<F>>_p)> stands for the number of points of the curve C<E> over the finite field C<B<I<F>>_p>. When C<I<flag>> is C<0>, this uses the baby-step giant-step method and a trick due to Mestre. This runs in time C<O(p^{1/4})> and requires C<O(p^{1/4})> storage, hence becomes unreasonable when C<p> has about 30 digits. If C<I<flag>> is C<1>, computes the C<a_p> as a sum of Legendre symbols. This is slower than the previous method as soon as C<p> is greater than 100, say. No checking is done that C<p> is indeed prime. C<E> must be an I<sell> as output by C<ellinit>, defined over B<I<Q>>, C<B<I<F>>_p> or C<B<I<Q>>_p>. C<E> must be given by a Weierstrass equation minimal at C<p>. X<ellap0>The library syntax is B<ellap0>C<(E,p,I<flag>)>. Also available are C< B<apell>(E,p)>X<apell>, corresponding to C<I<flag> = 0>, and C< B<apell2>(E,p)>X<apell2> (C<I<flag> = 1>). =head2 X<ellbil>ellbilC<(E,z1,z2)> if C<z1> and C<z2> are points on the elliptic curve C<E>, assumed to be integral given by a minimal model, this function computes the value of the canonical bilinear form on C<z1>, C<z2>: S< >C< ( h(E,z1+z2) - h(E,z1) - h(E,z2) ) / 2 > where C<+> denotes of course addition on C<E>. In addition, C<z1> or C<z2> (but not both) can be vectors or matrices. X<bilhell>The library syntax is B<bilhell>C<(E,z1,z2,I<prec>)>. =head2 X<ellchangecurve>ellchangecurveC<(E,v)> changes the data for the elliptic curve C<E> by changing the coordinates using the vector C<v = [u,r,s,t]>, i.e.S< >if C<x'> and C<y'> are the new coordinates, then C<x = u^2x'+r>, C<y = u^3y'+su^2x'+t>. C<E> must be an I<sell> as output by C<ellinit>. X<coordch>The library syntax is B<coordch>C<(E,v)>. =head2 X<ellchangepoint>ellchangepointC<(x,v)> changes the coordinates of the point or vector of points C<x> using the vector C<v = [u,r,s,t]>, i.e.S< >if C<x'> and C<y'> are the new coordinates, then C<x = u^2x'+r>, C<y = u^3y'+su^2x'+t> (see also C<ellchangecurve>). X<pointch>The library syntax is B<pointch>C<(x,v)>. =head2 X<ellconvertname>ellconvertnameC<(I<name>)> converts an elliptic curve name, as found in the X<elldata>C<elldata> database, from a string to a triplet C<[I<conductor>, I<isogeny class>, I<index>]>. It will also convert a triplet back to a curve name. Examples: ? ellconvertname("123b1") %1 = [123, 1, 1] ? ellconvertname(%) %2 = "123b1" X<ellconvertname>The library syntax is B<ellconvertname>C<(I<name>)>. =head2 X<elleisnum>elleisnumC<(E,k,{I<flag> = 0})> C<E> being an elliptic curve as output by C<ellinit> (or, alternatively, given by a 2-component vector C<[F<omega>_1,F<omega>_2]> representing its periods), and C<k> being an even positive integer, computes the numerical value of the Eisenstein series of weight C<k> at C<E>, namely S< >C< (2i F<Pi>/F<omega>_2)^k \Big(1 + 2/F<zeta>(1-k) F<sum>_{n E<gt>= 0} n^{k-1}q^n / (1-q^n)\Big), > where C<q = e(F<omega>_1/F<omega>_2)>. When I<flag> is non-zero and C<k = 4> or 6, returns the elliptic invariants C<g_2> or C<g_3>, such that S< >C<y^2 = 4x^3 - g_2 x - g_3> is a Weierstrass equation for C<E>. X<elleisnum>The library syntax is B<elleisnum>C<(E,k,I<flag>)>. =head2 X<elleta>elletaC<(om)> returns the two-component row vector C<[F<eta>_1,F<eta>_2]> of quasi-periods associated to C<om = [F<omega>_1, F<omega>_2]> X<elleta>The library syntax is B<elleta>C<(om, I<prec>)> =head2 X<ellgenerators>ellgeneratorsC<(E)> returns a B<I<Z>>-basis of the free part of the X<Mordell-Weil group>Mordell-Weil group associated to C<E>. This function depends on the X<elldata>C<elldata> database being installed and referencing the curve, and so is only available for curves over B<I<Z>> of small conductors. X<ellgenerators>The library syntax is B<ellgenerators>C<(E)>. =head2 X<ellglobalred>ellglobalredC<(E)> calculates the arithmetic conductor, the global minimal model of C<E> and the global X<Tamagawa number>Tamagawa number C<c>. C<E> must be an I<sell> as output by C<ellinit>, \emph{and is supposed to have all its coefficients C<a_i> in} B<I<Q>>. The result is a 3 component vector C<[N,v,c]>. C<N> is the arithmetic conductor of the curve. C<v> gives the coordinate change for C<E> over B<I<Q>> to the minimal integral model (see X<ellminimalmodel>C<ellminimalmodel>). Finally C<c> is the product of the local Tamagawa numbers C<c_p>, a quantity which enters in the X<Birch and Swinnerton-Dyer conjecture>Birch and Swinnerton-Dyer conjecture.X<minimal model> X<ellglobalred>The library syntax is B<ellglobalred>C<(E)>. =head2 X<ellheight>ellheightC<(E,z,{I<flag> = 2})> global X<NE<eacute>ron-Tate height>NE<eacute>ron-Tate height of the point C<z> on the elliptic curve C<E> (defined over B<I<Q>>), given by a standard minimal integral model. C<E> must be an C<ell> as output by C<ellinit>. I<flag> selects the algorithm used to compute the archimedean local height. If C<I<flag> = 0>, this computation is done using sigma and theta-functions and a trick due to J. Silverman. If C<I<flag> = 1>, use Tate's C<4^n> algorithm. If C<I<flag> = 2>, use Mestre's AGM algorithm. The latter is much faster than the other two, both in theory (converges quadratically) and in practice. X<ellheight0>The library syntax is B<ellheight0>C<(E,z,I<flag>,I<prec>)>. Also available are C< B<ghell>(E,z,I<prec>)>X<ghell> (C<I<flag> = 0>) and C< B<ghell2>(E,z,I<prec>)>X<ghell2> (C<I<flag> = 1>). =head2 X<ellheightmatrix>ellheightmatrixC<(E,x)> C<x> being a vector of points, this function outputs the Gram matrix of C<x> with respect to the NE<eacute>ron-Tate height, in other words, the C<(i,j)> component of the matrix is equal to C<ellbil(E,x[i],x[j])>. The rank of this matrix, at least in some approximate sense, gives the rank of the set of points, and if C<x> is a basis of the X<Mordell-Weil group>Mordell-Weil group of C<E>, its determinant is equal to the regulator of C<E>. Note that this matrix should be divided by 2 to be in accordance with certain normalizations. C<E> is assumed to be integral, given by a minimal model. X<mathell>The library syntax is B<mathell>C<(E,x,I<prec>)>. =head2 X<ellidentify>ellidentifyC<(E)> look up the elliptic curve C<E> (over B<I<Z>>) in the X<elldata>C<elldata> database and return C<[[N, M, G], C]> where C<N> is the name of the curve in J. E. Cremona database, C<M> the minimal model, C<G> a B<I<Z>>-basis of the free part of the X<Mordell-Weil group>Mordell-Weil group of C<E> and C<C> the coordinates change (see C<ellchangecurve>). X<ellidentify>The library syntax is B<ellidentify>C<(E)>. =head2 X<ellinit>ellinitC<(E,{I<flag> = 0})> initialize an X<ell>C<ell> structure, associated to the elliptic curve C<E>. C<E> is a C<5>-component vector C<[a_1,a_2,a_3,a_4,a_6]> defining the elliptic curve with Weierstrass equation S< >C< Y^2 + a_1 XY + a_3 Y = X^3 + a_2 X^2 + a_4 X + a_6 > or a string, in this case the coefficients of the curve with matching name are looked in the X<elldata>C<elldata> database if available. For the time being, only curves over a prime field C<B<I<F>>_p> and over the C<p>-adic or real numbers (including rational numbers) are fully supported. Other domains are only supported for very basic operations such as point addition. The result of X<ellinit>C<ellinit> is a an X<ell>I<ell> structure by default, and a shorted X<sell>I<sell> if C<I<flag> = 1>. Both contain the following information in their components: S< >C< a_1,a_2,a_3,a_4,a_6,b_2,b_4,b_6,b_8,c_4,c_6,F<Delta>,j.> All are accessible via member functions. In particular, the discriminant is C<E.disc>, and the C<j>-invariant is C<E.j>. The other six components are only present if C<I<flag>> is C<0> or omitted. Their content depends on whether the curve is defined over B<I<R>> or not: \item When C<E> is defined over B<I<R>>, C<E.roots> is a vector whose three components contain the roots of the right hand side of the associated Weierstrass equation. S< >C< (y + a_1x/2 + a_3/2)^2 = g(x) > If the roots are all real, then they are ordered by decreasing value. If only one is real, it is the first component. Then C<F<omega>_1 = >C<E.omega[1]> is the real period of C<E> (integral of C<dx/(2y+a_1x+a_3)> over the connected component of the identity element of the real points of the curve), and C<F<omega>_2 = >C<E.omega[2]> is a complex period. In other words, C<E.omega> forms a basis of the complex lattice defining C<E>, with C<F<tau> = (F<omega>_2)/(F<omega>_1)> having positive imaginary part. C<E.eta> is a row vector containing the corresponding values C<F<eta>_1> and C<F<eta>_2> such that C<F<eta>_1F<omega>_2-F<eta>_2F<omega>_1 = iF<Pi>>. Finally, C<E.area> is the volume of the complex lattice defining C<E>. \item When C<E> is defined over C<B<I<Q>>_p>, the C<p>-adic valuation of C<j> must be negative. Then C<E.roots> is the vector with a single component equal to the C<p>-adic root of the associated Weierstrass equation corresponding to C<-1> under the Tate parametrization. C<E.tate> yields the three-component vector C<[u^2,u,q]>, in the notations of Tate. If the C<u>-component does not belong to C<B<I<Q>>_p>, it is set to zero. C<E.w> is Mestre's C<w> (this is technical). For all other base fields or rings, the last six components are arbitrarily set equal to zero. See also the description of member functions related to elliptic curves at the beginning of this section. X<ellinit0>The library syntax is B<ellinit0>C<(E,I<flag>,I<prec>)>. Also available are C< B<initell>(E,I<prec>)>X<initell> (C<I<flag> = 0>) and C< B<smallinitell>(E,I<prec>)>X<smallinitell> (C<I<flag> = 1>). =head2 X<ellisoncurve>ellisoncurveC<(E,z)> gives 1 (i.e.S< >true) if the point C<z> is on the elliptic curve C<E>, 0 otherwise. If C<E> or C<z> have imprecise coefficients, an attempt is made to take this into account, i.e.S< >an imprecise equality is checked, not a precise one. It is allowed for C<z> to be a vector of points in which case a vector (of the same type) is returned. X<ellisoncurve>The library syntax is B<ellisoncurve>C<(E,z)>. Also available is C< B<oncurve>(E,z)>X<oncurve> which returns a C<long> but does not accept vector of points. =head2 X<ellj>elljC<(x)> elliptic C<j>-invariant. C<x> must be a complex number with positive imaginary part, or convertible into a power series or a C<p>-adic number with positive valuation. X<jell>The library syntax is B<jell>C<(x,I<prec>)>. =head2 X<elllocalred>elllocalredC<(E,p)> calculates the X<Kodaira>Kodaira type of the local fiber of the elliptic curve C<E> at the prime C<p>. C<E> must be an I<sell> as output by C<ellinit>, and is assumed to have all its coefficients C<a_i> in B<I<Z>>. The result is a 4-component vector C<[f,kod,v,c]>. Here C<f> is the exponent of C<p> in the arithmetic conductor of C<E>, and C<kod> is the Kodaira type which is coded as follows: 1 means good reduction (type IC<_0>), 2, 3 and 4 mean types II, III and IV respectively, C<4+F<nu>> with C<F<nu> E<gt> 0> means type IC<_F<nu>>; finally the opposite values C<-1>, C<-2>, etc.S< >refer to the starred types IC<_0^*>, IIC<^*>, etc. The third component C<v> is itself a vector C<[u,r,s,t]> giving the coordinate changes done during the local reduction. Normally, this has no use if C<u> is 1, that is, if the given equation was already minimal. Finally, the last component C<c> is the local X<Tamagawa number>Tamagawa number C<c_p>. X<elllocalred>The library syntax is B<elllocalred>C<(E,p)>. =head2 X<elllseries>elllseriesC<(E,s,{A = 1})> C<E> being an I<sell> as output by C<ellinit>, this computes the value of the L-series of C<E> at C<s>. It is assumed that C<E> is defined over B<I<Q>>, not necessarily minimal. The optional parameter C<A> is a cutoff point for the integral, which must be chosen close to 1 for best speed. The result must be independent of C<A>, so this allows some internal checking of the function. Note that if the conductor of the curve is large, say greater than C<10^{12}>, this function will take an unreasonable amount of time since it uses an C<O(N^{1/2})> algorithm. X<elllseries>The library syntax is B<elllseries>C<(E,s,A,I<prec>)> where C<I<prec>> is a C<long> and an omitted C<A> is coded as C<NULL>. =head2 X<ellminimalmodel>ellminimalmodelC<(E,{&v})> return the standard minimal integral model of the rational elliptic curve C<E>. If present, sets C<v> to the corresponding change of variables, which is a vector C<[u,r,s,t]> with rational components. The return value is identical to that of C<ellchangecurve(E, v)>. The resulting model has integral coefficients, is everywhere minimal, C<a_1> is 0 or 1, C<a_2> is 0, 1 or C<-1> and C<a_3> is 0 or 1. Such a model is unique, and the vector C<v> is unique if we specify that C<u> is positive, which we do. X<minimal model> X<ellminimalmodel>The library syntax is B<ellminimalmodel>C<(E,&v)>, where an omitted C<v> is coded as C<NULL>. =head2 X<ellorder>ellorderC<(E,z)> gives the order of the point C<z> on the elliptic curve C<E> if it is a torsion point, zero otherwise. In the present version B<2.2.0>, this is implemented only for elliptic curves defined over B<I<Q>>. X<orderell>The library syntax is B<orderell>C<(E,z)>. =head2 X<ellordinate>ellordinateC<(E,x)> gives a 0, 1 or 2-component vector containing the C<y>-coordinates of the points of the curve C<E> having C<x> as C<x>-coordinate. X<ordell>The library syntax is B<ordell>C<(E,x)>. =head2 X<ellpointtoz>ellpointtozC<(E,z)> if C<E> is an elliptic curve with coefficients in B<I<R>>, this computes a complex number C<t> (modulo the lattice defining C<E>) corresponding to the point C<z>, i.e.S< >such that, in the standard Weierstrass model, C< F<wp> (t) = z[1], F<wp> '(t) = z[2]>. In other words, this is the inverse function of C<ellztopoint>. More precisely, if C<(w1,w2)> are the real and complex periods of C<E>, C<t> is such that C<0 E<lt>= F<Re> (t) E<lt> w1> and C<0 E<lt>= F<Im> (t) E<lt> F<Im> (w2)>. If C<E> has coefficients in C<B<I<Q>>_p>, then either Tate's C<u> is in C<B<I<Q>>_p>, in which case the output is a C<p>-adic number C<t> corresponding to the point C<z> under the Tate parametrization, or only its square is, in which case the output is C<t+1/t>. C<E> must be an I<ell> as output by C<ellinit>. X<zell>The library syntax is B<zell>C<(E,z,I<prec>)>. =head2 X<ellpow>ellpowC<(E,z,n)> computes C<n> times the point C<z> for the group law on the elliptic curve C<E>. Here, C<n> can be in B<I<Z>>, or C<n> can be a complex quadratic integer if the curve C<E> has complex multiplication by C<n> (if not, an error message is issued). X<powell>The library syntax is B<powell>C<(E,z,n)>. =head2 X<ellrootno>ellrootnoC<(E,{p = 1})> C<E> being an I<sell> as output by C<ellinit>, this computes the local (if C<p ! = 1>) or global (if C<p = 1>) root number of the L-series of the elliptic curve C<E>. Note that the global root number is the sign of the functional equation and conjecturally is the parity of the rank of the X<Mordell-Weil group>Mordell-Weil group. The equation for C<E> must have coefficients in B<I<Q>> but need \emph{not} be minimal. X<ellrootno>The library syntax is B<ellrootno>C<(E,p)> and the result (equal to C<F<+->1>) is a C<long>. =head2 X<ellsigma>ellsigmaC<(E,z,{I<flag> = 0})> value of the Weierstrass C<F<sigma>> function of the lattice associated to C<E> as given by C<ellinit> (alternatively, C<E> can be given as a lattice C<[F<omega>_1,F<omega>_2]>). If C<I<flag> = 1>, computes an (arbitrary) determination of C< F<log> (F<sigma>(z))>. If C<I<flag> = 2,3>, same using the product expansion instead of theta series. X<ellsigma>The library syntax is B<ellsigma>C<(E,z,I<flag>)> =head2 X<ellsearch>ellsearchC<(N)> if C<N> is an integer, it is taken as a conductor else if C<N> is a string, it can be a curve name ("11a1"), a isogeny class ("11a") or a conductor "11". This function finds all curves in the X<elldata>C<elldata> database with the given property. If C<N> is a full curve name, the output format is C<[N, [a_1,a_2,a_3,a_4,a_6], G]> where C<[a_1,a_2,a_3,a_4,a_6]> are the coefficients of the Weierstrass equation of the curve and C<G> is a B<I<Z>>-basis of the free part of the X<Mordell-Weil group>Mordell-Weil group associated to the curve. If C<N> is not a full-curve name, the output is the list (as a vector) of all matching curves in the above format. X<ellsearch>The library syntax is B<ellsearch>C<(N)>. Also available is C< B<ellsearchcurve>(N)>X<ellsearchcurve> that only accept complete curve names. =head2 X<ellsub>ellsubC<(E,z1,z2)> difference of the points C<z1> and C<z2> on the elliptic curve corresponding to C<E>. X<subell>The library syntax is B<subell>C<(E,z1,z2)>. =head2 X<elltaniyama>elltaniyamaC<(E)> computes the modular parametrization of the elliptic curve C<E>, where C<E> is an I<sell> as output by C<ellinit>, in the form of a two-component vector C<[u,v]> of power series, given to the current default series precision. This vector is characterized by the following two properties. First the point C<(x,y) = (u,v)> satisfies the equation of the elliptic curve. Second, the differential C<du/(2v+a_1u+a_3)> is equal to C<f(z)dz>, a differential form on C<H/F<Gamma>_0(N)> where C<N> is the conductor of the curve. The variable used in the power series for C<u> and C<v> is C<x>, which is implicitly understood to be equal to C< F<exp> (2iF<Pi> z)>. It is assumed that the curve is a \emph{strong} X<Weil curve>Weil curve, and that the Manin constant is equal to 1. The equation of the curve C<E> must be minimal (use C<ellminimalmodel> to get a minimal equation). X<elltaniyama>The library syntax is B<elltaniyama>C<(E, prec)>, and the precision of the result is determined by C<prec>. =head2 X<elltors>elltorsC<(E,{I<flag> = 0})> if C<E> is an elliptic curve \emph{defined over B<I<Q>>}, outputs the torsion subgroup of C<E> as a 3-component vector C<[t,v1,v2]>, where C<t> is the order of the torsion group, C<v1> gives the structure of the torsion group as a product of cyclic groups (sorted by decreasing order), and C<v2> gives generators for these cyclic groups. C<E> must be an I<ell> as output by C<ellinit>. ? E = ellinit([0,0,0,-1,0]); ? elltors(E) %1 = [4, [2, 2], [[0, 0], [1, 0]]] Here, the torsion subgroup is isomorphic to C<B<I<Z>>/2B<I<Z>> x B<I<Z>>/2B<I<Z>>>, with generators C<[0,0]> and C<[1,0]>. If C<I<flag> = 0>, use Doud's algorithm: bound torsion by computing C<#E(B<I<F>>_p)> for small primes of good reduction, then look for torsion points using Weierstrass parametrization (and Mazur's classification). If C<I<flag> = 1>, use Lutz-Nagell (\emph{much} slower), C<E> is allowed to be an I<sell>. X<elltors0>The library syntax is B<elltors0>C<(E,flag)>. =head2 X<ellwp>ellwpC<(E,{z = x},{I<flag> = 0})> Computes the value at C<z> of the Weierstrass C< F<wp> > function attached to the elliptic curve C<E> as given by C<ellinit> (alternatively, C<E> can be given as a lattice C<[F<omega>_1,F<omega>_2]>). If C<z> is omitted or is a simple variable, computes the \emph{power series} expansion in C<z> (starting C<z^{-2}+O(z^2)>). The number of terms to an \emph{even} power in the expansion is the default serieslength in C<gp>, and the second argument (C long integer) in library mode. Optional I<flag> is (for now) only taken into account when C<z> is numeric, and means 0: compute only C< F<wp> (z)>, 1: compute C<[ F<wp> (z), F<wp> '(z)]>. X<ellwp0>The library syntax is B<ellwp0>C<(E,z,I<flag>,I<prec>,I<precdl>)>. Also available is C< B<weipell>(E,I<precdl>)>X<weipell> for the power series. =head2 X<ellzeta>ellzetaC<(E,z)> value of the Weierstrass C<F<zeta>> function of the lattice associated to C<E> as given by C<ellinit> (alternatively, C<E> can be given as a lattice C<[F<omega>_1,F<omega>_2]>). X<ellzeta>The library syntax is B<ellzeta>C<(E,z)>. =head2 X<ellztopoint>ellztopointC<(E,z)> C<E> being an I<ell> as output by C<ellinit>, computes the coordinates C<[x,y]> on the curve C<E> corresponding to the complex number C<z>. Hence this is the inverse function of C<ellpointtoz>. In other words, if the curve is put in Weierstrass form, C<[x,y]> represents the X<Weierstrass F<wp> -function>Weierstrass C< F<wp> >-function and its derivative. If C<z> is in the lattice defining C<E> over B<I<C>>, the result is the point at infinity C<[0]>. X<pointell>The library syntax is B<pointell>C<(E,z,I<prec>)>. =head1 Functions related to general number fields In this section can be found functions which are used almost exclusively for working in general number fields. Other less specific functions can be found in the next section on polynomials. Functions related to quadratic number fields are found in section L<Label se:arithmetic> (Arithmetic functions). =head2 Number field structures Let C<K = B<I<Q>>[X] / (T)> a number field, C<B<I<Z>>_K> its ring of integers, C<T belongs to B<I<Z>>[X]> is monic. Three basic number field structures can be associated to C<K> in GP: \item C<X<nf>I<nf>> denotes a number field, i.e.S< >a data structure output by X<nfinit>C<nfinit>. This contains the basic arithmetic data associated to the number field: signature, maximal order (given by a basis C<nf.zk>), discriminant, defining polynomial C<T>, etc. \item C<X<bnf>I<bnf>> denotes a ``Buchmann's number field'', i.e.S< >a data structure output by X<bnfinit>C<bnfinit>. This contains C<I<nf>> and the deeper invariants of the field: units C<U(K)>, class group C<\Cl(K)>, as well as technical data required to solve the two associated discrete logarithm problems. \item C<X<bnr>I<bnr>> denotes a ``ray number field'', i.e.S< >a data structure output by C<bnrinit>, corresponding to the ray class group structure of the field, for some modulus C<f>. It contains a I<bnf>, the modulus C<f>, the ray class group C<\Cl_f(K)> and data associated to the discrete logarithm problem therein. =head2 Algebraic numbers and ideals An X<algebraic number>I<algebraic number> belonging to C<K = B<I<Q>>[X]/(T)> is given as \item a C<t_INT>, C<t_FRAC> or C<t_POL> (implicitly modulo C<T>), or \item a C<t_POLMOD> (modulo C<T>), or \item a C<t_COL>S< >C<v> of dimension C<N = [K:B<I<Q>>]>, representing the element in terms of the computed integral basis, as C<sum(i = 1, N,S< >v[i] * nf.zk[i])>. Note that a C<t_VEC> will not be recognized. An X<ideal>I<ideal> is given in any of the following ways: \item an algebraic number in one of the above forms, defining a principal ideal. \item a prime ideal, i.e.S< >a 5-component vector in the format output by C<idealprimedec>. \item a C<t_MAT>, square and in Hermite Normal Form (or at least upper triangular with non-negative coefficients), whose columns represent a basis of the ideal. One may use C<idealhnf> to convert an ideal to the last (preferred) format. B<Note.> Some routines accept non-square matrices, but using this format is strongly discouraged. Nevertheless, their behaviour is as follows: If strictly less than C<N = [K:B<I<Q>>]> generators are given, it is assumed they form a C<B<I<Z>>_K>-basis. If C<N> or more are given, a B<I<Z>>-basis is assumed. If exactly C<N> are given, it is further assumed the matrix is in HNF. If any of these assumptions is not correct the behaviour of the routine is undefined. \item an X<idele>I<idele> is a 2-component vector, the first being an ideal as above, the second being a C<R_1+R_2>-component row vector giving Archimedean information, as complex numbers. =head2 Finite abelian groups A finite abelian group C<G> in user-readable format is given by its Smith Normal Form as a pair C<[h,d]> or triple C<[h,d,g]>. Here C<h> is the cardinality of C<G>, C<(d_i)> is the vector of elementary divisors, and C<(g_i)> is a vector of generators. In short, C<G = F<oplus> _{i E<lt>= n} (B<I<Z>>/d_iB<I<Z>>) g_i>, with C<d_n | ... | d_2 | d_1> and C<F<prod> d_i = h>. This information can also be retrieved as C<G.no>, C<G.cyc> and C<G.gen>. \item a X<character>I<character> on the abelian group C< F<oplus> (B<I<Z>>/d_iB<I<Z>>) g_i> is given by a row vector C<F<chi> = [a_1,...,a_n]> such that C<F<chi>(F<prod> g_i^{n_i}) = F<exp> (2iF<Pi>F<sum> a_i n_i / d_i)>. \item given such a structure, a X<subgroup>I<subgroup> C<H> is input as a square matrix, whose column express generators of C<H> on the given generators C<g_i>. Note that the absolute value of the determinant of that matrix is equal to the index C<(G:H)>. =head2 Relative extensions When defining a relative extension, the base field C<I<nf>> must be defined by a variable having a lower priority (see L<Label se:priority>) than the variable defining the extension. For example, you may use the variable name C<y> to define the base field, and C<x> to define the relative extension. \item C<X<rnf>I<rnf>> denotes a relative number field, i.e.S< >a data structure output by C<rnfinit>. \item A \emph{relative matrix} is a matrix whose entries are elements of a (fixed) number field C<I<nf>>, always expressed as column vectors on the integral basis C<I<nf>.zk>. Hence it is a matrix of vectors. \item An X<ideal list>I<ideal list> is a row vector of (fractional) ideals of the number field C<I<nf>>. \item A X<pseudo-matrix>I<pseudo-matrix> is a pair C<(A,I)> where C<A> is a relative matrix and C<I> an ideal list whose length is the same as the number of columns of C<A>. This pair is represented by a 2-component row vector. \item The X<projective module>I<projective module> generated by a pseudo-matrix C<(A,I)> is the sum C<F<sum>_i {B<I<a>>}_j A_j> where the C<{B<I<a>>}_j> are the ideals of C<I> and C<A_j> is the C<j>-th column of C<A>. \item A pseudo-matrix C<(A,I)> is a X<pseudo-basis>I<pseudo-basis> of the module it generates if C<A> is a square matrix with non-zero determinant and all the ideals of C<I> are non-zero. We say that it is in Hermite Normal FormX<Hermite normal form> (HNF) if it is upper triangular and all the elements of the diagonal are equal to 1. \item The \emph{determinant} of a pseudo-basis C<(A,I)> is the ideal equal to the product of the determinant of C<A> by all the ideals of C<I>. The determinant of a pseudo-matrix is the determinant of any pseudo-basis of the module it generates. =head2 Class field theory A C<X<modulus>I<modulus>>, in the sense of class field theory, is a divisor supported on the non-complex places of C<K>. In PARI terms, this means either an ordinary ideal C<I> as above (no archimedean component), or a pair C<[I,a]>, where C<a> is a vector with C<r_1> C<{0,1}>-components, corresponding to the infinite part of the divisor. More precisely, the C<i>-th component of C<a> corresponds to the real embedding associated to the C<i>-th real root of C<K.roots>. (That ordering is not canonical, but well defined once a defining polynomial for C<K> is chosen.) For instance, C<[1, [1,1]]> is a modulus for a real quadratic field, allowing ramification at any of the two places at infinity. A X<bid>I<bid> or ``big ideal'' is a structure output by C<idealstar> needed to compute in C<(B<I<Z>>_K/I)^*>, where C<I> is a modulus in the above sense. If is a finite abelian group as described above, supplemented by technical data needed to solve discrete log problems. Finally we explain how to input ray number fields (or I<bnr>), using class field theory. These are defined by a triple C<a1>, C<a2>, C<a3>, where the defining set C<[a1,a2,a3]> can have any of the following forms: C<[I<bnr>]>, C<[I<bnr>,I<subgroup>]>, C<[I<bnf>,I<module>]>, C<[I<bnf>,I<module>,I<subgroup>]>. \item C<I<bnf>> is as output by C<bnfinit>, where units are mandatory unless the modulus is trivial; I<bnr> is as output by C<bnrinit>. This is the ground field C<K>. \item \emph{module} is a modulus C<\goth{f}>, as described above. \item \emph{subgroup} a subgroup of the ray class group modulo C<\goth{f}> of C<K>. As described above, this is input as a square matrix expressing generators of a subgroup of the ray class group C<I<bnr>.clgp> on the given generators. The corresponding I<bnr> is the subfield of the ray class field of C<K> modulo C<\goth{f}>, fixed by the given subgroup. =head2 General use All the functions which are specific to relative extensions, number fields, Buchmann's number fields, Buchmann's number rays, share the prefix C<rnf>, C<nf>, C<bnf>, C<bnr> respectively. They take as first argument a number field of that precise type, respectively output by C<rnfinit>, C<nfinit>, C<bnfinit>, and C<bnrinit>. However, and even though it may not be specified in the descriptions of the functions below, it is permissible, if the function expects a C<I<nf>>, to use a C<I<bnf>> instead, which contains much more information. On the other hand, if the function requires a C<bnf>, it will \emph{not} launch C<bnfinit> for you, which is a costly operation. Instead, it will give you a specific error message. In short, the types S< >C< nf E<lt>= bnf E<lt>= bnr> are ordered, each function requires a minimal type to work properly, but you may always substitute a larger type. The data types corresponding to the structures described above are rather complicated. Thus, as we already have seen it with elliptic curves, GP provides ``member functions'' to retrieve data from these structures (once they have been initialized of course). The relevant types of number fields are indicated between parentheses: X<member functions> S< >X<bid>C<bid> (I<bnr>, ) : bid ideal structure. S< >X<bnf>C<bnf> (I<bnr>, I<bnf> ) : Buchmann's number field. S< >X<clgp>C<clgp> (I<bnr>, I<bnf> ) : classgroup. This one admits the following three subclasses: S< > X<cyc>C<cyc> : cyclic decomposition (SNF)X<Smith normal form>. S< > C<gen>X<gen (member function)> : generators. S< > X<no>C<no> : number of elements. S< >X<diff>C<diff> (I<bnr>, I<bnf>, I<nf> ) : the different ideal. S< >X<codiff>C<codiff> (I<bnr>, I<bnf>, I<nf> ) : the codifferent (inverse of the different in the ideal group). S< >X<disc>C<disc> (I<bnr>, I<bnf>, I<nf> ) : discriminant. S< >X<fu>C<fu> (I<bnr>, I<bnf>, I<nf> ) : X<fundamental units>fundamental units. S< >X<index>C<index> (I<bnr>, I<bnf>, I<nf> ) : X<index>index of the power order in the ring of integers. S< >X<nf>C<nf> (I<bnr>, I<bnf>, I<nf> ) : number field. S< >X<r1>C<r1> (I<bnr>, I<bnf>, I<nf> ) : the number of real embeddings. S< >X<r2>C<r2> (I<bnr>, I<bnf>, I<nf> ) : the number of pairs of complex embeddings. S< >X<reg>C<reg> (I<bnr>, I<bnf>, ) : regulator. S< >X<roots>C<roots> (I<bnr>, I<bnf>, I<nf> ) : roots of the polynomial generating the field. S< >X<t2>C<t2> (I<bnr>, I<bnf>, I<nf> ) : the T2 matrix (see C<nfinit>). S< >X<tu>C<tu> (I<bnr>, I<bnf>, ) : a generator for the torsion units. S< >X<tufu>C<tufu> (I<bnr>, I<bnf>, ) : C<[w,u_1,...,u_r]>, C<(u_i)> is a vector of fundamental units, C<w> generates the torsion units. S< >X<zk>C<zk> (I<bnr>, I<bnf>, I<nf> ) : integral basis, i.e.S< >a B<I<Z>>-basis of the maximal order. For instance, assume that C<I<bnf> = bnfinit(I<pol>)>, for some polynomial. Then C<I<bnf>.clgp> retrieves the class group, and C<I<bnf>.clgp.no> the class number. If we had set C<I<bnf> = nfinit(I<pol>)>, both would have output an error message. All these functions are completely recursive, thus for instance C<I<bnr>.bnf.nf.zk> will yield the maximal order of I<bnr>, which you could get directly with a simple C<I<bnr>.zk>. =head2 Class group, units, and the GRH X<Label se:GRHbnf> Some of the functions starting with C<bnf> are implementations of the sub-exponential algorithms for finding class and unit groups under X<GRH>GRH, due to Hafner-McCurley, X<Buchmann>Buchmann and Cohen-Diaz-Olivier. The general call to the functions concerning class groups of general number fields (i.e.S< >excluding C<quadclassunit>) involves a polynomial C<P> and a technical vector S< >C<I<tech> = [c, c2, I<nrpid> ],> where the parameters are to be understood as follows: C<P> is the defining polynomial for the number field, which must be in C<B<I<Z>>[X]>, irreducible and monic. In fact, if you supply a non-monic polynomial at this point, C<gp> issues a warning, then \emph{transforms your polynomial} so that it becomes monic. The C<nfinit> routine will return a different result in this case: instead of C<res>, you get a vector C<[res,Mod(a,Q)]>, where C<Mod(a,Q) = Mod(X,P)> gives the change of variables. In all other routines, the variable change is simply lost. The numbers C<c E<lt>= c_2> are positive real numbers which control the execution time and the stack size. For a given C<c>, set C<c_2 = c> to get maximum speed. To get a rigorous result under X<GRH>GRH you must take C<c2 E<gt>= 12> (or C<c2 E<gt>= 6> in C<P> is quadratic). Reasonable values for C<c> are between C<0.1> and C<2>. The default is C<c = c_2 = 0.3>. C<I<nrpid>> is the maximal number of small norm relations associated to each ideal in the factor base. Set it to C<0> to disable the search for small norm relations. Otherwise, reasonable values are between 4 and 20. The default is 4. B<Warning.> Make sure you understand the above! By default, most of the C<bnf> routines depend on the correctness of a heuristic assumption which is stronger than the GRH. In particular, any of the class number, class group structure, class group generators, regulator and fundamental units may be wrong, independently of each other. Any result computed from such a C<bnf> may be wrong. The only guarantee is that the units given generate a subgroup of finite index in the full unit group. In practice, very few counter-examples are known, requiring unlucky random seeds. No counter-example has been reported for C<c_2 = 0.5> (which should be almost as fast as C<c_2 = 0.3>, and shall very probably become the default). If you use C<c_2 = 12>, then everything is correct assuming the GRH holds. You can use C<bnfcertify> to certify the computations unconditionally. B<Remarks.> Apart from the polynomial C<P>, you do not need to supply the technical parameters (under the library you still need to send at least an empty vector, coded as C<NULL>). However, should you choose to set some of them, they \emph{must} be given in the requested order. For example, if you want to specify a given value of I<nrpid>, you must give some values as well for C<c> and C<c_2>, and provide a vector C<[c,c_2,I<nrpid>]>. Note also that you can use an C<I<nf>> instead of C<P>, which avoids recomputing the integral basis and analogous quantities. =head2 X<bnfcertify>bnfcertifyC<(I<bnf>)> C<I<bnf>> being as output by C<bnfinit>, checks whether the result is correct, i.e.S< >whether it is possible to remove the assumption of the Generalized Riemann HypothesisX<GRH>. It is correct if and only if the answer is 1. If it is incorrect, the program may output some error message, or loop indefinitely. You can check its progress by increasing the debug level. X<certifybuchall>The library syntax is B<certifybuchall>C<(I<bnf>)>, and the result is a C long. =head2 X<bnfclassunit>bnfclassunitC<(P,{I<flag> = 0},{I<tech> = []})> \emph{this function is DEPRECATED, use C<bnfinit>}. X<Buchmann>Buchmann's sub-exponential algorithm for computing the class group, the regulator and a system of X<fundamental units>fundamental units of the general algebraic number field C<K> defined by the irreducible polynomial C<P> with integer coefficients. The result of this function is a vector C<v> with many components, which for ease of presentation is in fact output as a one column matrix. It is \emph{not} a C<I<bnf>>, you need C<bnfinit> for that. First we describe the default behaviour (C<I<flag> = 0>): C<v[1]> is equal to the polynomial C<P>. C<v[2]> is the 2-component vector C<[r1,r2]>, where C<r1> and C<r2> are as usual the number of real and half the number of complex embeddings of the number field C<K>. C<v[3]> is the 2-component vector containing the field discriminant and the index. C<v[4]> is an integral basis in Hermite normal form. C<v[5]> (C<v.clgp>) is a 3-component vector containing the class number (C<v.clgp.no>), the structure of the class group as a product of cyclic groups of order C<n_i> (C<v.clgp.cyc>), and the corresponding generators of the class group of respective orders C<n_i> (C<v.clgp.gen>). C<v[6]> (C<v.reg>) is the regulator computed to an accuracy which is the maximum of an internally determined accuracy and of the default. C<v[7]> is deprecated, maintained for backward compatibility and always equal to C<1>. C<v[8]> (C<v.tu>) a vector with 2 components, the first being the number C<w> of roots of unity in C<K> and the second a primitive C<w>-th root of unity expressed as a polynomial. C<v[9]> (C<v.fu>) is a system of fundamental units also expressed as polynomials. If C<I<flag> = 1>, and the precision happens to be insufficient for obtaining the fundamental units, the internal precision is doubled and the computation redone, until the exact results are obtained. Be warned that this can take a very long time when the coefficients of the fundamental units on the integral basis are very large, for example in large real quadratic fields. For this case, there are alternate compact representations for algebraic numbers, implemented in PARI but currently not available in GP. If C<I<flag> = 2>, the fundamental units and roots of unity are not computed. Hence the result has only 7 components, the first seven ones. X<bnfclassunit0>The library syntax is B<bnfclassunit0>C<(P,I<flag>,I<tech>,I<prec>)>. =head2 X<bnfclgp>bnfclgpC<(P,{I<tech> = []})> as C<bnfinit>, but only outputs C<bnf.clgp>, i.e.S< >the class group. X<classgrouponly>The library syntax is B<classgrouponly>C<(P,I<tech>,I<prec>)>, where I<tech> is as described under C<bnfinit>. =head2 X<bnfdecodemodule>bnfdecodemoduleC<(I<nf>,m)> if C<m> is a module as output in the first component of an extension given by C<bnrdisclist>, outputs the true module. X<decodemodule>The library syntax is B<decodemodule>C<(I<nf>,m)>. =head2 X<bnfinit>bnfinitC<(P,{I<flag> = 0},{I<tech> = []})> initializes a I<bnf> structure. Used in programs such as C<bnfisprincipal>, C<bnfisunit> or C<bnfnarrow>. By default, the results are conditional on a heuristic strengthening of the GRH, see X<se:GRHbnf>se:GRHbnf. The result is a 10-component vector I<bnf>. This implements X<Buchmann>Buchmann's sub-exponential algorithm for computing the class group, the regulator and a system of X<fundamental units>fundamental units of the general algebraic number field C<K> defined by the irreducible polynomial C<P> with integer coefficients. If the precision becomes insufficient, C<gp> outputs a warning (C<fundamental units too large, not given>) and does not strive to compute the units by default (C<I<flag> = 0>). When C<I<flag> = 1>, we insist on finding the fundamental units exactly. Be warned that this can take a very long time when the coefficients of the fundamental units on the integral basis are very large. If the fundamental units are simply too large to be represented in this form, an error message is issued. They could be obtained using the so-called compact representation of algebraic numbers as a formal product of algebraic integers. The latter is implemented internally but not publicly accessible yet. When C<I<flag> = 2>, on the contrary, it is initially agreed that units are not computed. Note that the resulting I<bnf> will not be suitable for C<bnrinit>, and that this flag provides negligible time savings compared to the default. In short, it is deprecated. When C<I<flag> = 3>, computes a very small version of C<bnfinit>, a ``small Buchmann's number field'' (or I<sbnf> for short) which contains enough information to recover the full C<I<bnf>> vector very rapidly, but which is much smaller and hence easy to store and print. It is supposed to be used in conjunction with C<bnfmake>. C<I<tech>> is a technical vector (empty by default, see X<se:GRHbnf>se:GRHbnf). Careful use of this parameter may speed up your computations considerably. The components of a I<bnf> or I<sbnf> are technical and never used by the casual user. In fact: \emph{never access a component directly, always use a proper member function.} However, for the sake of completeness and internal documentation, their description is as follows. We use the notations explained in the book by H. Cohen, \emph{A Course in Computational Algebraic Number Theory}, Graduate Texts in Maths B<138>, Springer-Verlag, 1993, Section 6.5, and subsection 6.5.5 in particular. C<I<bnf>[1]> contains the matrix C<W>, i.e.S< >the matrix in Hermite normal form giving relations for the class group on prime ideal generators C<( F<wp> _i)_{1 E<lt>= i E<lt>= r}>. C<I<bnf>[2]> contains the matrix C<B>, i.e.S< >the matrix containing the expressions of the prime ideal factorbase in terms of the C< F<wp> _i>. It is an C<r x c> matrix. C<I<bnf>[3]> contains the complex logarithmic embeddings of the system of fundamental units which has been found. It is an C<(r_1+r_2) x (r_1+r_2-1)> matrix. C<I<bnf>[4]> contains the matrix C<M''_C> of Archimedean components of the relations of the matrix C<(W|B)>. C<I<bnf>[5]> contains the prime factor base, i.e.S< >the list of prime ideals used in finding the relations. C<I<bnf>[6]> used to contain a permutation of the prime factor base, but has been obsoleted. It contains a dummy C<0>. C<I<bnf>[7]> or C<I<bnf>.nf> is equal to the number field data C<I<nf>> as would be given by C<nfinit>. C<I<bnf>[8]> is a vector containing the classgroup C<I<bnf>.clgp> as a finite abelian group, the regulator C<I<bnf>.reg>, a C<1> (used to contain an obsolete ``check number''), the number of roots of unity and a generator C<I<bnf>.tu>, the fundamental units C<I<bnf>.fu>. C<I<bnf>[9]> is a 3-element row vector used in X<bnfisprincipal>C<bnfisprincipal> only and obtained as follows. Let C<D = U W V> obtained by applying the X<Smith normal form>Smith normal form algorithm to the matrix C<W> ( = C<I<bnf>[1]>) and let C<U_r> be the reduction of C<U> modulo C<D>. The first elements of the factorbase are given (in terms of C<bnf.gen>) by the columns of C<U_r>, with Archimedean component C<g_a>; let also C<GD_a> be the Archimedean components of the generators of the (principal) ideals defined by the C<bnf.gen[i]^bnf.cyc[i]>. Then C<I<bnf>[9] = [U_r, g_a, GD_a]>. C<I<bnf>[10]> is by default unused and set equal to 0. This field is used to store further information about the field as it becomes available, which is rarely needed, hence would be too expensive to compute during the initial C<bnfinit> call. For instance, the generators of the principal ideals C<bnf.gen[i]^bnf.cyc[i]> (during a call to X<bnrisprincipal>C<bnrisprincipal>), or those corresponding to the relations in C<W> and C<B> (when the C<bnf> internal precision needs to be increased). An I<sbnf> is a 12 component vector C<v>, as follows. Let C<I<bnf>> be the result of a full C<bnfinit>, complete with units. Then C<v[1]> is the polynomial C<P>, C<v[2]> is the number of real embeddings C<r_1>, C<v[3]> is the field discriminant, C<v[4]> is the integral basis, C<v[5]> is the list of roots as in the sixth component of C<nfinit>, C<v[6]> is the matrix C<MD> of C<nfinit> giving a B<I<Z>>-basis of the different, C<v[7]> is the matrix C<W = I<bnf>[1]>, C<v[8]> is the matrix C<matalpha = I<bnf>[2]>, C<v[9]> is the prime ideal factor base C<I<bnf>[5]> coded in a compact way, and ordered according to the permutation C<I<bnf>[6]>, C<v[10]> is the 2-component vector giving the number of roots of unity and a generator, expressed on the integral basis, C<v[11]> is the list of fundamental units, expressed on the integral basis, C<v[12]> is a vector containing the algebraic numbers alpha corresponding to the columns of the matrix C<matalpha>, expressed on the integral basis. Note that all the components are exact (integral or rational), except for the roots in C<v[5]>. Note also that member functions will \emph{not} work on I<sbnf>, you have to use C<bnfmake> explicitly first. X<bnfinit0>The library syntax is B<bnfinit0>C<(P,I<flag>,I<tech>,I<prec>)>. =head2 X<bnfisintnorm>bnfisintnormC<(I<bnf>,x)> computes a complete system of solutions (modulo units of positive norm) of the absolute norm equation C<\Norm(a) = x>, where C<a> is an integer in C<I<bnf>>. If C<I<bnf>> has not been certified, the correctness of the result depends on the validity of X<GRH>GRH. See also X<bnfisnorm>C<bnfisnorm>. X<bnfisintnorm>The library syntax is B<bnfisintnorm>C<(I<bnf>,x)>. =head2 X<bnfisnorm>bnfisnormC<(I<bnf>,x,{I<flag> = 1})> tries to tell whether the rational number C<x> is the norm of some element y in C<I<bnf>>. Returns a vector C<[a,b]> where C<x = Norm(a)*b>. Looks for a solution which is an C<S>-unit, with C<S> a certain set of prime ideals containing (among others) all primes dividing C<x>. If C<I<bnf>> is known to be X<Galois>Galois, set C<I<flag> = 0> (in this case, C<x> is a norm iff C<b = 1>). If C<I<flag>> is non zero the program adds to C<S> the following prime ideals, depending on the sign of C<I<flag>>. If C<I<flag> E<gt> 0>, the ideals of norm less than C<I<flag>>. And if C<I<flag> E<lt> 0> the ideals dividing C<I<flag>>. Assuming X<GRH>GRH, the answer is guaranteed (i.e.S< >C<x> is a norm iff C<b = 1>), if C<S> contains all primes less than C<12 F<log> (\disc(I<Bnf>))^2>, where C<I<Bnf>> is the Galois closure of C<I<bnf>>. See also X<bnfisintnorm>C<bnfisintnorm>. X<bnfisnorm>The library syntax is B<bnfisnorm>C<(I<bnf>,x,I<flag>,I<prec>)>, where C<I<flag>> and C<I<prec>> are C<long>s. =head2 X<bnfissunit>bnfissunitC<(I<bnf>,I<sfu>,x)> C<I<bnf>> being output by C<bnfinit>, I<sfu> by C<bnfsunit>, gives the column vector of exponents of C<x> on the fundamental C<S>-units and the roots of unity. If C<x> is not a unit, outputs an empty vector. X<bnfissunit>The library syntax is B<bnfissunit>C<(I<bnf>,I<sfu>,x)>. =head2 X<bnfisprincipal>bnfisprincipalC<(I<bnf>,x,{I<flag> = 1})> C<I<bnf>> being the number field data output by C<bnfinit>, and C<x> being either a B<I<Z>>-basis of an ideal in the number field (not necessarily in HNF) or a prime ideal in the format output by the function C<idealprimedec>, this function tests whether the ideal is principal or not. The result is more complete than a simple true/false answer: it gives a row vector C<[v_1,v_2]>, where C<v_1> is the vector of components C<c_i> of the class of the ideal C<x> in the class group, expressed on the generators C<g_i> given by C<bnfinit> (specifically C<I<bnf>.gen>). The C<c_i> are chosen so that C<0 E<lt>= c_i E<lt> n_i> where C<n_i> is the order of C<g_i> (the vector of C<n_i> being C<I<bnf>.cyc>). C<v_2> gives on the integral basis the components of C<F<alpha>> such that C<x = F<alpha>F<prod>_ig_i^{c_i}>. In particular, C<x> is principal if and only if C<v_1> is equal to the zero vector. In the latter case, C<x = F<alpha>B<I<Z>>_K> where C<F<alpha>> is given by C<v_2>. Note that if C<F<alpha>> is too large to be given, a warning message will be printed and C<v_2> will be set equal to the empty vector. If C<I<flag> = 0>, outputs only C<v_1>, which is much easier to compute. If C<I<flag> = 2>, does as if C<I<flag>> were C<0>, but doubles the precision until a result is obtained. If C<I<flag> = 3>, as in the default behaviour (C<I<flag> = 1>), but doubles the precision until a result is obtained. The user is warned that these two last setting may induce \emph{very} lengthy computations. X<isprincipalall>The library syntax is B<isprincipalall>C<(I<bnf>,x,I<flag>)>. =head2 X<bnfisunit>bnfisunitC<(I<bnf>,x)> C<I<bnf>> being the number field data output by C<bnfinit> and C<x> being an algebraic number (type integer, rational or polmod), this outputs the decomposition of C<x> on the fundamental units and the roots of unity if C<x> is a unit, the empty vector otherwise. More precisely, if C<u_1>,...,C<u_r> are the fundamental units, and C<F<zeta>> is the generator of the group of roots of unity (C<bnf.tu>), the output is a vector C<[x_1,...,x_r,x_{r+1}]> such that C<x = u_1^{x_1}... u_r^{x_r}.F<zeta>^{x_{r+1}}>. The C<x_i> are integers for C<i E<lt>= r> and is an integer modulo the order of C<F<zeta>> for C<i = r+1>. X<isunit>The library syntax is B<isunit>C<(I<bnf>,x)>. =head2 X<bnfmake>bnfmakeC<(I<sbnf>)> I<sbnf> being a ``small C<I<bnf>>'' as output by C<bnfinit>C<(x,3)>, computes the complete C<bnfinit> information. The result is \emph{not} identical to what C<bnfinit> would yield, but is functionally identical. The execution time is very small compared to a complete C<bnfinit>. Note that if the default precision in C<gp> (or C<I<prec>> in library mode) is greater than the precision of the roots C<I<sbnf>[5]>, these are recomputed so as to get a result with greater accuracy. Note that the member functions are \emph{not} available for I<sbnf>, you have to use C<bnfmake> explicitly first. X<makebigbnf>The library syntax is B<makebigbnf>C<(I<sbnf>,I<prec>)>, where C<I<prec>> is a C long integer. =head2 X<bnfnarrow>bnfnarrowC<(I<bnf>)> C<I<bnf>> being as output by C<bnfinit>, computes the narrow class group of C<I<bnf>>. The output is a 3-component row vector C<v> analogous to the corresponding class group component C<I<bnf>.clgp> (C<I<bnf>[8][1]>): the first component is the narrow class number C<v.no>, the second component is a vector containing the SNFX<Smith normal form> cyclic components C<v.cyc> of the narrow class group, and the third is a vector giving the generators of the corresponding C<v.gen> cyclic groups. Note that this function is a special case of C<bnrinit>. X<buchnarrow>The library syntax is B<buchnarrow>C<(I<bnf>)>. =head2 X<bnfsignunit>bnfsignunitC<(I<bnf>)> C<I<bnf>> being as output by C<bnfinit>, this computes an C<r_1 x (r_1+r_2-1)> matrix having C<F<+->1> components, giving the signs of the real embeddings of the fundamental units. The following functions compute generators for the totally positive units: /* exponents of totally positive units generators on bnf.tufu */ tpuexpo(bnf)= { local(S,d,K); S = bnfsignunit(bnf); d = matsize(S); S = matrix(d[1],d[2], i,j, if (S[i,j] < 0, 1,0)); S = concat(vectorv(d[1],i,1), S); \\ add sign(-1) K = lift(matker(S * Mod(1,2))); if (K, mathnfmodid(K, 2), 2*matid(d[1])) } /* totally positive units */ tpu(bnf)= { local(vu = bnf.tufu, ex = tpuexpo(bnf)); vector(#ex-1, i, factorback(vu, ex[,i+1])) \\ ex[,1] is 1 } X<signunits>The library syntax is B<signunits>C<(I<bnf>)>. =head2 X<bnfreg>bnfregC<(I<bnf>)> C<I<bnf>> being as output by C<bnfinit>, computes its regulator. X<regulator>The library syntax is B<regulator>C<(I<bnf>,I<tech>,I<prec>)>, where I<tech> is as in C<bnfinit>. =head2 X<bnfsunit>bnfsunitC<(I<bnf>,S)> computes the fundamental C<S>-units of the number field C<I<bnf>> (output by C<bnfinit>), where C<S> is a list of prime ideals (output by C<idealprimedec>). The output is a vector C<v> with 6 components. C<v[1]> gives a minimal system of (integral) generators of the C<S>-unit group modulo the unit group. C<v[2]> contains technical data needed by C<bnfissunit>. C<v[3]> is an empty vector (used to give the logarithmic embeddings of the generators in C<v[1]> in version 2.0.16). C<v[4]> is the C<S>-regulator (this is the product of the regulator, the determinant of C<v[2]> and the natural logarithms of the norms of the ideals in C<S>). C<v[5]> gives the C<S>-class group structure, in the usual format (a row vector whose three components give in order the C<S>-class number, the cyclic components and the generators). C<v[6]> is a copy of C<S>. X<bnfsunit>The library syntax is B<bnfsunit>C<(I<bnf>,S,I<prec>)>. =head2 X<bnfunit>bnfunitC<(I<bnf>)> C<I<bnf>> being as output by C<bnfinit>, outputs the vector of fundamental units of the number field. This function is mostly useless, since it will only succeed if I<bnf> contains the units, in which case C<bnf.fu> is recommanded instead, or I<bnf> was produced with C<bnfinit(,,2)>, which is itself deprecated. X<buchfu>The library syntax is B<buchfu>C<(I<bnf>)>. =head2 X<bnrL1>bnrL1C<(I<bnr>,{I<subgroup>},{I<flag> = 0})> I<bnr> being the number field data which is output by C<bnrinit(,,1)> and I<subgroup> being a square matrix defining a congruence subgroup of the ray class group corresponding to I<bnr> (the trivial congruence subgroup if omitted), returns for each X<character>character C<F<chi>> of the ray class group which is trivial on this subgroup, the value at C<s = 1> (or C<s = 0>) of the abelian C<L>-function associated to C<F<chi>>. For the value at C<s = 0>, the function returns in fact for each character C<F<chi>> a vector C<[r_F<chi> , c_F<chi>]> where C<r_F<chi>> is the order of C<L(s, F<chi>)> at C<s = 0> and C<c_F<chi>> the first non-zero term in the expansion of C<L(s, F<chi>)> at C<s = 0>; in other words S< >C<L(s, F<chi>) = c_F<chi>.s^{r_F<chi>} + O(s^{r_F<chi> + 1})> near C<0>. I<flag> is optional, default value is 0; its binary digits mean 1: compute at C<s = 1> if set to 1 or C<s = 0> if set to 0, 2: compute the primitive C<L>-functions associated to C<F<chi>> if set to 0 or the C<L>-function with Euler factors at prime ideals dividing the modulus of I<bnr> removed if set to 1 (this is the so-called C<L_S(s, F<chi>)> function where C<S> is the set of infinite places of the number field together with the finite prime ideals dividing the modulus of I<bnr>, see the example below), 3: returns also the character. Example: bnf = bnfinit(x^2 - 229); bnr = bnrinit(bnf,1,1); bnrL1(bnr) returns the order and the first non-zero term of the abelian C<L>-functions C<L(s, F<chi>)> at C<s = 0> where C<F<chi>> runs through the characters of the class group of C<B<I<Q>>( F<sqrt> {229})>. Then bnr2 = bnrinit(bnf,2,1); bnrL1(bnr2,,2) returns the order and the first non-zero terms of the abelian C<L>-functions C<L_S(s, F<chi>)> at C<s = 0> where C<F<chi>> runs through the characters of the class group of C<B<I<Q>>( F<sqrt> {229})> and C<S> is the set of infinite places of C<B<I<Q>>( F<sqrt> {229})> together with the finite prime C<2>. Note that the ray class group modulo C<2> is in fact the class group, so C<bnrL1(bnr2,0)> returns exactly the same answer as C<bnrL1(bnr,0)>. X<bnrL1>The library syntax is B<bnrL1>C<(I<bnr>,I<subgroup>,I<flag>,I<prec>)>, where an omitted I<subgroup> is coded as C<NULL>. =head2 X<bnrclass>bnrclassC<(I<bnf>,I<ideal>,{I<flag> = 0})> \emph{this function is DEPRECATED, use C<bnrinit>}. C<I<bnf>> being as output by C<bnfinit> (the units are mandatory unless the ideal is trivial), and I<ideal> being a modulus, computes the ray class group of the number field for the modulus I<ideal>, as a finite abelian group. X<bnrclass0>The library syntax is B<bnrclass0>C<(I<bnf>,I<ideal>,I<flag>)>. =head2 X<bnrclassno>bnrclassnoC<(I<bnf>,I)> C<I<bnf>> being as output by C<bnfinit> (units are mandatory unless the ideal is trivial), and C<I> being a modulus, computes the ray class number of the number field for the modulus C<I>. This is faster than C<bnrinit> and should be used if only the ray class number is desired. See X<bnrclassnolist>C<bnrclassnolist> if you need ray class numbers for all moduli less than some bound. X<bnrclassno>The library syntax is B<bnrclassno>C<(I<bnf>,I)>. =head2 X<bnrclassnolist>bnrclassnolistC<(I<bnf>,I<list>)> C<I<bnf>> being as output by C<bnfinit>, and I<list> being a list of moduli (with units) as output by C<ideallist> or C<ideallistarch>, outputs the list of the class numbers of the corresponding ray class groups. To compute a single class number, X<bnrclassno>C<bnrclassno> is more efficient. ? bnf = bnfinit(x^2 - 2); ? L = ideallist(bnf, 100, 2); ? H = bnrclassnolist(bnf, L); ? H[98] %4 = [1, 3, 1] ? l = L[1][98]; ids = vector(#l, i, l[i].mod[1]) %5 = [[98, 88; 0, 1], [14, 0; 0, 7], [98, 10; 0, 1]] The weird C<l[i].mod[1]>, is the first component of C<l[i].mod>, i.e. the finite part of the conductor. (This is cosmetic: since by construction the archimedean part is trivial, I do not want to see it). This tells us that the ray class groups modulo the ideals of norm 98 (printed as C<%5>) have respectively order C<1>, C<3> and C<1>. Indeed, we may check directly : ? bnrclassno(bnf, ids[2]) %6 = 3 X<bnrclassnolist>The library syntax is B<bnrclassnolist>C<(I<bnf>,I<list>)>. =head2 X<bnrconductor>bnrconductorC<(a_1,{a_2},{a_3}, {I<flag> = 0})> conductor C<f> of the subfield of a ray class field as defined by C<[a_1,a_2,a_3]> (see C<bnr> at the beginning of this section). If C<I<flag> = 0>, returns C<f>. If C<I<flag> = 1>, returns C<[f, Cl_f, H]>, where C<Cl_f> is the ray class group modulo C<f>, as a finite abelian group; finally C<H> is the subgroup of C<Cl_f> defining the extension. If C<I<flag> = 2>, returns C<[f, I<bnr>(f), H]>, as above except C<Cl_f> is replaced by a C<bnr> structure, as output by C<X<bnrinit>bnrinit(,f,1)>. X<conductor>The library syntax is B<conductor>C<(I<bnr>, I<subgroup>, I<flag>)>, where an omitted subgroup (trivial subgroup, i.e.S< >ray class field) is input as C<NULL>, and C<I<flag>> is a C long. =head2 X<bnrconductorofchar>bnrconductorofcharC<(I<bnr>,I<chi>)> I<bnr> being a big ray number field as output by C<bnrinit>, and I<chi> being a row vector representing a X<character>character as expressed on the generators of the ray class group, gives the conductor of this character as a modulus. X<bnrconductorofchar>The library syntax is B<bnrconductorofchar>C<(I<bnr>,I<chi>)>. =head2 X<bnrdisc>bnrdiscC<(a1,{a2},{a3},{I<flag> = 0})> C<a1>, C<a2>, C<a3> defining a big ray number field C<L> over a ground field C<K> (see C<bnr> at the beginning of this section for the meaning of C<a1>, C<a2>, C<a3>), outputs a 3-component row vector C<[N,R_1,D]>, where C<N> is the (absolute) degree of C<L>, C<R_1> the number of real places of C<L>, and C<D> the discriminant of C<L/B<I<Q>>>, including sign (if C<I<flag> = 0>). If C<I<flag> = 1>, as above but outputs relative data. C<N> is now the degree of C<L/K>, C<R_1> is the number of real places of C<K> unramified in C<L> (so that the number of real places of C<L> is equal to C<R_1> times the relative degree C<N>), and C<D> is the relative discriminant ideal of C<L/K>. If C<I<flag> = 2>, as the default case, except that if the modulus is not the exact conductor corresponding to the C<L>, no data is computed and the result is C<0>. If C<I<flag> = 3>, as case 2, but output relative data. X<bnrdisc0>The library syntax is B<bnrdisc0>C<(a1,a2,a3,I<flag>)>. =head2 X<bnrdisclist>bnrdisclistC<(I<bnf>,I<bound>,{I<arch>})> C<I<bnf>> being as output by C<bnfinit> (with units), computes a list of discriminants of Abelian extensions of the number field by increasing modulus norm up to bound I<bound>. The ramified Archimedean places are given by I<arch>; all possible values are taken if I<arch> is omitted. The alternative syntax C<bnrdisclist(I<bnf>,I<list>)> is supported, where I<list> is as output by C<ideallist> or C<ideallistarch> (with units), in which case I<arch> is disregarded. The output C<v> is a vector of vectors, where C<v[i][j]> is understood to be in fact C<V[2^{15}(i-1)+j]> of a unique big vector C<V>. (This akward scheme allows for larger vectors than could be otherwise represented.) C<V[k]> is itself a vector C<W>, whose length is the number of ideals of norm C<k>. We consider first the case where I<arch> was specified. Each component of C<W> corresponds to an ideal C<m> of norm C<k>, and gives invariants associated to the ray class field C<L> of C<I<bnf>> of conductor C<[m, I<arch>]>. Namely, each contains a vector C<[m,d,r,D]> with the following meaning: C<m> is the prime ideal factorization of the modulus, C<d = [L:B<I<Q>>]> is the absolute degree of C<L>, C<r> is the number of real places of C<L>, and C<D> is the factorization of its absolute discriminant. We set C<d = r = D = 0> if C<m> is not the finite part of a conductor. If I<arch> was omitted, all C<t = 2^{r_1}> possible values are taken and a component of C<W> has the form C<[m, [[d_1,r_1,D_1],..., [d_t,r_t,D_t]]]>, where C<m> is the finite part of the conductor as above, and C<[d_i,r_i,D_i]> are the invariants of the ray class field of conductor C<[m,v_i]>, where C<v_i> is the C<i>-th archimedean component, ordered by inverse lexicographic order; so C<v_1 = [0,...,0]>, C<v_2 = [1,0...,0]>, etc. Again, we set C<d_i = r_i = D_i = 0> if C<[m,v_i]> is not a conductor. Finally, each prime ideal C<pr = [p,F<alpha>,e,f,F<beta>]> in the prime factorization C<m> is coded as the integer C<p.n^2+(f-1).n+(j-1)>, where C<n> is the degree of the base field and C<j> is such that C<pr = idealprimedec(I<nf>,p)[j]>. C<m> can be decoded using X<bnfdecodemodule>C<bnfdecodemodule>. Note that to compute such data for a single field, either X<bnrclassno>C<bnrclassno> or X<bnrdisc>C<bnrdisc> is more efficient. X<bnrdisclist0>The library syntax is B<bnrdisclist0>C<(bnf,I<bound>,I<arch>)>. =head2 X<bnrinit>bnrinitC<(I<bnf>,f,{I<flag> = 0})> C<I<bnf>> is as output by C<bnfinit>, C<f> is a modulus, initializes data linked to the ray class group structure corresponding to this module, a so-called I<bnr> structure. The following member functions are available on the result: C<.bnf> is the underlying I<bnf>, C<.mod> the modulus, C<.bid> the I<bid> structure associated to the modulus; finally, C<.clgp>, C<.no>, C<.cyc>, C<clgp> refer to the ray class group (as a finite abelian group), its cardinality, its elementary divisors, its generators. The last group of functions are different from the members of the underlying I<bnf>, which refer to the class group; use C<I<bnr>.bnf.I<xxx>> to access these, e.g.S< >C<I<bnr>.bnf.cyc> to get the cyclic decomposition of the class group. They are also different from the members of the underlying I<bid>, which refer to C<(\O_K/f)^*>; use C<I<bnr>.bid.I<xxx>> to access these, e.g.S< >C<I<bnr>.bid.no> to get C<F<phi>(f)>. If C<I<flag> = 0> (default), the generators of the ray class group are not computed, which saves time. Hence C<I<bnr>.gen> would produce an error. If C<I<flag> = 1>, as the default, except that generators are computed. X<bnrinit0>The library syntax is B<bnrinit0>C<(I<bnf>,f,I<flag>)>. =head2 X<bnrisconductor>bnrisconductorC<(a1,{a2},{a3})> C<a1>, C<a2>, C<a3> represent an extension of the base field, given by class field theory for some modulus encoded in the parameters. Outputs 1 if this modulus is the conductor, and 0 otherwise. This is slightly faster than C<bnrconductor>. X<bnrisconductor>The library syntax is B<bnrisconductor>C<(a1,a2,a3)> and the result is a C<long>. =head2 X<bnrisprincipal>bnrisprincipalC<(I<bnr>,x,{I<flag> = 1})> I<bnr> being the number field data which is output by C<bnrinit>C<(,,1)> and C<x> being an ideal in any form, outputs the components of C<x> on the ray class group generators in a way similar to C<bnfisprincipal>. That is a 2-component vector C<v> where C<v[1]> is the vector of components of C<x> on the ray class group generators, C<v[2]> gives on the integral basis an element C<F<alpha>> such that C<x = F<alpha>F<prod>_ig_i^{x_i}>. If C<I<flag> = 0>, outputs only C<v_1>. In that case, I<bnr> need not contain the ray class group generators, i.e.S< >it may be created with C<bnrinit>C<(,,0)> X<bnrisprincipal>The library syntax is B<bnrisprincipal>C<(I<bnr>,x,I<flag>)>. =head2 X<bnrrootnumber>bnrrootnumberC<(I<bnr>,I<chi>,{I<flag> = 0})> if C<F<chi> = I<chi>> is a (not necessarily primitive) X<character>character over I<bnr>, let C<L(s,F<chi>) = F<sum>_{id} F<chi>(id) N(id)^{-s}> be the associated X<Artin L-function>Artin L-function. Returns the so-called X<Artin root number>Artin root number, i.e.S< >the complex number C<W(F<chi>)> of modulus 1 such that S< >C<F<Lambda>(1-s,F<chi>) = W(F<chi>) F<Lambda>(s,\overline{F<chi>})> where C<F<Lambda>(s,F<chi>) = A(F<chi>)^{s/2}F<gamma>_F<chi>(s) L(s,F<chi>)> is the enlarged L-function associated to C<L>. The generators of the ray class group are needed, and you can set C<I<flag> = 1> if the character is known to be primitive. Example: bnf = bnfinit(x^2 - 145); bnr = bnrinit(bnf,7,1); bnrrootnumber(bnr, [5]) returns the root number of the character C<F<chi>> of C<\Cl_7(B<I<Q>>( F<sqrt> {145}))> such that C<F<chi>(g) = F<zeta>^5>, where C<g> is the generator of the ray-class field and C<F<zeta> = e^{2iF<Pi>/N}> where C<N> is the order of C<g> (C<N = 12> as C<bnr.cyc> readily tells us). X<bnrrootnumber>The library syntax is B<bnrrootnumber>C<(I<bnf>,I<chi>,I<flag>)> =head2 bnrstarkC<{(I<bnr>,{I<subgroup>})}> I<bnr> being as output by C<bnrinit(,,1)>, finds a relative equation for the class field corresponding to the modulus in I<bnr> and the given congruence subgroup (as usual, omit C<I<subgroup>> if you want the whole ray class group). The routine uses X<Stark units>Stark units and needs to find a suitable auxilliary conductor, which may not exist when the class field is not cyclic over the base. In this case C<bnrstark> is allowed to return a vector of polynomials defining \emph{independent} relative extensions, whose compositum is the requested class field. It was decided that it was more useful to keep the extra information thus made available, hence the user has to take the compositum herself. The main variable of I<bnr> must not be C<x>, and the ground field and the class field must be totally real. When the base field is B<I<Q>>, the vastly simpler X<galoissubcyclo>C<galoissubcyclo> is used instead. Here is an example: bnf = bnfinit(y^2 - 3); bnr = bnrinit(bnf, 5, 1); pol = bnrstark(bnr) returns the ray class field of C<B<I<Q>>( F<sqrt> {3})> modulo C<5>. Usually, one wants to apply to the result one of rnfpolredabs(bnf, pol, 16) \\ compute a reduced relative polynomial rnfpolredabs(bnf, pol, 16 + 2) \\ compute a reduced absolute polynomial X<bnrstark>The library syntax is B<bnrstark>C<(I<bnr>,I<subgroup>)>, where an omitted I<subgroup> is coded by C<NULL>. =head2 X<dirzetak>dirzetakC<(I<nf>,b)> gives as a vector the first C<b> coefficients of the X<Dedekind>Dedekind zeta function of the number field C<I<nf>> considered as a X<Dirichlet series>Dirichlet series. X<dirzetak>The library syntax is B<dirzetak>C<(I<nf>,b)>. =head2 X<factornf>factornfC<(x,t)> factorization of the univariate polynomial C<x> over the number field defined by the (univariate) polynomial C<t>. C<x> may have coefficients in B<I<Q>> or in the number field. The algorithm reduces to factorization over B<I<Q>> (X<Trager>Trager's trick). The direct approach of X<nffactor>C<nffactor>, which uses X<van Hoeij>van Hoeij's method in a relative setting, is in general faster. The main variable of C<t> must be of \emph{lower} priority than that of C<x> (see L<Label se:priority>). However if non-rational number field elements occur (as polmods or polynomials) as coefficients of C<x>, the variable of these polmods \emph{must} be the same as the main variable of C<t>. For example ? factornf(x^2 + Mod(y, y^2+1), y^2+1); ? factornf(x^2 + y, y^2+1); \\ these two are OK ? factornf(x^2 + Mod(z,z^2+1), y^2+1) *** factornf: inconsistent data in rnf function. ? factornf(x^2 + z, y^2+1) *** factornf: incorrect variable in rnf function. X<polfnf>The library syntax is B<polfnf>C<(x,t)>. =head2 X<galoisexport>galoisexportC<(I<gal>,{I<flag> = 0})> I<gal> being be a Galois field as output by X<galoisinit>C<galoisinit>, export the underlying permutation group as a string suitable for (no flags or C<I<flag> = 0>) GAP or (C<I<flag> = 1>) Magma. The following example compute the index of the underlying abstract group in the GAP library: ? G = galoisinit(x^6+108); ? s = galoisexport(G) %2 = "Group((1, 2, 3)(4, 5, 6), (1, 4)(2, 6)(3, 5))" ? extern("echo \"IdGroup("s");\" | gap -q") %3 = [6, 1] ? galoisidentify(G) %4 = [6, 1] This command also accepts subgroups returned by C<galoissubgroups>. X<galoisexport>The library syntax is B<galoisexport>C<(I<gal>,I<flag>)>. =head2 X<galoisfixedfield>galoisfixedfieldC<(I<gal>,I<perm>,{I<flag> = 0},{v = y}))> I<gal> being be a Galois field as output by X<galoisinit>C<galoisinit> and I<perm> an element of C<I<gal>.group> or a vector of such elements, computes the fixed field of I<gal> by the automorphism defined by the permutations I<perm> of the roots C<I<gal>.roots>. C<P> is guaranteed to be squarefree modulo C<I<gal>.p>. If no flags or C<I<flag> = 0>, output format is the same as for X<nfsubfield>C<nfsubfield>, returning C<[P,x]> such that C<P> is a polynomial defining the fixed field, and C<x> is a root of C<P> expressed as a polmod in C<I<gal>.pol>. If C<I<flag> = 1> return only the polynomial C<P>. If C<I<flag> = 2> return C<[P,x,F]> where C<P> and C<x> are as above and C<F> is the factorization of C<I<gal>.pol> over the field defined by C<P>, where variable C<v> (C<y> by default) stands for a root of C<P>. The priority of C<v> must be less than the priority of the variable of C<I<gal>.pol> (see L<Label se:priority>). Example: ? G = galoisinit(x^4+1); ? galoisfixedfield(G,G.group[2],2) %2 = [x^2 + 2, Mod(x^3 + x, x^4 + 1), [x^2 - y*x - 1, x^2 + y*x - 1]] computes the factorization C<x^4+1 = (x^2- F<sqrt> {-2}x-1)(x^2+ F<sqrt> {-2}x-1)> X<galoisfixedfield>The library syntax is B<galoisfixedfield>C<(I<gal>,I<perm>,I<flag>,C<v>)>, where C<v> is a variable number, an omitted C<v> being coded by C<-1>. =head2 X<galoisidentify>galoisidentifyC<(I<gal>)> I<gal> being be a Galois field as output by X<galoisinit>C<galoisinit>, output the isomorphism class of the underlying abstract group as a two-components vector C<[o,i]>, where C<o> is the group order, and C<i> is the group index in the GAP4 Small Group library, by Hans Ulrich Besche, Bettina Eick and Eamonn O'Brien. This command also accepts subgroups returned by C<galoissubgroups>. The current implementation is limited to degree less or equal to C<127>. Some larger ``easy'' orders are also supported. The output is similar to the output of the function C<IdGroup> in GAP4. Note that GAP4 C<IdGroup> handles all groups of order less than C<2000> except C<1024>, so you can use X<galoisexport>C<galoisexport> and GAP4 to identify large Galois groups. X<galoisidentify>The library syntax is B<galoisidentify>C<(I<gal>)>. =head2 X<galoisinit>galoisinitC<(I<pol>,{den})> computes the Galois group and all necessary information for computing the fixed fields of the Galois extension C<K/B<I<Q>>> where C<K> is the number field defined by C<I<pol>> (monic irreducible polynomial in C<B<I<Z>>[X]> or a number field as output by X<nfinit>C<nfinit>). The extension C<K/B<I<Q>>> must be Galois with Galois group ``weakly'' super-solvable (see X<nfgaloisconj>C<nfgaloisconj>) This is a prerequisite for most of the C<galois>C<xxx> routines. For instance: P = x^6 + 108; G = galoisinit(P); L = galoissubgroups(G); vector(#L, i, galoisisabelian(L[i],1)) vector(#L, i, galoisidentify(L[i])) The output is an 8-component vector I<gal>. C<I<gal>[1]> contains the polynomial I<pol> (C<I<gal>.pol>). C<I<gal>[2]> is a three-components vector C<[p,e,q]> where C<p> is a prime number (C<I<gal>.p>) such that I<pol> totally split modulo C<p> , C<e> is an integer and C<q = p^e> (C<I<gal>.mod>) is the modulus of the roots in C<I<gal>.roots>. C<I<gal>[3]> is a vector C<L> containing the C<p>-adic roots of I<pol> as integers implicitly modulo C<I<gal>.mod>. (C<I<gal>.roots>). C<I<gal>[4]> is the inverse of the Van der Monde matrix of the C<p>-adic roots of I<pol>, multiplied by C<I<gal>[5]>. C<I<gal>[5]> is a multiple of the least common denominator of the automorphisms expressed as polynomial in a root of I<pol>. C<I<gal>[6]> is the Galois group C<G> expressed as a vector of permutations of C<L> (C<I<gal>.group>). C<I<gal>[7]> is a generating subset C<S = [s_1,...,s_g]> of C<G> expressed as a vector of permutations of C<L> (C<I<gal>.gen>). C<I<gal>[8]> contains the relative orders C<[o_1,...,o_g]> of the generators of C<S> (C<I<gal>.orders>). Let C<H> be the maximal normal supersolvable subgroup of C<G>, we have the following properties: S< >S< >\item if C<G/H ~ A_4> then C<[o_1,...,o_g]> ends by C<[2,2,3]>. S< >S< >\item if C<G/H ~ S_4> then C<[o_1,...,o_g]> ends by C<[2,2,3,2]>. S< >S< >\item else C<G> is super-solvable. S< >S< >\item for C<1 E<lt>= i E<lt>= g> the subgroup of C<G> generated by C<[s_1,...,s_g]> is normal, with the exception of C<i = g-2> in the second case and of C<i = g-3> in the third. S< >S< >\item the relative order C<o_i> of C<s_i> is its order in the quotient group C<G/E<lt>s_1,...,s_{i-1}E<gt>>, with the same exceptions. S< >S< >\item for any C<x belongs to G> there exists a unique family C<[e_1,...,e_g]> such that (no exceptions): -- for C<1 E<lt>= i E<lt>= g> we have C<0 E<lt>= e_i E<lt> o_i> -- C<x = g_1^{e_1}g_2^{e_2}...g_n^{e_n}> If present C<den> must be a suitable value for C<I<gal>[5]>. X<galoisinit>The library syntax is B<galoisinit>C<(I<gal>,I<den>)>. =head2 X<galoisisabelian>galoisisabelianC<(I<gal>,{fl = 0})> I<gal> being as output by C<galoisinit>, return C<0> if I<gal> is not an abelian group, and the HNF matrix of I<gal> over C<gal.gen> if C<fl = 0>, C<1> if C<fl = 1>. This command also accepts subgroups returned by C<galoissubgroups>. X<galoisisabelian>The library syntax is B<galoisisabelian>C<(I<gal>,I<fl>)> where I<fl> is a C long integer. =head2 X<galoispermtopol>galoispermtopolC<(I<gal>,I<perm>)> I<gal> being a Galois field as output by C<galoisinit> and I<perm> a element of C<I<gal>.group>, return the polynomial defining the Galois automorphism, as output by C<nfgaloisconj>, associated with the permutation I<perm> of the roots C<I<gal>.roots>. I<perm> can also be a vector or matrix, in this case, C<galoispermtopol> is applied to all components recursively. Note that G = galoisinit(pol); galoispermtopol(G, G[6])~ is equivalent to C<nfgaloisconj(pol)>, if degree of I<pol> is greater or equal to C<2>. X<galoispermtopol>The library syntax is B<galoispermtopol>C<(I<gal>,I<perm>)>. =head2 X<galoissubcyclo>galoissubcycloC<(N,H,{fl = 0},{v})> computes the subextension of C<B<I<Q>>(F<zeta>_n)> fixed by the subgroup C<H \subset (B<I<Z>>/nB<I<Z>>)^*>. By the Kronecker-Weber theorem, all abelian number fields can be generated in this way (uniquely if C<n> is taken to be minimal). The pair C<(n, H)> is deduced from the parameters C<(N, H)> as follows \item C<N> an integer: then C<n = N>; C<H> is a generator, i.e. an integer or an integer modulo C<n>; or a vector of generators. \item C<N> the output of C<znstar(n)>. C<H> as in the first case above, or a matrix, taken to be a HNF left divisor of the SNF for C<(B<I<Z>>/nB<I<Z>>)^*> (of type C<N.cyc>), giving the generators of C<H> in terms of C<N.gen>. \item C<N> the output of C<bnrinit(bnfinit(y), m, 1)> where C<m> is a module. C<H> as in the first case, or a matrix taken to be a HNF left divisor of the SNF for the ray class group modulo C<m> (of type C<N.cyc>), giving the generators of C<H> in terms of C<N.gen>. In this last case, beware that C<H> is understood relatively to C<N>; in particular, if the infinite place does not divide the module, e.g if C<m> is an integer, then it is not a subgroup of C<(B<I<Z>>/nB<I<Z>>)^*>, but of its quotient by C<{F<+-> 1}>. If C<fl = 0>, compute a polynomial (in the variable I<v>) defining the the subfield of C<B<I<Q>>(F<zeta>_n)> fixed by the subgroup I<H> of C<(B<I<Z>>/nB<I<Z>>)^*>. If C<fl = 1>, compute only the conductor of the abelian extension, as a module. If C<fl = 2>, output C<[pol, N]>, where C<pol> is the polynomial as output when C<fl = 0> and C<N> the conductor as output when C<fl = 1>. The following function can be used to compute all subfields of C<B<I<Q>>(F<zeta>_n)> (of exact degree C<d>, if C<d> is set): subcyclo(n, d = -1)= { local(bnr,L,IndexBound); IndexBound = if (d < 0, n, [d]); bnr = bnrinit(bnfinit(y), [n,[1]], 1); L = subgrouplist(bnr, IndexBound, 1); vector(#L,i, galoissubcyclo(bnr,L[i])); } Setting C<L = subgrouplist(bnr, IndexBound)> would produce subfields of exact conductor C<n oo >. X<galoissubcyclo>The library syntax is B<galoissubcyclo>C<(N,H,fl,v)> where I<fl> is a C long integer, and I<v> a variable number. =head2 X<galoissubfields>galoissubfieldsC<(G,{fl = 0},{v})> Output all the subfields of the Galois group I<G>, as a vector. This works by applying C<galoisfixedfield> to all subgroups. The meaning of the flag I<fl> is the same as for C<galoisfixedfield>. X<galoissubfields>The library syntax is B<galoissubfields>C<(I<G>,fl,v)>, where I<fl> is a long and I<v> a variable number. =head2 X<galoissubgroups>galoissubgroupsC<(gal)> Output all the subgroups of the Galois group C<gal>. A subgroup is a vector [I<gen>, I<orders>], with the same meaning as for C<I<gal>.gen> and C<I<gal>.orders>. Hence I<gen> is a vector of permutations generating the subgroup, and I<orders> is the relatives orders of the generators. The cardinal of a subgroup is the product of the relative orders. Such subgroup can be used instead of a Galois group in the following command: C<galoisisabelian>, C<galoissubgroups>, C<galoisexport> and C<galoisidentify>. To get the subfield fixed by a subgroup I<sub> of I<gal>, use galoisfixedfield(gal,sub[1]) X<galoissubgroups>The library syntax is B<galoissubgroups>C<(I<gal>)>. =head2 X<idealadd>idealaddC<(I<nf>,x,y)> sum of the two ideals C<x> and C<y> in the number field C<I<nf>>. When C<x> and C<y> are given by B<I<Z>>-bases, this does not depend on C<I<nf>> and can be used to compute the sum of any two B<I<Z>>-modules. The result is given in HNF. X<idealadd>The library syntax is B<idealadd>C<(I<nf>,x,y)>. =head2 X<idealaddtoone>idealaddtooneC<(I<nf>,x,{y})> C<x> and C<y> being two co-prime integral ideals (given in any form), this gives a two-component row vector C<[a,b]> such that C<a belongs to x>, C<b belongs to y> and C<a+b = 1>. The alternative syntax C<idealaddtoone(I<nf>,v)>, is supported, where C<v> is a C<k>-component vector of ideals (given in any form) which sum to C<B<I<Z>>_K>. This outputs a C<k>-component vector C<e> such that C<e[i] belongs to x[i]> for C<1 E<lt>= i E<lt>= k> and C<F<sum>_{1 E<lt>= i E<lt>= k}e[i] = 1>. X<idealaddtoone0>The library syntax is B<idealaddtoone0>C<(I<nf>,x,y)>, where an omitted C<y> is coded as C<NULL>. =head2 X<idealappr>idealapprC<(I<nf>,x,{I<flag> = 0})> if C<x> is a fractional ideal (given in any form), gives an element C<F<alpha>> in C<I<nf>> such that for all prime ideals C< F<wp> > such that the valuation of C<x> at C< F<wp> > is non-zero, we have C<v_{ F<wp> }(F<alpha>) = v_{ F<wp> }(x)>, and. C<v_{ F<wp> }(F<alpha>) E<gt>= 0> for all other C<{ F<wp> }>. If C<I<flag>> is non-zero, C<x> must be given as a prime ideal factorization, as output by C<idealfactor>, but possibly with zero or negative exponents. This yields an element C<F<alpha>> such that for all prime ideals C< F<wp> > occurring in C<x>, C<v_{ F<wp> }(F<alpha>)> is equal to the exponent of C< F<wp> > in C<x>, and for all other prime ideals, C<v_{ F<wp> }(F<alpha>) E<gt>= 0>. This generalizes C<idealappr(I<nf>,x,0)> since zero exponents are allowed. Note that the algorithm used is slightly different, so that C<idealappr(I<nf>,idealfactor(I<nf>,x))> may not be the same as C<idealappr(I<nf>,x,1)>. X<idealappr0>The library syntax is B<idealappr0>C<(I<nf>,x,I<flag>)>. =head2 X<idealchinese>idealchineseC<(I<nf>,x,y)> C<x> being a prime ideal factorization (i.e.S< >a 2 by 2 matrix whose first column contain prime ideals, and the second column integral exponents), C<y> a vector of elements in C<I<nf>> indexed by the ideals in C<x>, computes an element C<b> such that C<v_ F<wp> (b - y_ F<wp> ) E<gt>= v_ F<wp> (x)> for all prime ideals in C<x> and C<v_ F<wp> (b) E<gt>= 0> for all other C< F<wp> >. X<idealchinese>The library syntax is B<idealchinese>C<(I<nf>,x,y)>. =head2 X<idealcoprime>idealcoprimeC<(I<nf>,x,y)> given two integral ideals C<x> and C<y> in the number field C<I<nf>>, finds a C<F<beta>> in the field, expressed on the integral basis C<I<nf>[7]>, such that C<F<beta>.x> is an integral ideal coprime to C<y>. X<idealcoprime>The library syntax is B<idealcoprime>C<(I<nf>,x,y)>. =head2 X<idealdiv>idealdivC<(I<nf>,x,y,{I<flag> = 0})> quotient C<x.y^{-1}> of the two ideals C<x> and C<y> in the number field C<I<nf>>. The result is given in HNF. If C<I<flag>> is non-zero, the quotient C<x.y^{-1}> is assumed to be an integral ideal. This can be much faster when the norm of the quotient is small even though the norms of C<x> and C<y> are large. X<idealdiv0>The library syntax is B<idealdiv0>C<(I<nf>,x,y,I<flag>)>. Also available are C< B<idealdiv>(I<nf>,x,y)>X<idealdiv> (C<I<flag> = 0>) and C< B<idealdivexact>(I<nf>,x,y)>X<idealdivexact> (C<I<flag> = 1>). =head2 X<idealfactor>idealfactorC<(I<nf>,x)> factors into prime ideal powers the ideal C<x> in the number field C<I<nf>>. The output format is similar to the C<factor> function, and the prime ideals are represented in the form output by the C<idealprimedec> function, i.e.S< >as 5-element vectors. X<idealfactor>The library syntax is B<idealfactor>C<(I<nf>,x)>. =head2 X<idealhnf>idealhnfC<(I<nf>,a,{b})> gives the X<Hermite normal form>Hermite normal form matrix of the ideal C<a>. The ideal can be given in any form whatsoever (typically by an algebraic number if it is principal, by a C<B<I<Z>>_K>-system of generators, as a prime ideal as given by C<idealprimedec>, or by a B<I<Z>>-basis). If C<b> is not omitted, assume the ideal given was C<aB<I<Z>>_K+bB<I<Z>>_K>, where C<a> and C<b> are elements of C<K> given either as vectors on the integral basis C<I<nf>[7]> or as algebraic numbers. X<idealhnf0>The library syntax is B<idealhnf0>C<(I<nf>,a,b)> where an omitted C<b> is coded as C<NULL>. Also available is C< B<idealhermite>(I<nf>,a)>X<idealhermite> (C<b> omitted). =head2 X<idealintersect>idealintersectC<(I<nf>,A,B)> intersection of the two ideals C<A> and C<B> in the number field C<I<nf>>. The result is given in HNF. ? nf = nfinit(x^2+1); ? idealintersect(nf, 2, x+1) %2 = [2 0] [0 2] This function does not apply to general B<I<Z>>-modules, e.g.S< >orders, since its arguments are replaced by the ideals they generate. The following script intersects B<I<Z>>-modules C<A> and C<B> given by matrices of compatible dimensions with integer coefficients: ZM_intersect(A,B) = { local( Ker = matkerint(concat(A,B)) ); mathnf(A * vecextract(Ker, Str("..", #A), "..")) } X<idealintersect>The library syntax is B<idealintersect>C<(I<nf>,A,B)>. =head2 X<idealinv>idealinvC<(I<nf>,x)> inverse of the ideal C<x> in the number field C<I<nf>>. The result is the Hermite normal form of the inverse of the ideal, together with the opposite of the Archimedean information if it is given. X<idealinv>The library syntax is B<idealinv>C<(I<nf>,x)>. =head2 X<ideallist>ideallistC<(I<nf>,I<bound>,{I<flag> = 4})> computes the list of all ideals of norm less or equal to I<bound> in the number field I<nf>. The result is a row vector with exactly I<bound> components. Each component is itself a row vector containing the information about ideals of a given norm, in no specific order, depending on the value of C<I<flag>>: The possible values of C<I<flag>> are: S< >S< >0: give the I<bid> associated to the ideals, without generators. S< >S< >1: as 0, but include the generators in the I<bid>. S< >S< >2: in this case, I<nf> must be a I<bnf> with units. Each component is of the form C<[I<bid>,U]>, where I<bid> is as case 0 and C<U> is a vector of discrete logarithms of the units. More precisely, it gives the C<ideallog>s with respect to I<bid> of C<bnf.tufu>. This structure is technical, and only meant to be used in conjunction with X<bnrclassnolist>C<bnrclassnolist> or X<bnrdisclist>C<bnrdisclist>. S< >S< >3: as 2, but include the generators in the I<bid>. S< >S< >4: give only the HNF of the ideal. ? nf = nfinit(x^2+1); ? L = ideallist(nf, 100); ? L[1] %3 = [[1, 0; 0, 1]] \\ A single ideal of norm 1 ? #L[65] %4 = 4 \\ There are 4 ideals of norm 4 in Z[i] If one wants more information, one could do instead: ? nf = nfinit(x^2+1); ? L = ideallist(nf, 100, 0); ? l = L[25]; vector(#l, i, l[i].clgp) %3 = [[20, [20]], [16, [4, 4]], [20, [20]]] ? l[1].mod %4 = [[25, 18; 0, 1], []] ? l[2].mod %5 = [[5, 0; 0, 5], []] ? l[3].mod %6 = [[25, 7; 0, 1], []] where we ask for the structures of the C<(B<I<Z>>[i]/I)^*> for all three ideals of norm C<25>. In fact, for all moduli with finite part of norm C<25> and trivial archimedean part, as the last 3 commands show. See X<ideallistarch>C<ideallistarch> to treat general moduli. X<ideallist0>The library syntax is B<ideallist0>C<(I<nf>,I<bound>,I<flag>)>, where I<bound> must be a C long integer. Also available is C< B<ideallist>(I<nf>,I<bound>)>X<ideallist>, corresponding to the case C<I<flag> = 4>. =head2 X<ideallistarch>ideallistarchC<(I<nf>,I<list>,I<arch>)> I<list> is a vector of vectors of bid's, as output by X<ideallist>C<ideallist> with flag C<0> to C<3>. Return a vector of vectors with the same number of components as the original I<list>. The leaves give information about moduli whose finite part is as in original list, in the same order, and archimedean part is now I<arch> (it was originally trivial). The information contained is of the same kind as was present in the input; see X<ideallist>C<ideallist>, in particular the meaning of I<flag>. ? bnf = bnfinit(x^2-2); ? bnf.sign %2 = [2, 0] \\ two places at infinity ? L = ideallist(bnf, 100, 0); ? l = L[98]; vector(#l, i, l[i].clgp) %4 = [[42, [42]], [36, [6, 6]], [42, [42]]] ? La = ideallistarch(bnf, L, [1,1]); \\ add them to the modulus ? l = La[98]; vector(#l, i, l[i].clgp) %6 = [[168, [42, 2, 2]], [144, [6, 6, 2, 2]], [168, [42, 2, 2]]] Of course, the results above are obvious: adding C<t> places at infinity will add C<t> copies of C<B<I<Z>>/2B<I<Z>>> to the ray class group. The following application is more typical: ? L = ideallist(bnf, 100, 2); \\ units are required now ? La = ideallistarch(bnf, L, [1,1]); ? H = bnrclassnolist(bnf, La); ? H[98]; %6 = [2, 12, 2] X<ideallistarch>The library syntax is B<ideallistarch>C<(I<nf>,I<list>,I<arch>)>. =head2 X<ideallog>ideallogC<(I<nf>,x,I<bid>)> C<I<nf>> is a number field, I<bid> a ``big ideal'' as output by C<idealstar> and C<x> a non-necessarily integral element of I<nf> which must have valuation equal to 0 at all prime ideals dividing C<I = I<bid>[1]>. This function computes the ``discrete logarithm'' of C<x> on the generators given in C<I<bid>[2]>. In other words, if C<g_i> are these generators, of orders C<d_i> respectively, the result is a column vector of integers C<(x_i)> such that C<0 E<lt>= x_i E<lt> d_i> and S< >C<x = F<prod>_ig_i^{x_i} (mod ^*I) .> Note that when C<I> is a module, this implies also sign conditions on the embeddings. X<zideallog>The library syntax is B<zideallog>C<(I<nf>,x,I<bid>)>. =head2 X<idealmin>idealminC<(I<nf>,x,{I<vdir>})> computes a minimum of the ideal C<x> in the direction I<vdir> in the number field I<nf>. X<minideal>The library syntax is B<minideal>C<(I<nf>,x,I<vdir>,I<prec>)>, where an omitted I<vdir> is coded as C<NULL>. =head2 X<idealmul>idealmulC<(I<nf>,x,y,{I<flag> = 0})> ideal multiplication of the ideals C<x> and C<y> in the number field I<nf>. The result is a generating set for the ideal product with at most C<n> elements, and is in Hermite normal form if either C<x> or C<y> is in HNF or is a prime ideal as output by C<idealprimedec>, and this is given together with the sum of the Archimedean information in C<x> and C<y> if both are given. If C<I<flag>> is non-zero, reduce the result using C<idealred>. X<idealmul>The library syntax is B<idealmul>C<(I<nf>,x,y)> (C<I<flag> = 0>) or C< B<idealmulred>(I<nf>,x,y,I<prec>)>X<idealmulred> (C<I<flag> ! = 0>), where as usual, C<I<prec>> is a C long integer representing the precision. =head2 X<idealnorm>idealnormC<(I<nf>,x)> computes the norm of the idealS< >C<x> in the number fieldS< >C<I<nf>>. X<idealnorm>The library syntax is B<idealnorm>C<(I<nf>, x)>. =head2 X<idealpow>idealpowC<(I<nf>,x,k,{I<flag> = 0})> computes the C<k>-th power of the ideal C<x> in the number field C<I<nf>>. C<k> can be positive, negative or zero. The result is NOT reduced, it is really the C<k>-th ideal power, and is given in HNF. If C<I<flag>> is non-zero, reduce the result using C<idealred>. Note however that this is NOT the same as as C<idealpow(I<nf>,x,k)> followed by reduction, since the reduction is performed throughout the powering process. The library syntax corresponding to C<I<flag> = 0> is C< B<idealpow>(I<nf>,x,k)>X<idealpow>. If C<k> is a C<long>, you can use C< B<idealpows>(I<nf>,x,k)>X<idealpows>. Corresponding to C<I<flag> = 1> is C< B<idealpowred>(I<nf>,vp,k,I<prec>)>X<idealpowred>, where C<I<prec>> is a C<long>. =head2 X<idealprimedec>idealprimedecC<(I<nf>,p)> computes the prime ideal decomposition of the prime number C<p> in the number field C<I<nf>>. C<p> must be a (positive) prime number. Note that the fact that C<p> is prime is not checked, so if a non-prime C<p> is given the result is undefined. The result is a vector of X<pr>I<pr> structures, each representing one of the prime ideals above C<p> in the number field C<I<nf>>. The representation C<P = [p,a,e,f,b]> of a prime ideal means the following. The prime ideal is equal to C<pB<I<Z>>_K+F<alpha>B<I<Z>>_K> where C<B<I<Z>>_K> is the ring of integers of the field and C<F<alpha> = F<sum>_i a_iF<omega>_i> where the C<F<omega>_i> form the integral basis C<I<nf>.zk>, C<e> is the ramification index, C<f> is the residual index, and C<b> represents a C<F<beta> belongs to B<I<Z>>_K> such that C<P^{-1} = B<I<Z>>_K+F<beta>/pB<I<Z>>_K> which will be useful for computing valuations, but which the user can ignore. The number C<F<alpha>> is guaranteed to have a valuation equal to 1 at the prime ideal (this is automatic if C<e E<gt> 1>). The components of C<P> should be accessed by member functions: C<P.p>, C<P.e>, C<P.f>, and C<P.gen> (returns the vector C<[p,a]>). X<primedec>The library syntax is B<primedec>C<(I<nf>,p)>. =head2 X<idealprincipal>idealprincipalC<(I<nf>,x)> creates the principal ideal generated by the algebraic number C<x> (which must be of type integer, rational or polmod) in the number field C<I<nf>>. The result is a one-column matrix. X<principalideal>The library syntax is B<principalideal>C<(I<nf>,x)>. =head2 X<idealred>idealredC<(I<nf>,I,{I<vdir> = 0})> X<LLL>LLL reduction of the ideal C<I> in the number field I<nf>, along the direction I<vdir>. If I<vdir> is present, it must be an C<r1+r2>-component vector (C<r1> and C<r2> number of real and complex places of I<nf> as usual). This function finds a ``small'' C<a> in C<I> (it is an LLL pseudo-minimum along direction I<vdir>). The result is the Hermite normal form of the LLL-reduced ideal C<r I/a>, where C<r> is a rational number such that the resulting ideal is integral and primitive. This is often, but not always, a reduced ideal in the sense of X<Buchmann>Buchmann. If C<I> is an idele, the logarithmic embeddings of C<a> are subtracted to the Archimedean part. More often than not, a X<principal ideal>principal ideal will yield the identity matrix. This is a quick and dirty way to check if ideals are principal without computing a full C<bnf> structure, but it's not a necessary condition; hence, a non-trivial result doesn't prove the ideal is non-trivial in the class group. Note that this is \emph{not} the same as the LLL reduction of the lattice C<I> since ideal operations are involved. X<ideallllred>The library syntax is B<ideallllred>C<(I<nf>,x,I<vdir>,I<prec>)>, where an omitted I<vdir> is coded as C<NULL>. =head2 X<idealstar>idealstarC<(I<nf>,I,{I<flag> = 1})> outputs a I<bid> structure, necessary for computing in the finite abelian group C<G = (B<I<Z>>_K/I)^*>. Here, I<nf> is a number field and C<I> is a I<modulus>: either an ideal in any form, or a row vector whose first component is an ideal and whose second component is a row vector of C<r_1> 0 or 1. This I<bid> is used in X<ideallog>C<ideallog> to compute discrete logarithms. It also contains useful information which can be conveniently retrieved as C<I<bid>.mod> (the modulus), C<I<bid>.clgp> (C<G> as a finite abelian group), C<I<bid>.no> (the cardinality of C<G>), C<I<bid>.cyc> (elementary divisors) and C<I<bid>.gen> (generators). If C<I<flag> = 1> (default), the result is a I<bid> structure without generators. If C<I<flag> = 2>, as C<I<flag> = 1>, but including generators, which wastes some time. If C<I<flag> = 0>, \emph{deprecated}. Only outputs C<(B<I<Z>>_K/I)^*> as an abelian group, i.e as a 3-component vector C<[h,d,g]>: C<h> is the order, C<d> is the vector of SNFX<Smith normal form> cyclic components and C<g> the corresponding generators. This flag is deprecated: it is in fact slightly faster to compute a true I<bid> structure, which contains much more information. X<idealstar0>The library syntax is B<idealstar0>C<(I<nf>,I,I<flag>)>. =head2 X<idealtwoelt>idealtwoeltC<(I<nf>,x,{a})> computes a two-element representation of the ideal C<x> in the number field C<I<nf>>, using a straightforward (exponential time) search. C<x> can be an ideal in any form, (including perhaps an Archimedean part, which is ignored) and the result is a row vector C<[a,F<alpha>]> with two components such that C<x = aB<I<Z>>_K+F<alpha>B<I<Z>>_K> and C<a belongs to B<I<Z>>>, where C<a> is the one passed as argument if any. If C<x> is given by at least two generators, C<a> is chosen to be the positive generator of C<x F<cap> B<I<Z>>>. Note that when an explicit C<a> is given, we use an asymptotically faster method, however in practice it is usually slower. X<ideal_two_elt0>The library syntax is B<ideal_two_elt0>C<(I<nf>,x,a)>, where an omitted C<a> is entered as C<NULL>. =head2 X<idealval>idealvalC<(I<nf>,x,I<vp>)> gives the valuation of the ideal C<x> at the prime ideal I<vp> in the number field C<I<nf>>, where I<vp> must be a 5-component vector as given by C<idealprimedec>. X<idealval>The library syntax is B<idealval>C<(I<nf>,x,I<vp>)>, and the result is a C<long> integer. =head2 X<ideleprincipal>ideleprincipalC<(I<nf>,x)> creates the principal idele generated by the algebraic number C<x> (which must be of type integer, rational or polmod) in the number field C<I<nf>>. The result is a two-component vector, the first being a one-column matrix representing the corresponding principal ideal, and the second being the vector with C<r_1+r_2> components giving the complex logarithmic embedding of C<x>. X<principalidele>The library syntax is B<principalidele>C<(I<nf>,x)>. =head2 X<matalgtobasis>matalgtobasisC<(I<nf>,x)> C<I<nf>> being a number field in C<nfinit> format, and C<x> a matrix whose coefficients are expressed as polmods in C<I<nf>>, transforms this matrix into a matrix whose coefficients are expressed on the integral basis of C<I<nf>>. This is the same as applying C<nfalgtobasis> to each entry, but it would be dangerous to use the same name. X<matalgtobasis>The library syntax is B<matalgtobasis>C<(I<nf>,x)>. =head2 X<matbasistoalg>matbasistoalgC<(I<nf>,x)> C<I<nf>> being a number field in C<nfinit> format, and C<x> a matrix whose coefficients are expressed as column vectors on the integral basis of C<I<nf>>, transforms this matrix into a matrix whose coefficients are algebraic numbers expressed as polmods. This is the same as applying C<nfbasistoalg> to each entry, but it would be dangerous to use the same name. X<matbasistoalg>The library syntax is B<matbasistoalg>C<(I<nf>,x)>. =head2 X<modreverse>modreverseC<(a)> C<a> being a polmod C<A(X)> modulo C<T(X)>, finds the ``reverse polmod'' C<B(X)> modulo C<Q(X)>, where C<Q> is the minimal polynomial of C<a>, which must be equal to the degree of C<T>, and such that if C<F<theta>> is a root of C<T> then C<F<theta> = B(F<alpha>)> for a certain root C<F<alpha>> of C<Q>. This is very useful when one changes the generating element in algebraic extensions. X<polmodrecip>The library syntax is B<polmodrecip>C<(x)>. =head2 X<newtonpoly>newtonpolyC<(x,p)> gives the vector of the slopes of the Newton polygon of the polynomial C<x> with respect to the prime number C<p>. The C<n> components of the vector are in decreasing order, where C<n> is equal to the degree of C<x>. Vertical slopes occur iff the constant coefficient of C<x> is zero and are denoted by C<VERYBIGINT>, the biggest single precision integer representable on the machine (C<2^{31}-1> (resp.S< >C<2^{63}-1>) on 32-bit (resp.S< >64-bit) machines), see L<Label se:valuation>. X<newtonpoly>The library syntax is B<newtonpoly>C<(x,p)>. =head2 X<nfalgtobasis>nfalgtobasisC<(I<nf>,x)> this is the inverse function of C<nfbasistoalg>. Given an object C<x> whose entries are expressed as algebraic numbers in the number field C<I<nf>>, transforms it so that the entries are expressed as a column vector on the integral basis C<I<nf>.zk>. X<algtobasis>The library syntax is B<algtobasis>C<(I<nf>,x)>. =head2 X<nfbasis>nfbasisC<(x,{I<flag> = 0},{I<fa>})> X<integral basis>integral basis of the number field defined by the irreducible, preferably monic, polynomial C<x>, using a modified version of the X<round 4>round 4 algorithm by default, due to David X<Ford>Ford, Sebastian X<Pauli>Pauli and Xavier X<Roblot>Roblot. The binary digits of C<I<flag>> have the following meaning: 1: assume that no square of a prime greater than the default C<primelimit> divides the discriminant of C<x>, i.e.S< >that the index of C<x> has only small prime divisors. 2: use X<round 2>round 2 algorithm. For small degrees and coefficient size, this is sometimes a little faster. (This program is the translation into C of a program written by David X<Ford>Ford in Algeb.) Thus for instance, if C<I<flag> = 3>, this uses the round 2 algorithm and outputs an order which will be maximal at all the small primes. If I<fa> is present, we assume (without checking!) that it is the two-column matrix of the factorization of the discriminant of the polynomial C<x>. Note that it does \emph{not} have to be a complete factorization. This is especially useful if only a local integral basis for some small set of places is desired: only factors with exponents greater or equal to 2 will be considered. X<nfbasis0>The library syntax is B<nfbasis0>C<(x,I<flag>,I<fa>)>. An extended version is C< B<nfbasis>(x,&d,I<flag>,I<fa>)>X<nfbasis>, where C<d> receives the discriminant of the number field (\emph{not} of the polynomial C<x>), and an omitted I<fa> is input as C<NULL>. Also available are C< B<base>(x,&d)>X<base> (C<I<flag> = 0>), C< B<base2>(x,&d)>X<base2> (C<I<flag> = 2>) and C< B<factoredbase>(x,I<fa>,&d)>X<factoredbase>. =head2 X<nfbasistoalg>nfbasistoalgC<(I<nf>,x)> this is the inverse function of C<nfalgtobasis>. Given an object C<x> whose entries are expressed on the integral basis C<I<nf>.zk>, transforms it into an object whose entries are algebraic numbers (i.e.S< >polmods). X<basistoalg>The library syntax is B<basistoalg>C<(I<nf>,x)>. =head2 X<nfdetint>nfdetintC<(I<nf>,x)> given a pseudo-matrix C<x>, computes a non-zero ideal contained in (i.e.S< >multiple of) the determinant of C<x>. This is particularly useful in conjunction with C<nfhnfmod>. X<nfdetint>The library syntax is B<nfdetint>C<(I<nf>,x)>. =head2 X<nfdisc>nfdiscC<(x,{I<flag> = 0},{fa})> X<field discriminant>field discriminant of the number field defined by the integral, preferably monic, irreducible polynomial C<x>. C<I<flag>> and C<fa> are exactly as in C<nfbasis>. That is, C<fa> provides the matrix of a partial factorization of the discriminant of C<x>, and binary digits of C<I<flag>> are as follows: 1: assume that no square of a prime greater than C<primelimit> divides the discriminant. 2: use the round 2 algorithm, instead of the default X<round 4>round 4. This should be slower except maybe for polynomials of small degree and coefficients. X<nfdiscf0>The library syntax is B<nfdiscf0>C<(x,I<flag>,fa)> where an omitted C<fa> is input as C<NULL>. You can also use C< B<discf>(x)>X<discf> (C<I<flag> = 0>). =head2 X<nfeltdiv>nfeltdivC<(I<nf>,x,y)> given two elements C<x> and C<y> in I<nf>, computes their quotient C<x/y> in the number field C<I<nf>>. X<element_div>The library syntax is B<element_div>C<(I<nf>,x,y)>. =head2 X<nfeltdiveuc>nfeltdiveucC<(I<nf>,x,y)> given two elements C<x> and C<y> in I<nf>, computes an algebraic integer C<q> in the number field C<I<nf>> such that the components of C<x-qy> are reasonably small. In fact, this is functionally identical to C<round(nfeltdiv(I<nf>,x,y))>. X<nfdiveuc>The library syntax is B<nfdiveuc>C<(I<nf>,x,y)>. =head2 X<nfeltdivmodpr>nfeltdivmodprC<(I<nf>,x,y,I<pr>)> given two elements C<x> and C<y> in I<nf> and I<pr> a prime ideal in C<modpr> format (see X<nfmodprinit>C<nfmodprinit>), computes their quotient C<x / y> modulo the prime ideal I<pr>. X<element_divmodpr>The library syntax is B<element_divmodpr>C<(I<nf>,x,y,I<pr>)>. =head2 X<nfeltdivrem>nfeltdivremC<(I<nf>,x,y)> given two elements C<x> and C<y> in I<nf>, gives a two-element row vector C<[q,r]> such that C<x = qy+r>, C<q> is an algebraic integer in C<I<nf>>, and the components of C<r> are reasonably small. X<nfdivrem>The library syntax is B<nfdivrem>C<(I<nf>,x,y)>. =head2 X<nfeltmod>nfeltmodC<(I<nf>,x,y)> given two elements C<x> and C<y> in I<nf>, computes an element C<r> of C<I<nf>> of the form C<r = x-qy> with C<q> and algebraic integer, and such that C<r> is small. This is functionally identical to S< >C<x - nfeltmul(I<nf>,round(nfeltdiv(I<nf>,x,y)),y).> X<nfmod>The library syntax is B<nfmod>C<(I<nf>,x,y)>. =head2 X<nfeltmul>nfeltmulC<(I<nf>,x,y)> given two elements C<x> and C<y> in I<nf>, computes their product C<x*y> in the number field C<I<nf>>. X<element_mul>The library syntax is B<element_mul>C<(I<nf>,x,y)>. =head2 X<nfeltmulmodpr>nfeltmulmodprC<(I<nf>,x,y,I<pr>)> given two elements C<x> and C<y> in I<nf> and I<pr> a prime ideal in C<modpr> format (see X<nfmodprinit>C<nfmodprinit>), computes their product C<x*y> modulo the prime ideal I<pr>. X<element_mulmodpr>The library syntax is B<element_mulmodpr>C<(I<nf>,x,y,I<pr>)>. =head2 X<nfeltpow>nfeltpowC<(I<nf>,x,k)> given an element C<x> in I<nf>, and a positive or negative integer C<k>, computes C<x^k> in the number field C<I<nf>>. X<element_pow>The library syntax is B<element_pow>C<(I<nf>,x,k)>. =head2 X<nfeltpowmodpr>nfeltpowmodprC<(I<nf>,x,k,I<pr>)> given an element C<x> in I<nf>, an integer C<k> and a prime ideal I<pr> in C<modpr> format (see X<nfmodprinit>C<nfmodprinit>), computes C<x^k> modulo the prime ideal I<pr>. X<element_powmodpr>The library syntax is B<element_powmodpr>C<(I<nf>,x,k,I<pr>)>. =head2 X<nfeltreduce>nfeltreduceC<(I<nf>,x,I<ideal>)> given an ideal in Hermite normal form and an element C<x> of the number field C<I<nf>>, finds an element C<r> in C<I<nf>> such that C<x-r> belongs to the ideal and C<r> is small. X<element_reduce>The library syntax is B<element_reduce>C<(I<nf>,x,I<ideal>)>. =head2 X<nfeltreducemodpr>nfeltreducemodprC<(I<nf>,x,I<pr>)> given an element C<x> of the number field C<I<nf>> and a prime ideal I<pr> in C<modpr> format compute a canonical representative for the class of C<x> modulo I<pr>. X<nfreducemodpr>The library syntax is B<nfreducemodpr>C<(I<nf>,x,I<pr>)>. =head2 X<nfeltval>nfeltvalC<(I<nf>,x,I<pr>)> given an element C<x> in I<nf> and a prime ideal I<pr> in the format output by C<idealprimedec>, computes their the valuation at I<pr> of the element C<x>. The same result could be obtained using C<idealval(I<nf>,x,I<pr>)> (since C<x> would then be converted to a principal ideal), but it would be less efficient. X<element_val>The library syntax is B<element_val>C<(I<nf>,x,I<pr>)>, and the result is a C<long>. =head2 X<nffactor>nffactorC<(I<nf>,x)> factorization of the univariate polynomial C<x> over the number field C<I<nf>> given by C<nfinit>. C<x> has coefficients in C<I<nf>> (i.e.S< >either scalar, polmod, polynomial or column vector). The main variable of C<I<nf>> must be of \emph{lower} priority than that of C<x> (see L<Label se:priority>). However if the polynomial defining the number field occurs explicitly in the coefficients of C<x> (as modulus of a C<t_POLMOD>), its main variable must be \emph{the same} as the main variable of C<x>. For example, ? nf = nfinit(y^2 + 1); ? nffactor(nf, x^2 + y); \\ OK ? nffactor(nf, x^2 + Mod(y, y^2+1)); \\ OK ? nffactor(nf, x^2 + Mod(z, z^2+1)); \\ WRONG X<nffactor>The library syntax is B<nffactor>C<(I<nf>,x)>. =head2 X<nffactormod>nffactormodC<(I<nf>,x,I<pr>)> factorization of the univariate polynomial C<x> modulo the prime ideal I<pr> in the number field C<I<nf>>. C<x> can have coefficients in the number field (scalar, polmod, polynomial, column vector) or modulo the prime ideal (intmod modulo the rational prime under I<pr>, polmod or polynomial with intmod coefficients, column vector of intmod). The prime ideal I<pr> \emph{must} be in the format output by C<idealprimedec>. The main variable of C<I<nf>> must be of lower priority than that of C<x> (see L<Label se:priority>). However if the coefficients of the number field occur explicitly (as polmods) as coefficients of C<x>, the variable of these polmods \emph{must} be the same as the main variable of C<t> (see C<nffactor>). X<nffactormod>The library syntax is B<nffactormod>C<(I<nf>,x,I<pr>)>. =head2 X<nfgaloisapply>nfgaloisapplyC<(I<nf>,I<aut>,x)> C<I<nf>> being a number field as output by C<nfinit>, and I<aut> being a X<Galois>Galois automorphism of C<I<nf>> expressed either as a polynomial or a polmod (such automorphisms being found using for example one of the variants of C<nfgaloisconj>), computes the action of the automorphism I<aut> on the object C<x> in the number field. C<x> can be an element (scalar, polmod, polynomial or column vector) of the number field, an ideal (either given by C<B<I<Z>>_K>-generators or by a B<I<Z>>-basis), a prime ideal (given as a 5-element row vector) or an idele (given as a 2-element row vector). Because of possible confusion with elements and ideals, other vector or matrix arguments are forbidden. X<galoisapply>The library syntax is B<galoisapply>C<(I<nf>,I<aut>,x)>. =head2 X<nfgaloisconj>nfgaloisconjC<(I<nf>,{I<flag> = 0},{d})> C<I<nf>> being a number field as output by C<nfinit>, computes the conjugates of a root C<r> of the non-constant polynomial C<x = I<nf>[1]> expressed as polynomials in C<r>. This can be used even if the number field C<I<nf>> is not X<Galois>Galois since some conjugates may lie in the field. C<I<nf>> can simply be a polynomial if C<I<flag> ! = 1>. If no flags or C<I<flag> = 0>, if C<I<nf>> is a number field use a combination of flag C<4> and C<1> and the result is always complete, else use a combination of flag C<4> and C<2> and the result is subject to the restriction of C<I<flag> = 2>, but a warning is issued when it is not proven complete. If C<I<flag> = 1>, use C<nfroots> (require a number field). If C<I<flag> = 2>, use complex approximations to the roots and an integral X<LLL>LLL. The result is not guaranteed to be complete: some conjugates may be missing (no warning issued), especially so if the corresponding polynomial has a huge index. In that case, increasing the default precision may help. If C<I<flag> = 4>, use Allombert's algorithm and permutation testing. If the field is Galois with ``weakly'' super solvable Galois group, return the complete list of automorphisms, else only the identity element. If present, C<d> is assumed to be a multiple of the least common denominator of the conjugates expressed as polynomial in a root of I<pol>. A group G is ``weakly'' super solvable (WKSS) if it contains a super solvable normal subgroup C<H> such that C<G = H> , or C<G/H ~ A_4> , or C<G/H ~ S_4>. Abelian and nilpotent groups are WKSS. In practice, almost all groups of small order are WKSS, the exceptions having order 36(1 exception), 48(2), 56(1), 60(1), 72(5), 75(1), 80(1), 96(10) and C< E<gt>= 108>. Hence C<I<flag> = 4> permits to quickly check whether a polynomial of order strictly less than C<36> is Galois or not. This method is much faster than C<nfroots> and can be applied to polynomials of degree larger than C<50>. This routine can only compute B<I<Q>>-automorphisms, but it may be used to get C<K>-automorphism for any base field C<K> as follows: rnfgaloisconj(nfK, R) = \\ K-automorphisms of L = K[X] / (R) { local(polabs, N, H); R *= Mod(1, nfK.pol); \\ convert coeffs to polmod elts of K polabs = rnfequation(nfK, R); N = nfgaloisconj(polabs) % R; \\ Q-automorphisms of L H = []; for(i=1, #N, \\ select the ones that fix K if (subst(R, variable(R), Mod(N[i],R)) == 0, H = concat(H,N[i]) ) ); H } K = nfinit(y^2 + 7); polL = x^4 - y*x^3 - 3*x^2 + y*x + 1; rnfgaloisconj(K, polL) \\ K-automorphisms of L X<galoisconj0>The library syntax is B<galoisconj0>C<(I<nf>,I<flag>,d,I<prec>)>. Also available are C< B<galoisconj>(I<nf>)>X<galoisconj> for C<I<flag> = 0>, C< B<galoisconj2>(I<nf>,n,I<prec>)>X<galoisconj2> for C<I<flag> = 2> where C<n> is a bound on the number of conjugates, and C< B<galoisconj4>(I<nf>,d)>X<galoisconj4> corresponding to C<I<flag> = 4>. =head2 X<nfhilbert>nfhilbertC<(I<nf>,a,b,{I<pr>})> if I<pr> is omitted, compute the global X<Hilbert symbol>Hilbert symbol C<(a,b)> in C<I<nf>>, that is C<1> if C<x^2 - a y^2 - b z^2> has a non trivial solution C<(x,y,z)> in C<I<nf>>, and C<-1> otherwise. Otherwise compute the local symbol modulo the prime ideal I<pr> (as output by C<idealprimedec>). X<nfhilbert>The library syntax is B<nfhilbert>C<(I<nf>,a,b,I<pr>)>, where an omitted I<pr> is coded as C<NULL>. =head2 X<nfhnf>nfhnfC<(I<nf>,x)> given a pseudo-matrix C<(A,I)>, finds a pseudo-basis in X<Hermite normal form>Hermite normal form of the module it generates. X<nfhermite>The library syntax is B<nfhermite>C<(I<nf>,x)>. =head2 X<nfhnfmod>nfhnfmodC<(I<nf>,x,I<detx>)> given a pseudo-matrix C<(A,I)> and an ideal I<detx> which is contained in (read integral multiple of) the determinant of C<(A,I)>, finds a pseudo-basis in X<Hermite normal form>Hermite normal form of the module generated by C<(A,I)>. This avoids coefficient explosion. I<detx> can be computed using the function C<nfdetint>. X<nfhermitemod>The library syntax is B<nfhermitemod>C<(I<nf>,x,I<detx>)>. =head2 X<nfinit>nfinitC<(I<pol>,{I<flag> = 0})> I<pol> being a non-constant, preferably monic, irreducible polynomial in C<B<I<Z>>[X]>, initializes a \emph{number field} structure (C<nf>) associated to the field C<K> defined by I<pol>. As such, it's a technical object passed as the first argument to most C<nf>I<xxx> functions, but it contains some information which may be directly useful. Access to this information via \emph{member functions} is preferred since the specific data organization specified below may change in the future. Currently, C<nf> is a row vector with 9 components: C<I<nf>[1]> contains the polynomial I<pol> (C<I<nf>.pol>). C<I<nf>[2]> contains C<[r1,r2]> (C<I<nf>.sign>, C<I<nf>.r1>, C<I<nf>.r2>), the number of real and complex places of C<K>. C<I<nf>[3]> contains the discriminant C<d(K)> (C<I<nf>.disc>) of C<K>. C<I<nf>[4]> contains the index of C<I<nf>[1]> (C<I<nf>.index>), i.e.S< >C<[B<I<Z>>_K : B<I<Z>>[F<theta>]]>, where C<F<theta>> is any root of C<I<nf>[1]>. C<I<nf>[5]> is a vector containing 7 matrices C<M>, C<G>, C<T2>, C<T>, C<MD>, C<TI>, C<MDI> useful for certain computations in the number field C<K>. S< >S< >\item C<M> is the C<(r1+r2) x n> matrix whose columns represent the numerical values of the conjugates of the elements of the integral basis. S< >S< >\item C<G> is such that C<T2 = ^t G G>, where C<T2> is the quadratic form C<T_2(x) = F<sum> |F<sigma>(x)|^2>, C<F<sigma>> running over the embeddings of C<K> into B<I<C>>. S< >S< >\item The C<T2> component is deprecated and currently unused. S< >S< >\item C<T> is the C<n x n> matrix whose coefficients are C<Tr(F<omega>_iF<omega>_j)> where the C<F<omega>_i> are the elements of the integral basis. Note also that C< F<det> (T)> is equal to the discriminant of the field C<K>. S< >S< >\item The columns of C<MD> (C<I<nf>.diff>) express a B<I<Z>>-basis of the different of C<K> on the integral basis. S< >S< >\item C<TI> is equal to C<d(K)T^{-1}>, which has integral coefficients. Note that, understood as as ideal, the matrix C<T^{-1}> generates the codifferent ideal. S< >S< >\item Finally, C<MDI> is a two-element representation (for faster ideal product) of C<d(K)> times the codifferent ideal (C<I<nf>.disc*I<nf>.codiff>, which is an integral ideal). C<MDI> is only used in X<idealinv>C<idealinv>. C<I<nf>[6]> is the vector containing the C<r1+r2> roots (C<I<nf>.roots>) of C<I<nf>[1]> corresponding to the C<r1+r2> embeddings of the number field into B<I<C>> (the first C<r1> components are real, the next C<r2> have positive imaginary part). C<I<nf>[7]> is an integral basis for C<B<I<Z>>_K> (C<I<nf>.zk>) expressed on the powers ofS< >C<F<theta>>. Its first element is guaranteed to be C<1>. This basis is LLL-reduced with respect to C<T_2> (strictly speaking, it is a permutation of such a basis, due to the condition that the first element be C<1>). C<I<nf>[8]> is the C<n x n> integral matrix expressing the power basis in terms of the integral basis, and finally C<I<nf>[9]> is the C<n x n^2> matrix giving the multiplication table of the integral basis. If a non monic polynomial is input, C<nfinit> will transform it into a monic one, then reduce it (see C<I<flag> = 3>). It is allowed, though not very useful given the existence of X<nfnewprec>C<nfnewprec>, to input a C<nf> or a C<bnf> instead of a polynomial. ? nf = nfinit(x^3 - 12); \\ initialize number field Q[X] / (X^3 - 12) ? nf.pol \\ defining polynomial %2 = x^3 - 12 ? nf.disc \\ field discriminant %3 = -972 ? nf.index \\ index of power basis order in maximal order %4 = 2 ? nf.zk \\ integer basis, lifted to Q[X] %5 = [1, x, 1/2*x^2] ? nf.sign \\ signature %6 = [1, 1] ? factor(abs(nf.disc )) \\ determines ramified primes %7 = [2 2] [3 5] ? idealfactor(nf, 2) %8 = [[2, [0, 0, -1]~, 3, 1, [0, 1, 0]~] 3] \\ \goth{P}_2^3 In case I<pol> has a huge discriminant which is difficult to factor, the special input format C<[I<pol>,B]> is also accepted where I<pol> is a polynomial as above and C<B> is the integer basis, as would be computed by X<nfbasis>C<nfbasis>. This is useful if the integer basis is known in advance, or was computed conditionnally. ? pol = polcompositum(x^5 - 101, polcyclo(7))[1]; ? B = nfbasis(pol, 1); \\ faster than nfbasis(pol), but conditional ? nf = nfinit( [pol, B] ); ? factor( abs(nf.disc) ) [5 18] [7 25] [101 24] C<B> is conditional when its discriminant, which is C<nf.disc>, can't be factored. In this example, the above factorization proves the correctness of the computation. If C<I<flag> = 2>: I<pol> is changed into another polynomial C<P> defining the same number field, which is as simple as can easily be found using the C<polred> algorithm, and all the subsequent computations are done using this new polynomial. In particular, the first component of the result is the modified polynomial. If C<I<flag> = 3>, does a C<polred> as in case 2, but outputs C<[I<nf>,Mod(a,P)]>, where C<I<nf>> is as before and C<Mod(a,P) = Mod(x,I<pol>)> gives the change of variables. This is implicit when I<pol> is not monic: first a linear change of variables is performed, to get a monic polynomial, then a C<polred> reduction. If C<I<flag> = 4>, as C<2> but uses a partial C<polred>. If C<I<flag> = 5>, as C<3> using a partial C<polred>. X<nfinit0>The library syntax is B<nfinit0>C<(x,I<flag>,I<prec>)>. =head2 X<nfisideal>nfisidealC<(I<nf>,x)> returns 1 if C<x> is an ideal in the number field C<I<nf>>, 0 otherwise. X<isideal>The library syntax is B<isideal>C<(x)>. =head2 X<nfisincl>nfisinclC<(x,y)> tests whether the number field C<K> defined by the polynomial C<x> is conjugate to a subfield of the field C<L> defined by C<y> (where C<x> and C<y> must be in C<B<I<Q>>[X]>). If they are not, the output is the number 0. If they are, the output is a vector of polynomials, each polynomial C<a> representing an embedding of C<K> into C<L>, i.e.S< >being such that C<y | x o a>. If C<y> is a number field (I<nf>), a much faster algorithm is used (factoring C<x> over C<y> using X<nffactor>C<nffactor>). Before version 2.0.14, this wasn't guaranteed to return all the embeddings, hence was triggered by a special flag. This is no more the case. X<nfisincl>The library syntax is B<nfisincl>C<(x,y,I<flag>)>. =head2 X<nfisisom>nfisisomC<(x,y)> as X<nfisincl>C<nfisincl>, but tests for isomorphism. If either C<x> or C<y> is a number field, a much faster algorithm will be used. X<nfisisom>The library syntax is B<nfisisom>C<(x,y,I<flag>)>. =head2 X<nfnewprec>nfnewprecC<(I<nf>)> transforms the number field C<I<nf>> into the corresponding data using current (usually larger) precision. This function works as expected if C<I<nf>> is in fact a C<I<bnf>> (update C<I<bnf>> to current precision) but may be quite slow (many generators of principal ideals have to be computed). X<nfnewprec>The library syntax is B<nfnewprec>C<(I<nf>,I<prec>)>. =head2 X<nfkermodpr>nfkermodprC<(I<nf>,a,I<pr>)> kernel of the matrix C<a> in C<B<I<Z>>_K/I<pr>>, where I<pr> is in B<modpr> format (see C<nfmodprinit>). X<nfkermodpr>The library syntax is B<nfkermodpr>C<(I<nf>,a,I<pr>)>. =head2 X<nfmodprinit>nfmodprinitC<(I<nf>,I<pr>)> transforms the prime ideal I<pr> into X<modpr>C<modpr> format necessary for all operations modulo I<pr> in the number field I<nf>.X<Label se:nfmodprinit> X<nfmodprinit>The library syntax is B<nfmodprinit>C<(I<nf>,I<pr>)>. =head2 X<nfsubfields>nfsubfieldsC<(I<pol>,{d = 0})> finds all subfields of degree C<d> of the number field defined by the (monic, integral) polynomial I<pol> (all subfields if C<d> is null or omitted). The result is a vector of subfields, each being given by C<[g,h]>, where C<g> is an absolute equation and C<h> expresses one of the roots of C<g> in terms of the root C<x> of the polynomial defining C<I<nf>>. This routine uses J.S< >KlE<uuml>ners's algorithm in the general case, and B.S< >Allombert's X<galoissubfields>C<galoissubfields> when I<nf> is Galois (with weakly supersolvable Galois group).X<Galois>X<subfield> X<subfields>The library syntax is B<subfields>C<(I<nf>,d)>. =head2 X<nfroots>nfrootsC<({I<nf>},x)> roots of the polynomial C<x> in the number field C<I<nf>> given by C<nfinit> without multiplicity (in B<I<Q>> if C<I<nf>> is omitted). C<x> has coefficients in the number field (scalar, polmod, polynomial, column vector). The main variable of C<I<nf>> must be of lower priority than that of C<x> (see L<Label se:priority>). However if the coefficients of the number field occur explicitly (as polmods) as coefficients of C<x>, the variable of these polmods \emph{must} be the same as the main variable of C<t> (see C<nffactor>). X<nfroots>The library syntax is B<nfroots>C<(I<nf>,x)>. =head2 X<nfrootsof1>nfrootsof1C<(I<nf>)> computes the number of roots of unity C<w> and a primitive C<w>-th root of unity (expressed on the integral basis) belonging to the number field C<I<nf>>. The result is a two-component vector C<[w,z]> where C<z> is a column vector expressing a primitive C<w>-th root of unity on the integral basis C<I<nf>.zk>. X<rootsof1>The library syntax is B<rootsof1>C<(I<nf>)>. =head2 X<nfsnf>nfsnfC<(I<nf>,x)> given a torsion module C<x> as a 3-component row vector C<[A,I,J]> where C<A> is a square invertible C<n x n> matrix, C<I> and C<J> are two ideal lists, outputs an ideal list C<d_1,...,d_n> which is the X<Smith normal form>Smith normal form of C<x>. In other words, C<x> is isomorphic to C<B<I<Z>>_K/d_1 F<oplus> ... F<oplus> B<I<Z>>_K/d_n> and C<d_i> divides C<d_{i-1}> for C<i E<gt>= 2>. The link between C<x> and C<[A,I,J]> is as follows: if C<e_i> is the canonical basis of C<K^n>, C<I = [b_1,...,b_n]> and C<J = [a_1,...,a_n]>, then C<x> is isomorphic to S< >C< (b_1e_1 F<oplus> ... F<oplus> b_ne_n) / (a_1A_1 F<oplus> ... F<oplus> a_nA_n) , > where the C<A_j> are the columns of the matrix C<A>. Note that every finitely generated torsion module can be given in this way, and even with C<b_i = Z_K> for all C<i>. X<nfsmith>The library syntax is B<nfsmith>C<(I<nf>,x)>. =head2 X<nfsolvemodpr>nfsolvemodprC<(I<nf>,a,b,I<pr>)> solution of C<a.x = b> in C<B<I<Z>>_K/I<pr>>, where C<a> is a matrix and C<b> a column vector, and where I<pr> is in B<modpr> format (see C<nfmodprinit>). X<nfsolvemodpr>The library syntax is B<nfsolvemodpr>C<(I<nf>,a,b,I<pr>)>. =head2 X<polcompositum>polcompositumC<(P,Q,{I<flag> = 0})> X<compositum>C<P> and C<Q> being squarefree polynomials in C<B<I<Z>>[X]> in the same variable, outputs the simple factors of the E<eacute>tale B<I<Q>>-algebra C<A = B<I<Q>>(X, Y) / (P(X), Q(Y))>. The factors are given by a list of polynomials C<R> in C<B<I<Z>>[X]>, associated to the number field C<B<I<Q>>(X)/ (R)>, and sorted by increasing degree (with respect to lexicographic ordering for factors of equal degrees). Returns an error if one of the polynomials is not squarefree. Note that it is more efficient to reduce to the case where C<P> and C<Q> are irreducible first. The routine will not perform this for you, since it may be expensive, and the inputs are irreducible in most applications anyway. Assuming C<P> is irreducible (of smaller degree than C<Q> for efficiency), it is in general \emph{much} faster to proceed as follows nf = nfinit(P); L = nffactor(nf, Q)[,1]; vector(#L, i, rnfequation(nf, L[i])) to obtain the same result. If you are only interested in the degrees of the simple factors, the C<rnfequation> instruction can be replaced by a trivial C<poldegree(P) * poldegree(L[i])>. If C<I<flag> = 1>, outputs a vector of 4-component vectors C<[R,a,b,k]>, where C<R> ranges through the list of all possible compositums as above, and C<a> (resp. C<b>) expresses the root of C<P> (resp. C<Q>) as an element of C<B<I<Q>>(X)/(R)>. Finally, C<k> is a small integer such that C<b + ka = X> modulo C<R>. A compositum is quite often defined by a complicated polynomial, which it is advisable to reduce before further work. Here is a simple example involving the field C<B<I<Q>>(F<zeta>_5, 5^{1/5})>: ? z = polcompositum(x^5 - 5, polcyclo(5), 1)[1]; ? pol = z[1] \\ pol defines the compositum %2 = x^20 + 5*x^19 + 15*x^18 + 35*x^17 + 70*x^16 + 141*x^15 + 260*x^14 \ + 355*x^13 + 95*x^12 - 1460*x^11 - 3279*x^10 - 3660*x^9 - 2005*x^8 \ + 705*x^7 + 9210*x^6 + 13506*x^5 + 7145*x^4 - 2740*x^3 + 1040*x^2 \ - 320*x + 256 ? a = z[2]; a^5 - 5 \\ a is a fifth root of 5 %3 = 0 ? z = polredabs(pol, 1); \\ look for a simpler polynomial ? pol = z[1] %5 = x^20 + 25*x^10 + 5 ? a = subst(a.pol, x, z[2]) \\ a in the new coordinates %6 = Mod(-5/22*x^19 + 1/22*x^14 - 123/22*x^9 + 9/11*x^4, x^20 + 25*x^10 + 5) X<polcompositum0>The library syntax is B<polcompositum0>C<(P,Q,I<flag>)>. =head2 X<polgalois>polgaloisC<(x)> X<Galois>Galois group of the non-constant polynomial C<x belongs to B<I<Q>>[X]>. In the present version B<2.2.0>, C<x> must be irreducible and the degree of C<x> must be less than or equal to 7. On certain versions for which the data file of Galois resolvents has been installed (available in the Unix distribution as a separate package), degrees 8, 9, 10 and 11 are also implemented. The output is a 4-component vector C<[n,s,k,name]> with the following meaning: C<n> is the cardinality of the group, C<s> is its signature (C<s = 1> if the group is a subgroup of the alternating group C<A_n>, C<s = -1> otherwise) and name is a character string containing name of the transitive group according to the GAP 4 transitive groups library by Alexander Hulpke. C<k> is more arbitrary and the choice made up to versionS< >2.2.3 of PARI is rather unfortunate: for C<n E<gt> 7>, C<k> is the numbering of the group among all transitive subgroups of C<S_n>, as given in ``The transitive groups of degree up to eleven'', G.S< >Butler and J.S< >McKay, \emph{Communications in Algebra}, vol.S< >11, 1983, pp.S< >863--911 (group C<k> is denoted C<T_k> there). And for C<n E<lt>= 7>, it was ad hoc, so as to ensure that a given triple would design a unique group. Specifically, for polynomials of degree C< E<lt>= 7>, the groups are coded as follows, using standard notations In degree 1: C<S_1 = [1,1,1]>. In degree 2: C<S_2 = [2,-1,1]>. In degree 3: C<A_3 = C_3 = [3,1,1]>, C<S_3 = [6,-1,1]>. In degree 4: C<C_4 = [4,-1,1]>, C<V_4 = [4,1,1]>, C<D_4 = [8,-1,1]>, C<A_4 = [12,1,1]>, C<S_4 = [24,-1,1]>. In degree 5: C<C_5 = [5,1,1]>, C<D_5 = [10,1,1]>, C<M_{20} = [20,-1,1]>, C<A_5 = [60,1,1]>, C<S_5 = [120,-1,1]>. In degree 6: C<C_6 = [6,-1,1]>, C<S_3 = [6,-1,2]>, C<D_6 = [12,-1,1]>, C<A_4 = [12,1,1]>, C<G_{18} = [18,-1,1]>, C<S_4^ -= [24,-1,1]>, C<A_4 x C_2 = [24,-1,2]>, C<S_4^ += [24,1,1]>, C<G_{36}^ -= [36,-1,1]>, C<G_{36}^ += [36,1,1]>, C<S_4 x C_2 = [48,-1,1]>, C<A_5 = PSL_2(5) = [60,1,1]>, C<G_{72} = [72,-1,1]>, C<S_5 = PGL_2(5) = [120,-1,1]>, C<A_6 = [360,1,1]>, C<S_6 = [720,-1,1]>. In degree 7: C<C_7 = [7,1,1]>, C<D_7 = [14,-1,1]>, C<M_{21} = [21,1,1]>, C<M_{42} = [42,-1,1]>, C<PSL_2(7) = PSL_3(2) = [168,1,1]>, C<A_7 = [2520,1,1]>, C<S_7 = [5040,-1,1]>. This is deprecated and obsolete, but for reasons of backward compatibility, we cannot change this behaviour yet. So you can use the default X<new_galois_format>C<new_galois_format> to switch to a consistent naming scheme, namely C<k> is always the standard numbering of the group among all transitive subgroups of C<S_n>. If this default is in effect, the above groups will be coded as: In degree 1: C<S_1 = [1,1,1]>. In degree 2: C<S_2 = [2,-1,1]>. In degree 3: C<A_3 = C_3 = [3,1,1]>, C<S_3 = [6,-1,2]>. In degree 4: C<C_4 = [4,-1,1]>, C<V_4 = [4,1,2]>, C<D_4 = [8,-1,3]>, C<A_4 = [12,1,4]>, C<S_4 = [24,-1,5]>. In degree 5: C<C_5 = [5,1,1]>, C<D_5 = [10,1,2]>, C<M_{20} = [20,-1,3]>, C<A_5 = [60,1,4]>, C<S_5 = [120,-1,5]>. In degree 6: C<C_6 = [6,-1,1]>, C<S_3 = [6,-1,2]>, C<D_6 = [12,-1,3]>, C<A_4 = [12,1,4]>, C<G_{18} = [18,-1,5]>, C<A_4 x C_2 = [24,-1,6]>, C<S_4^ += [24,1,7]>, C<S_4^ -= [24,-1,8]>, C<G_{36}^ -= [36,-1,9]>, C<G_{36}^ += [36,1,10]>, C<S_4 x C_2 = [48,-1,11]>, C<A_5 = PSL_2(5) = [60,1,12]>, C<G_{72} = [72,-1,13]>, C<S_5 = PGL_2(5) = [120,-1,14]>, C<A_6 = [360,1,15]>, C<S_6 = [720,-1,16]>. In degree 7: C<C_7 = [7,1,1]>, C<D_7 = [14,-1,2]>, C<M_{21} = [21,1,3]>, C<M_{42} = [42,-1,4]>, C<PSL_2(7) = PSL_3(2) = [168,1,5]>, C<A_7 = [2520,1,6]>, C<S_7 = [5040,-1,7]>. B<Warning:> The method used is that of resolvent polynomials and is sensitive to the current precision. The precision is updated internally but, in very rare cases, a wrong result may be returned if the initial precision was not sufficient. X<polgalois>The library syntax is B<polgalois>C<(x,I<prec>)>. To enable the new format in library mode, set the global variable X<new_galois_format>C<new_galois_format> to C<1>. =head2 X<polred>polredC<(x,{I<flag> = 0},{fa})> finds polynomials with reasonably small coefficients defining subfields of the number field defined by C<x>. One of the polynomials always defines B<I<Q>> (hence is equal to C<x-1>), and another always defines the same number field as C<x> if C<x> is irreducible. All C<x> accepted by X<nfinit>C<nfinit> are also allowed here (e.g. non-monic polynomials, C<nf>, C<bnf>, C<[x,Z_K_basis]>). The following binary digits of C<I<flag>> are significant: 1: possibly use a suborder of the maximal order. The primes dividing the index of the order chosen are larger than X<primelimit>C<primelimit> or divide integers stored in the X<addprimes>C<addprimes> table. 2: gives also elements. The result is a two-column matrix, the first column giving the elements defining these subfields, the second giving the corresponding minimal polynomials. If C<fa> is given, it is assumed that it is the two-column matrix of the factorization of the discriminant of the polynomial C<x>. X<polred0>The library syntax is B<polred0>C<(x,I<flag>,fa)>, where an omitted C<fa> is coded by C<NULL>. Also available are C< B<polred>(x)>X<polred> and C< B<factoredpolred>(x,fa)>X<factoredpolred>, both corresponding to C<I<flag> = 0>. =head2 X<polredabs>polredabsC<(x,{I<flag> = 0})> finds one of the polynomial defining the same number field as the one defined by C<x>, and such that the sum of the squares of the modulus of the roots (i.e.S< >the C<T_2>-norm) is minimal. All C<x> accepted by X<nfinit>C<nfinit> are also allowed here (e.g. non-monic polynomials, C<nf>, C<bnf>, C<[x,Z_K_basis]>). B<Warning:> this routine uses an exponential-time algorithm to enumerate all potential generators, and may be exceedingly slow when the number field has many subfields, hence a lot of elements of small C<T_2>-norm. E.g. do not try it on the compositum of many quadratic fields, use X<polred>C<polred> instead. The binary digits of C<I<flag>> mean 1: outputs a two-component row vector C<[P,a]>, where C<P> is the default output and C<a> is an element expressed on a root of the polynomial C<P>, whose minimal polynomial is equal to C<x>. 4: gives \emph{all} polynomials of minimal C<T_2> norm (of the two polynomials C<P(x)> and C<P(-x)>, only one is given). 16: possibly use a suborder of the maximal order. The primes dividing the index of the order chosen are larger than X<primelimit>C<primelimit> or divide integers stored in the X<addprimes>C<addprimes> table. In that case it may happen that the output polynomial does not have minimal C<T_2> norm.X<Label se:polredabs> X<polredabs0>The library syntax is B<polredabs0>C<(x,I<flag>)>. =head2 X<polredord>polredordC<(x)> finds polynomials with reasonably small coefficients and of the same degree as that of C<x> defining suborders of the order defined by C<x>. One of the polynomials always defines B<I<Q>> (hence is equal to C<(x-1)^n>, where C<n> is the degree), and another always defines the same order as C<x> if C<x> is irreducible. X<ordred>The library syntax is B<ordred>C<(x)>. =head2 X<poltschirnhaus>poltschirnhausC<(x)> applies a random Tschirnhausen transformation to the polynomial C<x>, which is assumed to be non-constant and separable, so as to obtain a new equation for the E<eacute>tale algebra defined by C<x>. This is for instance useful when computing resolvents, hence is used by the C<polgalois> function. X<tschirnhaus>The library syntax is B<tschirnhaus>C<(x)>. =head2 X<rnfalgtobasis>rnfalgtobasisC<(I<rnf>,x)> expresses C<x> on the relative integral basis. Here, C<I<rnf>> is a relative number field extension C<L/K> as output by C<rnfinit>, and C<x> an element of C<L> in absolute form, i.e. expressed as a polynomial or polmod with polmod coefficients, \emph{not} on the relative integral basis. X<rnfalgtobasis>The library syntax is B<rnfalgtobasis>C<(I<rnf>,x)>. =head2 X<rnfbasis>rnfbasisC<(I<bnf>, M)> let C<K> the field represented by I<bnf>, as output by C<bnfinit>. C<M> is a projective C<B<I<Z>>_K>-module given by a pseudo-basis, as output by C<rnfhnfbasis>. The routine returns either a true C<B<I<Z>>_K>-basis of C<M> if it exists, or an C<n+1>-element generating set of C<M> if not, where C<n> is the rank of C<M> over C<I<K>>. (Note that C<n> is the size of the pseudo-basis.) It is allowed to use a polynomial C<P> with coefficients in C<K> instead of C<M>, in which case, C<M> is defined as the ring of integers of C<K[X]/(P)> (C<P> is assumed irreducible over C<K>), viewed as a C<B<I<Z>>_K>-module. X<rnfbasis>The library syntax is B<rnfbasis>C<(I<bnf>,x)>. =head2 X<rnfbasistoalg>rnfbasistoalgC<(I<rnf>,x)> computes the representation of C<x> as a polmod with polmods coefficients. Here, C<I<rnf>> is a relative number field extension C<L/K> as output by C<rnfinit>, and C<x> an element of C<L> expressed on the relative integral basis. X<rnfbasistoalg>The library syntax is B<rnfbasistoalg>C<(I<rnf>,x)>. =head2 X<rnfcharpoly>rnfcharpolyC<(I<nf>,T,a,{v = x})> characteristic polynomial of C<a> over C<I<nf>>, where C<a> belongs to the algebra defined by C<T> over C<I<nf>>, i.e.S< >C<I<nf>[X]/(T)>. Returns a polynomial in variable C<v> (C<x> by default). X<rnfcharpoly>The library syntax is B<rnfcharpoly>C<(I<nf>,T,a,v)>, where C<v> is a variable number. =head2 X<rnfconductor>rnfconductorC<(I<bnf>,I<pol>,{I<flag> = 0})> given C<I<bnf>> as output by C<bnfinit>, and I<pol> a relative polynomial defining an X<Abelian extension>Abelian extension, computes the class field theory conductor of this Abelian extension. The result is a 3-component vector C<[I<conductor>,I<rayclgp>,I<subgroup>]>, where I<conductor> is the conductor of the extension given as a 2-component row vector C<[f_0,f_ oo ]>, I<rayclgp> is the full ray class group corresponding to the conductor given as a 3-component vector [h,cyc,gen] as usual for a group, and I<subgroup> is a matrix in HNF defining the subgroup of the ray class group on the given generators gen. If C<I<flag>> is non-zero, check that I<pol> indeed defines an Abelian extension, return 0 if it does not. X<rnfconductor>The library syntax is B<rnfconductor>C<(I<rnf>,I<pol>,I<flag>)>. =head2 X<rnfdedekind>rnfdedekindC<(I<nf>,I<pol>,I<pr>)> given a number field C<I<nf>> as output by C<nfinit> and a polynomial I<pol> with coefficients in C<I<nf>> defining a relative extension C<L> of C<I<nf>>, evaluates the relative X<Dedekind>Dedekind criterion over the order defined by a root of I<pol> for the prime ideal I<pr> and outputs a 3-component vector as the result. The first component is a flag equal to 1 if the enlarged order could be proven to be I<pr>-maximal and to 0 otherwise (it may be maximal in the latter case if I<pr> is ramified in C<L>), the second component is a pseudo-basis of the enlarged order and the third component is the valuation at I<pr> of the order discriminant. X<rnfdedekind>The library syntax is B<rnfdedekind>C<(I<nf>,I<pol>,I<pr>)>. =head2 X<rnfdet>rnfdetC<(I<nf>,M)> given a pseudo-matrix C<M> over the maximal order of C<I<nf>>, computes its determinant. X<rnfdet>The library syntax is B<rnfdet>C<(I<nf>,M)>. =head2 X<rnfdisc>rnfdiscC<(I<nf>,I<pol>)> given a number field C<I<nf>> as output by C<nfinit> and a polynomial I<pol> with coefficients in C<I<nf>> defining a relative extension C<L> of C<I<nf>>, computes the relative discriminant of C<L>. This is a two-element row vector C<[D,d]>, where C<D> is the relative ideal discriminant and C<d> is the relative discriminant considered as an element of C<I<nf>^*/{I<nf>^*}^2>. The main variable of C<I<nf>> \emph{must} be of lower priority than that of I<pol>, see L<Label se:priority>. X<rnfdiscf>The library syntax is B<rnfdiscf>C<(I<bnf>,I<pol>)>. =head2 X<rnfeltabstorel>rnfeltabstorelC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being an element of C<L> expressed as a polynomial modulo the absolute equation C<I<rnf>.pol>, computes C<x> as an element of the relative extension C<L/K> as a polmod with polmod coefficients. X<rnfelementabstorel>The library syntax is B<rnfelementabstorel>C<(I<rnf>,x)>. =head2 X<rnfeltdown>rnfeltdownC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being an element of C<L> expressed as a polynomial or polmod with polmod coefficients, computes C<x> as an element of C<K> as a polmod, assuming C<x> is in C<K> (otherwise an error will occur). If C<x> is given on the relative integral basis, apply C<rnfbasistoalg> first, otherwise PARI will believe you are dealing with a vector. X<rnfelementdown>The library syntax is B<rnfelementdown>C<(I<rnf>,x)>. =head2 X<rnfeltreltoabs>rnfeltreltoabsC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being an element of C<L> expressed as a polynomial or polmod with polmod coefficients, computes C<x> as an element of the absolute extension C<L/B<I<Q>>> as a polynomial modulo the absolute equation C<I<rnf>.pol>. If C<x> is given on the relative integral basis, apply C<rnfbasistoalg> first, otherwise PARI will believe you are dealing with a vector. X<rnfelementreltoabs>The library syntax is B<rnfelementreltoabs>C<(I<rnf>,x)>. =head2 X<rnfeltup>rnfeltupC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being an element of C<K> expressed as a polynomial or polmod, computes C<x> as an element of the absolute extension C<L/B<I<Q>>> as a polynomial modulo the absolute equation C<I<rnf>.pol>. If C<x> is given on the integral basis of C<K>, apply C<nfbasistoalg> first, otherwise PARI will believe you are dealing with a vector. X<rnfelementup>The library syntax is B<rnfelementup>C<(I<rnf>,x)>. =head2 X<rnfequation>rnfequationC<(I<nf>,I<pol>,{I<flag> = 0})> given a number field C<I<nf>> as output by C<nfinit> (or simply a polynomial) and a polynomial I<pol> with coefficients in C<I<nf>> defining a relative extension C<L> of C<I<nf>>, computes the absolute equation of C<L> over B<I<Q>>. If C<I<flag>> is non-zero, outputs a 3-component row vector C<[z,a,k]>, where C<z> is the absolute equation of C<L> over B<I<Q>>, as in the default behaviour, C<a> expresses as an element of C<L> a root C<F<alpha>> of the polynomial defining the base field C<I<nf>>, and C<k> is a small integer such that C<F<theta> = F<beta>+kF<alpha>> where C<F<theta>> is a root of C<z> and C<F<beta>> a root of C<I<pol>>. The main variable of C<I<nf>> \emph{must} be of lower priority than that of I<pol> (see L<Label se:priority>). Note that for efficiency, this does not check whether the relative equation is irreducible over C<I<nf>>, but only if it is squarefree. If it is reducible but squarefree, the result will be the absolute equation of the E<eacute>tale algebra defined by I<pol>. If I<pol> is not squarefree, an error message will be issued. X<rnfequation0>The library syntax is B<rnfequation0>C<(I<nf>,I<pol>,I<flag>)>. =head2 X<rnfhnfbasis>rnfhnfbasisC<(I<bnf>,x)> given C<I<bnf>> as output by C<bnfinit>, and either a polynomial C<x> with coefficients in C<I<bnf>> defining a relative extension C<L> of C<I<bnf>>, or a pseudo-basis C<x> of such an extension, gives either a true C<I<bnf>>-basis of C<L> in upper triangular Hermite normal form, if it exists, and returns C<0> otherwise. X<rnfhnfbasis>The library syntax is B<rnfhnfbasis>C<(I<nf>,x)>. =head2 X<rnfidealabstorel>rnfidealabstorelC<(I<rnf>,x)> let C<I<rnf>> be a relative number field extension C<L/K> as output by C<rnfinit>, and C<x> an ideal of the absolute extension C<L/B<I<Q>>> given by a B<I<Z>>-basis of elements of C<L>. Returns the relative pseudo-matrix in HNF giving the ideal C<x> considered as an ideal of the relative extension C<L/K>. If C<x> is an ideal in HNF form, associated to an I<nf> structure, for instance as output by C<X<idealhnf>idealhnf(I<nf>,...)>, use C<rnfidealabstorel(rnf, nf.zk * x)> to convert it to a relative ideal. X<rnfidealabstorel>The library syntax is B<rnfidealabstorel>C<(I<rnf>,x)>.X<Label se:rnfidealabstorel> =head2 X<rnfidealdown>rnfidealdownC<(I<rnf>,x)> let C<I<rnf>> be a relative number field extension C<L/K> as output by C<rnfinit>, and C<x> an ideal of C<L>, given either in relative form or by a B<I<Z>>-basis of elements of C<L> (see L<Label se:rnfidealabstorel>), returns the ideal of C<K> below C<x>, i.e.S< >the intersection of C<x> with C<K>. X<rnfidealdown>The library syntax is B<rnfidealdown>C<(I<rnf>,x)>. =head2 X<rnfidealhnf>rnfidealhnfC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being a relative ideal (which can be, as in the absolute case, of many different types, including of course elements), computes the HNF pseudo-matrix associated to C<x>, viewed as a C<B<I<Z>>_K>-module. X<rnfidealhermite>The library syntax is B<rnfidealhermite>C<(I<rnf>,x)>. =head2 X<rnfidealmul>rnfidealmulC<(I<rnf>,x,y)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> and C<y> being ideals of the relative extension C<L/K> given by pseudo-matrices, outputs the ideal product, again as a relative ideal. X<rnfidealmul>The library syntax is B<rnfidealmul>C<(I<rnf>,x,y)>. =head2 X<rnfidealnormabs>rnfidealnormabsC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being a relative ideal (which can be, as in the absolute case, of many different types, including of course elements), computes the norm of the ideal C<x> considered as an ideal of the absolute extension C<L/B<I<Q>>>. This is identical to C<idealnorm(rnfidealnormrel(I<rnf>,x))>, but faster. X<rnfidealnormabs>The library syntax is B<rnfidealnormabs>C<(I<rnf>,x)>. =head2 X<rnfidealnormrel>rnfidealnormrelC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being a relative ideal (which can be, as in the absolute case, of many different types, including of course elements), computes the relative norm of C<x> as a ideal of C<K> in HNF. X<rnfidealnormrel>The library syntax is B<rnfidealnormrel>C<(I<rnf>,x)>. =head2 X<rnfidealreltoabs>rnfidealreltoabsC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being a relative ideal, gives the ideal C<xB<I<Z>>_L> as an absolute ideal of C<L/B<I<Q>>>, in the form of a B<I<Z>>-basis, given by a vector of polynomials (modulo C<rnf.pol>). The following routine might be useful: \\ return y = rnfidealreltoabs(rnf,...) as an ideal in HNF form \\ associated to nf = nfinit( rnf.pol ); idealgentoHNF(nf, y) = mathnf( Mat( nfalgtobasis(nf, y) ) ); X<rnfidealreltoabs>The library syntax is B<rnfidealreltoabs>C<(I<rnf>,x)>. =head2 X<rnfidealtwoelt>rnfidealtwoeltC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being an ideal of the relative extension C<L/K> given by a pseudo-matrix, gives a vector of two generators of C<x> over C<B<I<Z>>_L> expressed as polmods with polmod coefficients. X<rnfidealtwoelement>The library syntax is B<rnfidealtwoelement>C<(I<rnf>,x)>. =head2 X<rnfidealup>rnfidealupC<(I<rnf>,x)> C<I<rnf>> being a relative number field extension C<L/K> as output by C<rnfinit> and C<x> being an ideal of C<K>, gives the ideal C<xB<I<Z>>_L> as an absolute ideal of C<L/B<I<Q>>>, in the form of a B<I<Z>>-basis, given by a vector of polynomials (modulo C<rnf.pol>). The following routine might be useful: \\ return y = rnfidealup(rnf,...) as an ideal in HNF form \\ associated to nf = nfinit( rnf.pol ); idealgentoHNF(nf, y) = mathnf( Mat( nfalgtobasis(nf, y) ) ); X<rnfidealup>The library syntax is B<rnfidealup>C<(I<rnf>,x)>. =head2 X<rnfinit>rnfinitC<(I<nf>,I<pol>)> C<I<nf>> being a number field in C<nfinit> format considered as base field, and I<pol> a polynomial defining a relative extension over C<I<nf>>, this computes all the necessary data to work in the relative extension. The main variable of I<pol> must be of higher priority (see L<Label se:priority>) than that of C<I<nf>>, and the coefficients of I<pol> must be in C<I<nf>>. The result is a row vector, whose components are technical. In the following description, we let C<K> be the base field defined by C<I<nf>>, C<m> the degree of the base field, C<n> the relative degree, C<L> the large field (of relative degree C<n> or absolute degree C<nm>), C<r_1> and C<r_2> the number of real and complex places of C<K>. C<I<rnf>[1]> contains the relative polynomial I<pol>. C<I<rnf>[2]> is currently unused. C<I<rnf>[3]> is a two-component row vector C<[\goth{d}(L/K),s]> where C<\goth{d}(L/K)> is the relative ideal discriminant of C<L/K> and C<s> is the discriminant of C<L/K> viewed as an element of C<K^*/(K^*)^2>, in other words it is the output of C<rnfdisc>. C<I<rnf>[4]> is the ideal index C<\goth{f}>, i.e.S< >such that C<d(pol)B<I<Z>>_K = \goth{f}^2\goth{d}(L/K)>. C<I<rnf>[5]> is currently unused. C<I<rnf>[6]> is currently unused. C<I<rnf>[7]> is a two-component row vector, where the first component is the relative integral pseudo basis expressed as polynomials (in the variable of C<pol>) with polmod coefficients in C<I<nf>>, and the second component is the ideal list of the pseudobasis in HNF. C<I<rnf>[8]> is the inverse matrix of the integral basis matrix, with coefficients polmods in C<I<nf>>. C<I<rnf>[9]> is currently unused. C<I<rnf>[10]> is C<I<nf>>. C<I<rnf>[11]> is the output of C<rnfequation(nf, pol, 1)>. Namely, a vector I<vabs> with 3 entries describing the \emph{absolute} extension C<L/B<I<Q>>>. C<I<vabs>[1]> is an absolute equation, more conveniently obtained as C<rnf.pol>. C<I<vabs>[2]> expresses the generator C<F<alpha>> of the number field C<I<nf>> as a polynomial modulo the absolute equation C<I<vabs>[1]>. C<I<vabs>[3]> is a small integer C<k> such that, if C<F<beta>> is an abstract root of I<pol> and C<F<alpha>> the generator of C<I<nf>>, the generator whose root is I<vabs> will be C<F<beta> + k F<alpha>>. Note that one must be very careful if C<k ! = 0> when dealing simultaneously with absolute and relative quantities since the generator chosen for the absolute extension is not the same as for the relative one. If this happens, one can of course go on working, but we strongly advise to change the relative polynomial so that its root will be C<F<beta> + k F<alpha>>. Typically, the GP instruction would be C<pol = subst(pol, x, x - k*Mod(y,I<nf>.pol))> C<I<rnf>[12]> is by default unused and set equal to 0. This field is used to store further information about the field as it becomes available (which is rarely needed, hence would be too expensive to compute during the initial C<rnfinit> call). X<rnfinitalg>The library syntax is B<rnfinitalg>C<(I<nf>,I<pol>,I<prec>)>. =head2 X<rnfisfree>rnfisfreeC<(I<bnf>,x)> given C<I<bnf>> as output by C<bnfinit>, and either a polynomial C<x> with coefficients in C<I<bnf>> defining a relative extension C<L> of C<I<bnf>>, or a pseudo-basis C<x> of such an extension, returns true (1) if C<L/I<bnf>> is free, false (0) if not. X<rnfisfree>The library syntax is B<rnfisfree>C<(I<bnf>,x)>, and the result is a C<long>. =head2 X<rnfisnorm>rnfisnormC<(T,a,{I<flag> = 0})> similar to C<bnfisnorm> but in the relative case. C<T> is as output by X<rnfisnorminit>C<rnfisnorminit> applied to the extension C<L/K>. This tries to decide whether the element C<a> in C<K> is the norm of some C<x> in the extension C<L/K>. The output is a vector C<[x,q]>, where C<a = \Norm(x)*q>. The algorithm looks for a solution C<x> which is an C<S>-integer, with C<S> a list of places of C<K> containing at least the ramified primes, the generators of the class group of C<L>, as well as those primes dividing C<a>. If C<L/K> is Galois, then this is enough; otherwise, C<I<flag>> is used to add more primes to C<S>: all the places above the primes C<p E<lt>= I<flag>> (resp.S< >C<p|I<flag>>) if C<I<flag> E<gt> 0> (resp.S< >C<I<flag> E<lt> 0>). The answer is guaranteed (i.e.S< >C<a> is a norm iff C<q = 1>) if the field is Galois, or, under X<GRH>GRH, if C<S> contains all primes less than C<12 F<log> ^2|\disc(M)|>, where C<M> is the normal closure of C<L/K>. If X<rnfisnorminit>C<rnfisnorminit> has determined (or was told) that C<L/K> is X<Galois>Galois, and C<I<flag> ! = 0>, a Warning is issued (so that you can set C<I<flag> = 1> to check whether C<L/K> is known to be Galois, according to C<T>). Example: bnf = bnfinit(y^3 + y^2 - 2*y - 1); p = x^2 + Mod(y^2 + 2*y + 1, bnf.pol); T = rnfisnorminit(bnf, p); rnfisnorm(T, 17) checks whether C<17> is a norm in the Galois extension C<B<I<Q>>(F<beta>) / B<I<Q>>(F<alpha>)>, where C<F<alpha>^3 + F<alpha>^2 - 2F<alpha> - 1 = 0> and C<F<beta>^2 + F<alpha>^2 + 2F<alpha> + 1 = 0> (it is). X<rnfisnorm>The library syntax is B<rnfisnorm>C<(I<T>,x,I<flag>)>. =head2 X<rnfisnorminit>rnfisnorminitC<(I<pol>,I<polrel>,{I<flag> = 2})> let C<K> be defined by a root of I<pol>, and C<L/K> the extension defined by the polynomial I<polrel>. As usual, I<pol> can in fact be an I<nf>, or I<bnf>, etc; if I<pol> has degree C<1> (the base field is B<I<Q>>), polrel is also allowed to be an I<nf>, etc. Computes technical data needed by X<rnfisnorm>C<rnfisnorm> to solve norm equations C<Nx = a>, for C<x> in C<L>, and C<a> in C<K>. If C<I<flag> = 0>, do not care whether C<L/K> is Galois or not. If C<I<flag> = 1>, C<L/K> is assumed to be Galois (unchecked), which speeds up X<rnfisnorm>C<rnfisnorm>. If C<I<flag> = 2>, let the routine determine whether C<L/K> is Galois. X<rnfisnorminit>The library syntax is B<rnfisnorminit>C<(I<pol>,I<polrel>,I<flag>)>. =head2 X<rnfkummer>rnfkummerC<(I<bnr>,{I<subgroup>},{deg = 0})> I<bnr> being as output by C<bnrinit>, finds a relative equation for the class field corresponding to the module in I<bnr> and the given congruence subgroup (the full ray class field if I<subgroup> is omitted). If I<deg> is positive, outputs the list of all relative equations of degree I<deg> contained in the ray class field defined by I<bnr>, with the \emph{same} conductor as C<(I<bnr>, I<subgroup>)>. B<Warning:> this routine only works for subgroups of prime index. It uses Kummer theory, adjoining necessary roots of unity (it needs to compute a tough C<bnfinit> here), and finds a generator via Hecke's characterization of ramification in Kummer extensions of prime degree. If your extension does not have prime degree, for the time being, you have to split it by hand as a tower / compositum of such extensions. X<rnfkummer>The library syntax is B<rnfkummer>C<(I<bnr>,I<subgroup>,I<deg>,I<prec>)>, where I<deg> is a C<long> and an omitted I<subgroup> is coded as C<NULL> =head2 X<rnflllgram>rnflllgramC<(I<nf>,I<pol>,I<order>)> given a polynomial I<pol> with coefficients in I<nf> defining a relative extension C<L> and a suborder I<order> of C<L> (of maximal rank), as output by C<rnfpseudobasis>C<(I<nf>,I<pol>)> or similar, gives C<[[I<neworder>],U]>, where I<neworder> is a reduced order and C<U> is the unimodular transformation matrix. X<rnflllgram>The library syntax is B<rnflllgram>C<(I<nf>,I<pol>,I<order>,I<prec>)>. =head2 X<rnfnormgroup>rnfnormgroupC<(I<bnr>,I<pol>)> I<bnr> being a big ray class field as output by C<bnrinit> and I<pol> a relative polynomial defining an X<Abelian extension>Abelian extension, computes the norm group (alias Artin or Takagi group) corresponding to the Abelian extension of C<I<bnf> = bnr[1]> defined by I<pol>, where the module corresponding to I<bnr> is assumed to be a multiple of the conductor (i.e.S< >I<pol> defines a subextension of bnr). The result is the HNF defining the norm group on the given generators of C<I<bnr>[5][3]>. Note that neither the fact that I<pol> defines an Abelian extension nor the fact that the module is a multiple of the conductor is checked. The result is undefined if the assumption is not correct. X<rnfnormgroup>The library syntax is B<rnfnormgroup>C<(I<bnr>,I<pol>)>. =head2 X<rnfpolred>rnfpolredC<(I<nf>,I<pol>)> relative version of C<polred>. Given a monic polynomial I<pol> with coefficients in C<I<nf>>, finds a list of relative polynomials defining some subfields, hopefully simpler and containing the original field. In the present version B<2.2.0>, this is slower and less efficient than C<rnfpolredabs>. X<rnfpolred>The library syntax is B<rnfpolred>C<(I<nf>,I<pol>,I<prec>)>. =head2 X<rnfpolredabs>rnfpolredabsC<(I<nf>,I<pol>,{I<flag> = 0})> relative version of C<polredabs>. Given a monic polynomial I<pol> with coefficients in C<I<nf>>, finds a simpler relative polynomial defining the same field. The binary digits of C<I<flag>> mean 1: returns C<[P,a]> where C<P> is the default output and C<a> is an element expressed on a root of C<P> whose characteristic polynomial is I<pol> 2: returns an absolute polynomial (same as C<rnfequation(I<nf>,rnfpolredabs(I<nf>,I<pol>))> but faster). 16: possibly use a suborder of the maximal order. This is slower than the default when the relative discriminant is smooth, and much faster otherwise. See L<Label se:polredabs>. B<Remark.> In the present implementation, this is both faster and much more efficient than C<rnfpolred>, the difference being more dramatic than in the absolute case. This is because the implementation of C<rnfpolred> is based on (a partial implementation of) an incomplete reduction theory of lattices over number fields, the function C<rnflllgram>, which deserves to be improved. X<rnfpolredabs>The library syntax is B<rnfpolredabs>C<(I<nf>,I<pol>,I<flag>,I<prec>)>. =head2 X<rnfpseudobasis>rnfpseudobasisC<(I<nf>,I<pol>)> given a number field C<I<nf>> as output by C<nfinit> and a polynomial I<pol> with coefficients in C<I<nf>> defining a relative extension C<L> of C<I<nf>>, computes a pseudo-basis C<(A,I)> for the maximal order C<B<I<Z>>_L> viewed as a C<B<I<Z>>_K>-module, and the relative discriminant of C<L>. This is output as a four-element row vector C<[A,I,D,d]>, where C<D> is the relative ideal discriminant and C<d> is the relative discriminant considered as an element of C<I<nf>^*/{I<nf>^*}^2>. X<rnfpseudobasis>The library syntax is B<rnfpseudobasis>C<(I<nf>,I<pol>)>. =head2 X<rnfsteinitz>rnfsteinitzC<(I<nf>,x)> given a number field C<I<nf>> as output by C<nfinit> and either a polynomial C<x> with coefficients in C<I<nf>> defining a relative extension C<L> of C<I<nf>>, or a pseudo-basis C<x> of such an extension as output for example by C<rnfpseudobasis>, computes another pseudo-basis C<(A,I)> (not in HNF in general) such that all the ideals of C<I> except perhaps the last one are equal to the ring of integers of C<I<nf>>, and outputs the four-component row vector C<[A,I,D,d]> as in C<rnfpseudobasis>. The name of this function comes from the fact that the ideal class of the last ideal of C<I>, which is well defined, is the X<Steinitz class>Steinitz class of the C<B<I<Z>>_K>-module C<B<I<Z>>_L> (its image in C<SK_0(B<I<Z>>_K)>). X<rnfsteinitz>The library syntax is B<rnfsteinitz>C<(I<nf>,x)>. =head2 X<subgrouplist>subgrouplistC<(I<bnr>,{I<bound>},{I<flag> = 0})> I<bnr> being as output by C<bnrinit> or a list of cyclic components of a finite Abelian group C<G>, outputs the list of subgroups of C<G>. Subgroups are given as HNF left divisors of the SNF matrix corresponding to C<G>. B<Warning:> the present implementation cannot treat a group C<G> where any cyclic factor has more than C<2^{31}>, resp.S< >C<2^{63}> elements on a C<32>-bit, resp.S< >C<64>-bit architecture. X<forsubgroup>C<forsubgroup> is a bit more general and can handle C<G> if all C<p>-Sylow subgroups of C<G> satisfy the condition above. If C<I<flag> = 0> (default) and I<bnr> is as output by C<bnrinit>, gives only the subgroups whose modulus is the conductor. Otherwise, the modulus is not taken into account. If I<bound> is present, and is a positive integer, restrict the output to subgroups of index less than I<bound>. If I<bound> is a vector containing a single positive integer C<B>, then only subgroups of index exactly equal to C<B> are computed. For instance ? subgrouplist([6,2]) %1 = [[6, 0; 0, 2], [2, 0; 0, 2], [6, 3; 0, 1], [2, 1; 0, 1], [3, 0; 0, 2], [1, 0; 0, 2], [6, 0; 0, 1], [2, 0; 0, 1], [3, 0; 0, 1], [1, 0; 0, 1]] ? subgrouplist([6,2],3) \\ index less than 3 %2 = [[2, 1; 0, 1], [1, 0; 0, 2], [2, 0; 0, 1], [3, 0; 0, 1], [1, 0; 0, 1]] ? subgrouplist([6,2],[3]) \\ index 3 %3 = [[3, 0; 0, 1]] ? bnr = bnrinit(bnfinit(x), [120,[1]], 1); ? L = subgrouplist(bnr, [8]); In the last example, C<L> corresponds to the 24 subfields of C<B<I<Q>>(F<zeta>_{120})>, of degree C<8> and conductor C<120 oo > (by setting I<flag>, we see there are a total of C<43> subgroups of degree C<8>). ? vector(#L, i, galoissubcyclo(bnr, L[i])) will produce their equations. (For a general base field, you would have to rely on X<bnrstark>C<bnrstark>, or X<rnfkummer>C<rnfkummer>.) X<subgrouplist0>The library syntax is B<subgrouplist0>C<(I<bnr>,I<bound>,I<flag>)>, where C<I<flag>> is a long integer, and an omitted I<bound> is coded by C<NULL>. =head2 X<zetak>zetakC<(I<znf>,x,{I<flag> = 0})> I<znf> being a number field initialized by C<zetakinit> (\emph{not} by C<nfinit>), computes the value of the X<Dedekind>Dedekind zeta function of the number field at the complex number C<x>. If C<I<flag> = 1> computes Dedekind C<F<Lambda>> function instead (i.e.S< >the product of the Dedekind zeta function by its gamma and exponential factors). B<CAVEAT.> This implementation is not satisfactory and must be rewritten. In particular C<B<*>> The accuracy of the result depends in an essential way on the accuracy of both the C<zetakinit> program and the current accuracy. Be wary in particular that C<x> of large imaginary part or, on the contrary, very close to an ordinary integer will suffer from precision loss, yielding fewer significant digits than expected. Computing with 28 eight digits of relative accuracy, we have ? zeta(3) %1 = 1.202056903159594285399738161 ? zeta(3-1e-20) %2 = 1.202056903159594285401719424 ? zetak(zetakinit(x), 3-1e-20) %3 = 1.2020569031595952919 \\ 5 digits are wrong ? zetak(zetakinit(x), 3-1e-28) %4 = -25.33411749 \\ junk C<B<*>> As the precision increases, results become unexpectedly completely wrong: ? \p100 ? zetak(zetakinit(x^2-5), -1) - 1/30 %1 = 7.26691813 E-108 \\ perfect ? \p150 ? zetak(zetakinit(x^2-5), -1) - 1/30 %2 = -2.486113578 E-156 \\ perfect ? \p200 ? zetak(zetakinit(x^2-5), -1) - 1/30 %3 = 4.47... E-75 \\ more than half of the digits are wrong ? \p250 ? zetak(zetakinit(x^2-5), -1) - 1/30 %4 = 1.6 E43 \\ junk X<glambdak>The library syntax is B<glambdak>C<(I<znf>,x,I<prec>)> or C< B<gzetak>(I<znf>,x,I<prec>)>X<gzetak>. =head2 X<zetakinit>zetakinitC<(x)> computes a number of initialization data concerning the number field defined by the polynomial C<x> so as to be able to compute the X<Dedekind>Dedekind zeta and lambda functions (respectively C<zetak(x)> and C<zetak(x,1)>). This function calls in particular the C<bnfinit> program. The result is a 9-component vector C<v> whose components are very technical and cannot really be used by the user except through the C<zetak> function. The only component which can be used if it has not been computed already is C<v[1][4]> which is the result of the C<bnfinit> call. This function is very inefficient and should be rewritten. It needs to computes millions of coefficients of the corresponding Dirichlet series if the precision is big. Unless the discriminant is small it will not be able to handle more than 9 digits of relative precision. For instance, C<zetakinit(x^8 - 2)> needs 440MB of memory at default precision. X<initzeta>The library syntax is B<initzeta>C<(x)>. =head1 Polynomials and power series We group here all functions which are specific to polynomials or power series. Many other functions which can be applied on these objects are described in the other sections. Also, some of the functions described here can be applied to other types. =head2 X<O>OC<(p^e)> if C<p> is an integer greater than C<2>, returns a C<p>-adic C<0> of precision C<e>. In all other cases, returns a power series zero with precision given by C<e v>, where C<v> is the C<X>-adic valuation of C<p> with respect to its main variable. X<zeropadic>The library syntax is B<zeropadic>C<(p,e)> for a C<p>-adic and C< B<zeroser>(v,e)>X<zeroser> for a power series zero in variable C<v>, which is a C<long>. The precision C<e> is a C<long>. =head2 X<deriv>derivC<(x,{v})> derivative of C<x> with respect to the main variable if C<v> is omitted, and with respect to C<v> otherwise. The derivative of a scalar type is zero, and the derivative of a vector or matrix is done componentwise. One can use C<x'> as a shortcut if the derivative is with respect to the main variable of C<x>. By definition, the main variable of a C<t_POLMOD> is the main variable among the coefficients from its two polynomial components (representative and modulus); in other words, assuming a polmod represents an element of C<R[X]/(T(X))>, the variable C<X> is a mute variable and the derivative is taken with respect to the main variable used in the base ring C<R>. X<deriv>The library syntax is B<deriv>C<(x,v)>, where C<v> is a C<long>, and an omitted C<v> is coded as C<-1>. When C<x> is a C<t_POL>, C<X<derivpol>derivpol(x)> is a shortcut for C<deriv(x, -1)>. =head2 X<eval>evalC<(x)> replaces in C<x> the formal variables by the values that have been assigned to them after the creation of C<x>. This is mainly useful in GP, and not in library mode. Do not confuse this with substitution (see C<subst>). If C<x> is a character string, C<eval(x)> executes C<x> as a GP command, as if directly input from the keyboard, and returns its output.X<Label se:eval> For convenience, C<x> is evaluated as if C<strictmatch> was off. In particular, unused characters at the end of C<x> do not prevent its evaluation: ? eval("1a") % 1 = 1 X<geval>The library syntax is B<geval>C<(x)>. The more basic functions C< B<poleval>(q,x)>X<poleval>, C< B<qfeval>(q,x)>X<qfeval>, and C< B<hqfeval>(q,x)>X<hqfeval> evaluate C<q> at C<x>, where C<q> is respectively assumed to be a polynomial, a quadratic form (a symmetric matrix), or an Hermitian form (an Hermitian complex matrix). =head2 X<factorpadic>factorpadicC<(I<pol>,p,r,{I<flag> = 0})> C<p>-adic factorization of the polynomial I<pol> to precision C<r>, the result being a two-column matrix as in C<factor>. The factors are normalized so that their leading coefficient is a power of C<p>. C<r> must be strictly larger than the C<p>-adic valuation of the discriminant of I<pol> for the result to make any sense. The method used is a modified version of the X<round 4>round 4 algorithm of X<Zassenhaus>Zassenhaus. If C<I<flag> = 1>, use an algorithm due to X<Buchmann>Buchmann and X<Lenstra>Lenstra, which is usually less efficient. X<factorpadic4>The library syntax is B<factorpadic4>C<(I<pol>,p,r)>, where C<r> is a C<long> integer. =head2 X<intformal>intformalC<(x,{v})> X<formal integration>formal integration of C<x> with respect to the main variable if C<v> is omitted, with respect to the variable C<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. C<x> can be of any type. When C<x> is a rational function, it is assumed that the base ring is an integral domain of characteristic zero. X<integ>The library syntax is B<integ>C<(x,v)>, where C<v> is a C<long> and an omitted C<v> is coded as C<-1>. =head2 X<padicappr>padicapprC<(I<pol>,a)> vector of C<p>-adic roots of the polynomial C<pol> congruent to the C<p>-adic number C<a> modulo C<p>, and with the same C<p>-adic precision as C<a>. The number C<a> can be an ordinary C<p>-adic number (type C<t_PADIC>, i.e.S< >an element of C<B<I<Z>>_p>) or can be an integral element of a finite extension of C<B<I<Q>>_p>, given as a C<t_POLMOD> at least one of whose coefficients is a C<t_PADIC>. In this case, the result is the vector of roots belonging to the same extension of C<B<I<Q>>_p> as C<a>. X<padicappr>The library syntax is B<padicappr>C<(I<pol>,a)>. =head2 X<polcoeff>polcoeffC<(x,s,{v})> coefficient of degree C<s> of the polynomial C<x>, with respect to the main variable if C<v> is omitted, with respect to C<v> otherwise. Also applies to power series, scalars (polynomial of degree C<0>), and to rational functions provided the denominator is a monomial. X<polcoeff0>The library syntax is B<polcoeff0>C<(x,s,v)>, where C<v> is a C<long> and an omitted C<v> is coded as C<-1>. Also available is C< B<truecoeff>(x,v)>X<truecoeff>. =head2 X<poldegree>poldegreeC<(x,{v})> degree of the polynomial C<x> in the main variable if C<v> is omitted, in the variable C<v> otherwise. The degree of C<0> is a fixed negative number, whose exact value should not be used. The degree of a non-zero scalar is C<0>. Finally, when C<x> is a non-zero polynomial or rational function, returns the ordinary degree of C<x>. Raise an error otherwise. X<poldegree>The library syntax is B<poldegree>C<(x,v)>, where C<v> and the result are C<long>s (and an omitted C<v> is coded as C<-1>). Also available is C< B<degree>(x)>X<degree>, which is equivalent to C<poldegree(x,-1)>. =head2 X<polcyclo>polcycloC<(n,{v = x})> C<n>-th cyclotomic polynomial, in variable C<v> (C<x> by default). The integer C<n> must be positive. X<cyclo>The library syntax is B<cyclo>C<(n,v)>, where C<n> and C<v> are C<long> integers (C<v> is a variable number, usually obtained through C<varn>). =head2 X<poldisc>poldiscC<(I<pol>,{v})> discriminant of the polynomial I<pol> in the main variable is C<v> is omitted, in C<v> otherwise. The algorithm used is the X<subresultant algorithm>subresultant algorithm. X<poldisc0>The library syntax is B<poldisc0>C<(x,v)>. Also available is C< B<discsr>(x)>X<discsr>, equivalent to C<poldisc0(x,-1)>. =head2 X<poldiscreduced>poldiscreducedC<(f)> reduced discriminant vector of the (integral, monic) polynomial C<f>. This is the vector of elementary divisors of C<B<I<Z>>[F<alpha>]/f'(F<alpha>)B<I<Z>>[F<alpha>]>, where C<F<alpha>> is a root of the polynomial C<f>. The components of the result are all positive, and their product is equal to the absolute value of the discriminant ofS< >C<f>. X<reduceddiscsmith>The library syntax is B<reduceddiscsmith>C<(x)>. =head2 X<polhensellift>polhenselliftC<(x, y, p, e)> given a prime C<p>, an integral polynomial C<x> whose leading coefficient is a C<p>-unit, a vector C<y> of integral polynomials that are pairwise relatively prime modulo C<p>, and whose product is congruent to C<x> modulo C<p>, lift the elements of C<y> to polynomials whose product is congruent to C<x> modulo C<p^e>. X<polhensellift>The library syntax is B<polhensellift>C<(x,y,p,e)> where C<e> must be a C<long>. =head2 X<polinterpolate>polinterpolateC<(xa,{ya},{v = x},{&e})> given the data vectors C<xa> and C<ya> of the same length C<n> (C<xa> containing the C<x>-coordinates, and C<ya> the corresponding C<y>-coordinates), this function finds the X<interpolating polynomial>interpolating polynomial passing through these points and evaluates it atS< >C<v>. If C<ya> is omitted, return the polynomial interpolating the C<(i,xa[i])>. If present, C<e> will contain an error estimate on the returned value. X<polint>The library syntax is B<polint>C<(xa,ya,v,&e)>, where C<e> will contain an error estimate on the returned value. =head2 X<polisirreducible>polisirreducibleC<(I<pol>)> I<pol> being a polynomial (univariate in the present version B<2.2.0>), returns 1 if I<pol> is non-constant and irreducible, 0 otherwise. Irreducibility is checked over the smallest base field over which I<pol> seems to be defined. X<gisirreducible>The library syntax is B<gisirreducible>C<(I<pol>)>. =head2 X<pollead>polleadC<(x,{v})> leading coefficient of the polynomial or power series C<x>. This is computed with respect to the main variable of C<x> if C<v> is omitted, with respect to the variable C<v> otherwise. X<pollead>The library syntax is B<pollead>C<(x,v)>, where C<v> is a C<long> and an omitted C<v> is coded as C<-1>. Also available is C< B<leading_term>(x)>X<leading_term>. =head2 X<pollegendre>pollegendreC<(n,{v = x})> creates the C<n^{th}> X<Legendre polynomial>Legendre polynomial, in variable C<v>. X<legendre>The library syntax is B<legendre>C<(n)>, where C<x> is a C<long>. =head2 X<polrecip>polrecipC<(I<pol>)> reciprocal polynomial of I<pol>, i.e.S< >the coefficients are in reverse order. I<pol> must be a polynomial. X<polrecip>The library syntax is B<polrecip>C<(x)>. =head2 X<polresultant>polresultantC<(x,y,{v},{I<flag> = 0})> resultant of the two polynomials C<x> and C<y> with exact entries, with respect to the main variables of C<x> and C<y> if C<v> is omitted, with respect to the variable C<v> otherwise. The algorithm assumes the base ring is a domain. If C<I<flag> = 0>, uses the X<subresultant algorithm>subresultant algorithm. If C<I<flag> = 1>, uses the determinant of Sylvester's matrix instead (here C<x> and C<y> may have non-exact coefficients). If C<I<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. X<polresultant0>The library syntax is B<polresultant0>C<(x,y,v,I<flag>)>, where C<v> is a C<long> and an omitted C<v> is coded as C<-1>. Also available are C< B<subres>(x,y)>X<subres> (C<I<flag> = 0>) and C< B<resultant2>(x,y)>X<resultant2> (C<I<flag> = 1>). =head2 X<polroots>polrootsC<(I<pol>,{I<flag> = 0})> complex roots of the polynomial I<pol>, given as a column vector where each root is repeated according to its multiplicity. The precision is given as for transcendental functions: in GP it is kept in the variable C<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.S< >SchE<ouml>nhageX<SchE<ouml>nage>'s root-finding algorithm, due to and implemented by X.S< >Gourdon. Barring bugs, it is guaranteed to converge and to give the roots to the required accuracy. If C<I<flag> = 1>, use a variant of the Newton-Raphson method, which is \emph{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 algorithm. This used to be the default root-finding function in PARI until version 1.39.06. X<roots>The library syntax is B<roots>C<(I<pol>,I<prec>)> or C< B<rootsold>(I<pol>,I<prec>)>X<rootsold>. =head2 X<polrootsmod>polrootsmodC<(I<pol>,p,{I<flag> = 0})> row vector of roots modulo C<p> of the polynomial I<pol>. The particular non-prime value C<p = 4> is accepted, mainly for C<2>-adic computations. Multiple roots are \emph{not} repeated. If C<p> is very small, you may try setting C<I<flag> = 1>, which uses a naive search. X<rootmod>The library syntax is B<rootmod>C<(I<pol>,p)> (C<I<flag> = 0>) or C< B<rootmod2>(I<pol>,p)>X<rootmod2> (C<I<flag> = 1>). =head2 X<polrootspadic>polrootspadicC<(I<pol>,p,r)> row vector of C<p>-adic roots of the polynomial I<pol>, given to C<p>-adic precision C<r>. Multiple roots are \emph{not} repeated. C<p> is assumed to be a prime, and I<pol> to be non-zero modulo C<p>. Note that this is not the same as the roots in C<B<I<Z>>/p^rB<I<Z>>>, rather it gives approximations in C<B<I<Z>>/p^rB<I<Z>>> of the true roots living in C<B<I<Q>>_p>. If I<pol> has inexact C<t_PADIC> coefficients, this is not always well-defined; in this case, the equation is first made integral, then lifted to B<I<Z>>. Hence the roots given are approximations of the roots of a polynomial which is C<p>-adically close to the input. X<rootpadic>The library syntax is B<rootpadic>C<(I<pol>,p,r)>, where C<r> is a C<long>. =head2 X<polsturm>polsturmC<(I<pol>,{a},{b})> number of real roots of the real polynomial I<pol> in the interval C<]a,b]>, using Sturm's algorithm. C<a> (resp.S< >C<b>) is taken to be C<- oo > (resp.S< >C<+ oo >) if omitted. X<sturmpart>The library syntax is B<sturmpart>C<(I<pol>,a,b)>. Use C<NULL> to omit an argument. C< B<sturm>(I<pol>)>X<sturm> is equivalent to C< B<sturmpart>(I<pol>,NULL,NULL)>X<sturmpart>. The result is a C<long>. =head2 X<polsubcyclo>polsubcycloC<(n,d,{v = x})> gives polynomials (in variable C<v>) defining the sub-Abelian extensions of degree C<d> of the cyclotomic field C<B<I<Q>>(F<zeta>_n)>, where C<d | F<phi>(n)>. If there is exactly one such extension the output is a polynomial, else it is a vector of polynomials, eventually empty. To be sure to get a vector, you can use C<concat([],polsubcyclo(n,d))> The function X<galoissubcyclo>C<galoissubcyclo> allows to specify more closely which sub-Abelian extension should be computed. X<polsubcyclo>The library syntax is B<polsubcyclo>C<(n,d,v)>, where C<n>, C<d> and C<v> are C<long> and C<v> is a variable number. When C<(B<I<Z>>/nB<I<Z>>)^*> is cyclic, you can use C< B<subcyclo>(n,d,v)>X<subcyclo>, where C<n>, C<d> and C<v> are C<long> and C<v> is a variable number. =head2 X<polsylvestermatrix>polsylvestermatrixC<(x,y)> forms the Sylvester matrix corresponding to the two polynomials C<x> and C<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. X<sylvestermatrix>The library syntax is B<sylvestermatrix>C<(x,y)>. =head2 X<polsym>polsymC<(x,n)> creates the vector of the X<symmetric powers>symmetric powers of the roots of the polynomial C<x> up to power C<n>, using Newton's formula. X<polsym>The library syntax is B<polsym>C<(x)>. =head2 X<poltchebi>poltchebiC<(n,{v = x})> creates the C<n^{th}> X<Chebyshev>Chebyshev polynomialS< >C<T_n> of the first kind in variable C<v>. X<tchebi>The library syntax is B<tchebi>C<(n,v)>, where C<n> and C<v> are C<long> integers (C<v> is a variable number). =head2 X<polzagier>polzagierC<(n,m)> creates Zagier's polynomial C<P_n^{(m)}> used in the functions C<sumalt> and C<sumpos> (with C<I<flag> = 1>). One must have C<m E<lt>= n>. The exact definition can be found in ``Convergence acceleration of alternating series'', Cohen et al., Experiment.S< >Math., vol.S< >9, 2000, pp.S< >3--12. X<polzagreel>The library syntax is B<polzagreel>C<(n,m,I<prec>)> if the result is only wanted as a polynomial with real coefficients to the precision C<I<prec>>, or C< B<polzag>(n,m)>X<polzag> if the result is wanted exactly, where C<n> and C<m> are C<long>s. =head2 X<serconvol>serconvolC<(x,y)> convolution (or X<Hadamard product>Hadamard product) of the two power series C<x> and C<y>; in other words if C<x = F<sum> a_k*X^k> and C<y = F<sum> b_k*X^k> then C<serconvol(x,y) = F<sum> a_k*b_k*X^k>. X<convol>The library syntax is B<convol>C<(x,y)>. =head2 X<serlaplace>serlaplaceC<(x)> C<x> must be a power series with non-negative exponents. If C<x = F<sum> (a_k/k!)*X^k> then the result is C<F<sum> a_k*X^k>. X<laplace>The library syntax is B<laplace>C<(x)>. =head2 X<serreverse>serreverseC<(x)> reverse power series (i.e.S< >C<x^{-1}>, not C<1/x>) of C<x>. C<x> must be a power series whose valuation is exactly equal to one. X<recip>The library syntax is B<recip>C<(x)>. =head2 X<subst>substC<(x,y,z)> replace the simple variable C<y> by the argument C<z> in the ``polynomial'' expression C<x>. Every type is allowed for C<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 zero. 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 C<x> is a power series, C<z> must be either a polynomial, a power series, or a rational function. X<gsubst>The library syntax is B<gsubst>C<(x,y,z)>, where C<y> is the variable number. =head2 X<substpol>substpolC<(x,y,z)> replace the ``variable'' C<y> by the argument C<z> in the ``polynomial'' expression C<x>. Every type is allowed for C<x>, but the same behaviour as C<subst> above apply. The difference with C<subst> is that C<y> is allowed to be any polynomial here. The substitution is done as per the following script: subst_poly(pol, from, to) = { local(t = 'subst_poly_t, M = from - t); subst(lift(Mod(pol,M), variable(M)), t, to) } For instance ? substpol(x^4 + x^2 + 1, x^2, y) %1 = y^2 + y + 1 ? substpol(x^4 + x^2 + 1, x^3, y) %2 = x^2 + y*x + 1 ? substpol(x^4 + x^2 + 1, (x+1)^2, y) %3 = (-4*y - 6)*x + (y^2 + 3*y - 3) X<gsubstpol>The library syntax is B<gsubstpol>C<(x,y,z)>. =head2 X<substvec>substvecC<(x,v,w)> C<v> being a vector of monomials (variables), C<w> a vector of expressions of the same length, replace in the expression C<x> all occurences of C<v_i> by C<w_i>. The substitutions are done simultaneously; more precisely, the C<v_i> are first replaced by new variables in C<x>, then these are replaced by the C<w_i>: ? substvec([x,y], [x,y], [y,x]) %1 = [y, x] ? substvec([x,y], [x,y], [y,x+y]) %2 = [y, x + y] \\ not [y, 2*y] X<gsubstvec>The library syntax is B<gsubstvec>C<(x,v,w)>. =head2 X<taylor>taylorC<(x,y)> Taylor expansion around C<0> of C<x> with respect toX<Label se:taylor> the simple variable C<y>. C<x> can be of any reasonable type, for example a rational function. The number of terms of the expansion is transparent to the user in GP, but must be given as a second argument in library mode. X<tayl>The library syntax is B<tayl>C<(x,y,n)>, where the C<long> integer C<n> is the desired number of terms in the expansion. =head2 X<thue>thueC<(I<tnf>,a,{I<sol>})> solves the equation C<P(x,y) = a> in integers C<x> and C<y>, where I<tnf> was created with C<thueinit(P)>. I<sol>, if present, contains the solutions of C<\Norm(x) = a> modulo units of positive norm in the number field defined by C<P> (as computed by C<bnfisintnorm>). If the result is conditional (on the GRH or some heuristic strenghtening), a Warning is printed. Otherwise, the result is unconditional, barring bugs. For instance, here's how to solve the Thue equation C<x^{13} - 5y^{13} = - 4>: ? tnf = thueinit(x^13 - 5); ? thue(tnf, -4) %1 = [[1, 1]] Hence, the only solution is C<x = 1>, C<y = 1> and the result is unconditional. On the other hand: ? tnf = thueinit(x^3-2*x^2+3*x-17); ? thue(tnf, -15) *** thue: Warning: Non trivial conditional class group. *** May miss solutions of the norm equation. %2 = [[1, 1]] This time the result is conditional. All results computed using this tnf are likewise conditional, \emph{except} for a right-hand side of C<F<+-> 1>. X<thue>The library syntax is B<thue>C<(I<tnf>,a,I<sol>)>, where an omitted I<sol> is coded as C<NULL>. =head2 X<thueinit>thueinitC<(P,{I<flag> = 0})> initializes the I<tnf> corresponding to C<P>. It is meant to be used in conjunction with X<thue>C<thue> to solve Thue equations C<P(x,y) = a>, where C<a> is an integer. If C<I<flag>> is non-zero, certify the result unconditionnally. Otherwise, assume X<GRH>GRH, this being much faster of course. \emph{If} the conditional computed class group is trivial \emph{or} you are only interested in the case C<a = F<+->1>, then results are unconditional anyway. So one should only use the flag is C<thue> prints a Warning (see the example there). X<thueinit>The library syntax is B<thueinit>C<(P,I<flag>,I<prec>)>. =head1 Vectors, matrices, linear algebra and sets X<Label se:linear_algebra> Note that most linear algebra functions operating on subspaces defined by generating sets (such as X<mathnf>C<mathnf>, X<qflll>C<qflll>, etc.) take matrices as arguments. As usual, the generating vectors are taken to be the \emph{columns} of the given matrix. Since PARI does not have a strong typing system, scalars live in unspecified commutative base rings. It is very difficult to write robust linear algebra routines in such a general setting. The developpers's choice has been to assume the base ring is a domain and work over its field of fractions. If the base ring is \emph{not} a domain, one gets an error as soon as a non-zero pivot turns out to be non-invertible. Some functions, e.g.S< >C<mathnf> or C<mathnfmod>, specifically assume the base ring is B<I<Z>>. =head2 X<algdep>algdepC<(x,k,{I<flag> = 0})> X<algebraic dependence> X<Label se:algdep> C<x> being real/complex, or C<p>-adic, finds a polynomial of degree at most C<k> with integer coefficients having C<x> as approximate root. Note that the polynomial which is obtained is not necessarily the ``correct'' one. In fact it is not even guaranteed to be irreducible. One can check the closeness either by a polynomial evaluation (use X<subst>C<subst>), or by computing the roots of the polynomial given by C<algdep> (use X<polroots>C<polroots>). Internally, X<lindep>C<lindep>C<([1,x,...,x^k], I<flag>)> is used. If X<lindep>C<lindep> is not able to find a relation and returns a lower bound for the sup norm of the smallest relation, X<algdep>C<algdep> returns that bound instead. A suitable non-zero value of C<I<flag>> may improve on the default behaviour: \\\\\\\\\ LLL ? \p200 ? algdep(2^(1/6)+3^(1/5), 30); \\ wrong in 3.8s ? algdep(2^(1/6)+3^(1/5), 30, 100); \\ wrong in 1s ? algdep(2^(1/6)+3^(1/5), 30, 170); \\ right in 3.3s ? algdep(2^(1/6)+3^(1/5), 30, 200); \\ wrong in 2.9s ? \p250 ? algdep(2^(1/6)+3^(1/5), 30); \\ right in 2.8s ? algdep(2^(1/6)+3^(1/5), 30, 200); \\ right in 3.4s \\\\\\\\\ PSLQ ? \p200 ? algdep(2^(1/6)+3^(1/5), 30, -3); \\ failure in 14s. ? \p250 ? algdep(2^(1/6)+3^(1/5), 30, -3); \\ right in 18s Proceeding by increments of 5 digits of accuracy, C<algdep> with default flag produces its first correct result at 205 digits, and from then on a steady stream of correct results. Interestingly enough, our PSLQ also reliably succeeds from 205 digits on (and is 5 times slower at that accuracy). The above example is the testcase studied in a 2000 paper by Borwein and Lisonek, Applications of integer relation algorithms, \emph{Discrete Math.}, B<217>, p.S< >65--82. The paper conludes in the superiority of the PSLQ algorithm, which either shows that PARI's implementation of PSLQ is lacking, or that its LLL is extremely good. The version of PARI tested there was 1.39, which succeeded reliably from precision 265 on, in about 60 as much time as the current version. X<algdep0>The library syntax is B<algdep0>C<(x,k,I<flag>,I<prec>)>, where C<k> and C<I<flag>> are C<long>s. Also available is C< B<algdep>(x,k,I<prec>)>X<algdep> (C<I<flag> = 0>). =head2 X<charpoly>charpolyC<(A,{v = x},{I<flag> = 0})> X<characteristic polynomial>characteristic polynomial of C<A> with respect to the variable C<v>, i.e.S< >determinant of C<v*I-A> if C<A> is a square matrix. If C<A> is not a square matrix, it returns the characteristic polynomial of the map ``multiplication by C<A>'' if C<A> is a scalar, in particular a polmod. E.g.S< >C<charpoly(I) = x^2+1>. The value of C<I<flag>> is only significant for matrices. If C<I<flag> = 0>, the method used is essentially the same as for computing the adjoint matrix, i.e.S< >computing the traces of the powers of C<A>. If C<I<flag> = 1>, uses Lagrange interpolation which is almost always slower. If C<I<flag> = 2>, uses the Hessenberg form. This is faster than the default when the coefficients are intmod a prime or real numbers, but is usually slower in other base rings. X<charpoly0>The library syntax is B<charpoly0>C<(A,v,I<flag>)>, where C<v> is the variable number. Also available are the functions C< B<caract>(A,v)>X<caract> (C<I<flag> = 1>), C< B<carhess>(A,v)>X<carhess> (C<I<flag> = 2>), and C< B<caradj>(A,v,I<pt>)>X<caradj> where, in this last case, I<pt> is a C<GEN*> which, if not equal to C<NULL>, will receive the address of the adjoint matrix of C<A> (see C<matadjoint>), so both can be obtained at once. =head2 X<concat>concatC<(x,{y})> concatenation of C<x> and C<y>. If C<x> or C<y> is not a vector or matrix, it is considered as a one-dimensional vector. All types are allowed for C<x> and C<y>, but the sizes must be compatible. Note that matrices are concatenated horizontally, i.e.S< >the number of rows stays the same. Using transpositions, it is easy to concatenate them vertically. To concatenate vectors sideways (i.e.S< >to obtain a two-row or two-column matrix), use X<Mat>C<Mat> instead (see the example there). Concatenating a row vector to a matrix having the same number of columns will add the row to the matrix (top row if the vector is C<x>, i.e.S< >comes first, and bottom row otherwise). The empty matrix C<[;]> is considered to have a number of rows compatible with any operation, in particular concatenation. (Note that this is definitely \emph{not} the case for empty vectors C<[S< >]> or C<[S< >]~>.) If C<y> is omitted, C<x> has to be a row vector or a list, in which case its elements are concatenated, from left to right, using the above rules. ? concat([1,2], [3,4]) %1 = [1, 2, 3, 4] ? a = [[1,2]~, [3,4]~]; concat(a) %2 = [1 3] [2 4] ? concat([1,2; 3,4], [5,6]~) %3 = [1 2 5] [3 4 6] ? concat([%, [7,8]~, [1,2,3,4]]) %5 = [1 2 5 7] [3 4 6 8] [1 2 3 4] X<concat>The library syntax is B<concat>C<(x,y)>. =head2 X<lindep>lindepC<(x,{I<flag> = 0})> X<linear dependence>C<x> being a vector with C<p>-adic or real/complex coefficients, finds a small integral linear combination among these coefficients. If C<x> is C<p>-adic, C<I<flag>> is meaningless and the algorithm LLL-reduces a suitable (dual) lattice. Otherwise, the value of C<I<flag>> determines the algorithm used; in the current version of PARI, we suggest to use \emph{non-negative} values, since it is by far the fastest and most robust implementation. See the detailed example in L<Label se:algdep> (C<algdep>). If C<I<flag> E<gt>= 0>, uses a floating point (variable precision) LLL algorithm. This is in general much faster than the other variants. If C<I<flag> = 0> the accuracy is chosen internally using a crude heuristic. If C<I<flag> E<gt> 0> the computation is done with an accuracy of C<I<flag>> decimal digits. In that case, the parameter C<I<flag>> should be between 0.6 and 0.9 times the number of correct decimal digits in the input. If C<I<flag> = -1>, uses a variant of the X<LLL>LLL algorithm due to Hastad, Lagarias and Schnorr (STACS 1986). If the precision is too low, the routine may enter an infinite loop. If C<I<flag> = -2>, C<x> is allowed to be (and in any case interpreted as) a matrix. Returns a non trivial element of the kernel of C<x>, or C<0> if C<x> has trivial kernel. The element is defined over the field of coefficients of C<x>, and is in general not integral. If C<I<flag> = -3>, uses the PSLQ algorithm. This may return a real number C<B>, indicating that the input accuracy was exhausted and that no relation exist whose sup norm is less than C<B>. If C<I<flag> = -4>, uses an experimental 2-level PSLQ, which does not work at all. (Should be rewritten.) X<lindep0>The library syntax is B<lindep0>C<(x,I<flag>,I<prec>)>. Also available is C< B<lindep>(x,I<prec>)>X<lindep> (C<I<flag> = 0>). =head2 X<listcreate>listcreateC<(n)> creates an empty list of maximal length C<n>. This function is useless in library mode. =head2 X<listinsert>listinsertC<(I<list>,x,n)> inserts the object C<x> at position C<n> in I<list> (which must be of type C<t_LIST>). All the remaining elements of I<list> (from position C<n+1> onwards) are shifted to the right. This and C<listput> are the only commands which enable you to increase a list's effective length (as long as it remains under the maximal length specified at the time of the C<listcreate>). This function is useless in library mode. =head2 X<listkill>listkillC<(I<list>)> kill I<list>. This deletes all elements from I<list> and sets its effective length to C<0>. The maximal length is not affected. This function is useless in library mode. =head2 X<listput>listputC<(I<list>,x,{n})> sets the C<n>-th element of the list I<list> (which must be of type C<t_LIST>) equal to C<x>. If C<n> is omitted, or greater than the list current effective length, just appends C<x>. This and C<listinsert> are the only commands which enable you to increase a list's effective length (as long as it remains under the maximal length specified at the time of the C<listcreate>). If you want to put an element into an occupied cell, i.e.S< >if you don't want to change the effective length, you can consider the list as a vector and use the usual C<list[n] = x> construct. This function is useless in library mode. =head2 X<listsort>listsortC<(I<list>,{I<flag> = 0})> sorts I<list> (which must be of type C<t_LIST>) in place. If C<I<flag>> is non-zero, suppresses all repeated coefficients. This is much faster than the C<vecsort> command since no copy has to be made. This function is useless in library mode. =head2 X<matadjoint>matadjointC<(x)> X<adjoint matrix>adjoint matrix of C<x>, i.e.S< >the matrix C<y> of cofactors of C<x>, satisfying C<x*y = F<det> (x)*\Id>. C<x> must be a (non-necessarily invertible) square matrix. X<adj>The library syntax is B<adj>C<(x)>. =head2 X<matcompanion>matcompanionC<(x)> the left companion matrix to the polynomial C<x>. X<assmat>The library syntax is B<assmat>C<(x)>. =head2 X<matdet>matdetC<(x,{I<flag> = 0})> determinant of C<x>. C<x> must be a square matrix. If C<I<flag> = 0>, uses Gauss-Bareiss. If C<I<flag> = 1>, uses classical Gaussian elimination, which is better when the entries of the matrix are reals or integers for example, but usually much worse for more complicated entries like multivariate polynomials. X<det>The library syntax is B<det>C<(x)> (C<I<flag> = 0>) and C< B<det2>(x)>X<det2> (C<I<flag> = 1>). =head2 X<matdetint>matdetintC<(x)> C<x> being an C<m x n> matrix with integer coefficients, this function computes a \emph{multiple} of the determinant of the lattice generated by the columns of C<x> if it is of rank C<m>, and returns zero otherwise. This function can be useful in conjunction with the function C<mathnfmod> which needs to know such a multiple. To obtain the exact determinant (assuming the rank is maximal), you can compute C<matdet(mathnfmod(x, matdetint(x)))>. Note that as soon as one of the dimensions gets large (C<m> or C<n> is larger than 20, say), it will often be much faster to use C<mathnf(x, 1)> or C<mathnf(x, 4)> directly. X<detint>The library syntax is B<detint>C<(x)>. =head2 X<matdiagonal>matdiagonalC<(x)> C<x> being a vector, creates the diagonal matrix whose diagonal entries are those of C<x>. X<diagonal>The library syntax is B<diagonal>C<(x)>. =head2 X<mateigen>mateigenC<(x)> gives the eigenvectors of C<x> as columns of a matrix. X<eigen>The library syntax is B<eigen>C<(x)>. =head2 X<matfrobenius>matfrobeniusC<(M,{I<flag> = 0},{v = x})> returns the Frobenius form of the square matrix C<M>. If C<I<flag> = 1>, returns only the elementary divisors as a vectr of polynomials in the variable C<v>. If C<I<flag> = 2>, returns a two-components vector [F,B] where C<F> is the Frobenius form and C<B> is the basis change so that C<M = B^{-1}FB>. X<matfrobenius>The library syntax is B<matfrobenius>C<(M,I<flag>,v)>, where C<v> is the variable number. =head2 X<mathess>mathessC<(x)> Hessenberg form of the square matrix C<x>. X<hess>The library syntax is B<hess>C<(x)>. =head2 X<mathilbert>mathilbertC<(x)> C<x> being a C<long>, creates the X<Hilbert matrix>Hilbert matrixof order C<x>, i.e.S< >the matrix whose coefficient (C<i>,C<j>) is C<1/ (i+j-1)>. X<mathilbert>The library syntax is B<mathilbert>C<(x)>. =head2 X<mathnf>mathnfC<(x,{I<flag> = 0})> if C<x> is a (not necessarily square) matrix with integer entries, finds the \emph{upper triangular} X<Hermite normal form>Hermite normal form of C<x>. If the rank of C<x> is equal to its number of rows, the result is a square matrix. In general, the columns of the result form a basis of the lattice spanned by the columns of C<x>. If C<I<flag> = 0>, uses the naive algorithm. This should never be used if the dimension is at all large (larger than 10, say). It is recommanded to use either C<mathnfmod(x, matdetint(x))> (when C<x> has maximal rank) or C<mathnf(x, 1)>. Note that the latter is in general faster than C<mathnfmod>, and also provides a base change matrix. If C<I<flag> = 1>, uses Batut's algorithm, which is much faster than the default. Outputs a two-component row vector C<[H,U]>, where C<H> is the \emph{upper triangular} Hermite normal form of C<x> defined as above, and C<U> is the unimodular transformation matrix such that C<xU = [0|H]>. C<U> has in general huge coefficients, in particular when the kernel is large. If C<I<flag> = 3>, uses Batut's algorithm, but outputs C<[H,U,P]>, such that C<H> and C<U> are as before and C<P> is a permutation of the rows such that C<P> applied to C<xU> gives C<H>. The matrix C<U> is smaller than with C<I<flag> = 1>, but may still be large. If C<I<flag> = 4>, as in case 1 above, but uses a heuristic variant of X<LLL>LLL reduction along the way. The matrix C<U> is in general close to optimal (in terms of smallest C<L_2> norm), but the reduction is slower than in case C<1>. X<mathnf0>The library syntax is B<mathnf0>C<(x,I<flag>)>. Also available are C< B<hnf>(x)>X<hnf> (C<I<flag> = 0>) and C< B<hnfall>(x)>X<hnfall> (C<I<flag> = 1>). To reduce \emph{huge} (say C<400 x 400> and more) relation matrices (sparse with small entries), you can use the pair C<hnfspec> / C<hnfadd>. Since this is rather technical and the calling interface may change, they are not documented yet. Look at the code in C<basemath/alglin1.c>. =head2 X<mathnfmod>mathnfmodC<(x,d)> if C<x> is a (not necessarily square) matrix of maximal rank with integer entries, and C<d> is a multiple of the (non-zero) determinant of the lattice spanned by the columns of C<x>, finds the \emph{upper triangular} X<Hermite normal form>Hermite normal form of C<x>. If the rank of C<x> is equal to its number of rows, the result is a square matrix. In general, the columns of the result form a basis of the lattice spanned by the columns of C<x>. This is much faster than C<mathnf> when C<d> is known. X<hnfmod>The library syntax is B<hnfmod>C<(x,d)>. =head2 X<mathnfmodid>mathnfmodidC<(x,d)> outputs the (upper triangular) X<Hermite normal form>Hermite normal form of C<x> concatenated with C<d> times the identity matrix. Assumes that C<x> has integer entries. X<hnfmodid>The library syntax is B<hnfmodid>C<(x,d)>. =head2 X<matid>matidC<(n)> creates the C<n x n> identity matrix. X<matid>The library syntax is B<matid>C<(n)> where C<n> is a C<long>. Related functions are C< B<gscalmat>(x,n)>X<gscalmat>, which creates C<x> times the identity matrix (C<x> being a C<GEN> and C<n> a C<long>), and C< B<gscalsmat>(x,n)>X<gscalsmat> which is the same when C<x> is a C<long>. =head2 X<matimage>matimageC<(x,{I<flag> = 0})> gives a basis for the image of the matrix C<x> as columns of a matrix. A priori the matrix can have entries of any type. If C<I<flag> = 0>, use standard Gauss pivot. If C<I<flag> = 1>, use C<matsupplement>. X<matimage0>The library syntax is B<matimage0>C<(x,I<flag>)>. Also available is C< B<image>(x)>X<image> (C<I<flag> = 0>). =head2 X<matimagecompl>matimagecomplC<(x)> gives the vector of the column indices which are not extracted by the function C<matimage>. Hence the number of components of C<matimagecompl(x)> plus the number of columns of C<matimage(x)> is equal to the number of columns of the matrix C<x>. X<imagecompl>The library syntax is B<imagecompl>C<(x)>. =head2 X<matindexrank>matindexrankC<(x)> C<x> being a matrix of rank C<r>, gives two vectors C<y> and C<z> of length C<r> giving a list of rows and columns respectively (starting from 1) such that the extracted matrix obtained from these two vectors using C<X<vecextract>vecextract(x,y,z)> is invertible. X<indexrank>The library syntax is B<indexrank>C<(x)>. =head2 X<matintersect>matintersectC<(x,y)> C<x> and C<y> being two matrices with the same number of rows each of whose columns are independent, finds a basis of the B<I<Q>>-vector space equal to the intersection of the spaces spanned by the columns of C<x> and C<y> respectively. See also the function X<idealintersect>C<idealintersect>, which does the same for free B<I<Z>>-modules. X<intersect>The library syntax is B<intersect>C<(x,y)>. =head2 X<matinverseimage>matinverseimageC<(M,y)> gives a column vector belonging to the inverse image C<z> of the column vector or matrix C<y> by the matrix C<M> if one exists (i.e such that C<Mz = y>), the empty vector otherwise. To get the complete inverse image, it suffices to add to the result any element of the kernel of C<x> obtained for example by C<matker>. X<inverseimage>The library syntax is B<inverseimage>C<(x,y)>. =head2 X<matisdiagonal>matisdiagonalC<(x)> returns true (1) if C<x> is a diagonal matrix, false (0) if not. X<isdiagonal>The library syntax is B<isdiagonal>C<(x)>, and this returns a C<long> integer. =head2 X<matker>matkerC<(x,{I<flag> = 0})> gives a basis for the kernel of the matrix C<x> as columns of a matrix. A priori the matrix can have entries of any type. If C<x> is known to have integral entries, set C<I<flag> = 1>. B<Note:> The library function C<X<FpM_ker>FpM_ker(x, p)>, where C<x> has integer entries \emph{reduced mod p} and C<p> is prime, is equivalent to, but orders of magnitude faster than, C<matker(x*Mod(1,p))> and needs much less stack space. To use it under C<gp>, type C<install(FpM_ker, GG)> first. X<matker0>The library syntax is B<matker0>C<(x,I<flag>)>. Also available are C< B<ker>(x)>X<ker> (C<I<flag> = 0>), C< B<keri>(x)>X<keri> (C<I<flag> = 1>). =head2 X<matkerint>matkerintC<(x,{I<flag> = 0})> gives an X<LLL>LLL-reduced B<I<Z>>-basis for the lattice equal to the kernel of the matrix C<x> as columns of the matrix C<x> with integer entries (rational entries are not permitted). If C<I<flag> = 0>, uses a modified integer LLL algorithm. If C<I<flag> = 1>, uses C<matrixqz(x,-2)>. If LLL reduction of the final result is not desired, you can save time using C<matrixqz(matker(x),-2)> instead. X<matkerint0>The library syntax is B<matkerint0>C<(x,I<flag>)>. Also available is C< B<kerint>(x)>X<kerint> (C<I<flag> = 0>). =head2 X<matmuldiagonal>matmuldiagonalC<(x,d)> product of the matrix C<x> by the diagonal matrix whose diagonal entries are those of the vector C<d>. Equivalent to, but much faster than C<x*matdiagonal(d)>. X<matmuldiagonal>The library syntax is B<matmuldiagonal>C<(x,d)>. =head2 X<matmultodiagonal>matmultodiagonalC<(x,y)> product of the matrices C<x> and C<y> assuming that the result is a diagonal matrix. Much faster than C<x*y> in that case. The result is undefined if C<x*y> is not diagonal. X<matmultodiagonal>The library syntax is B<matmultodiagonal>C<(x,y)>. =head2 X<matpascal>matpascalC<(x,{q})> creates as a matrix the lower triangular X<Pascal triangle>Pascal triangle of order C<x+1> (i.e.S< >with binomial coefficients up to C<x>). If C<q> is given, compute the C<q>-Pascal triangle (i.e.S< >using C<q>-binomial coefficients). X<matqpascal>The library syntax is B<matqpascal>C<(x,q)>, where C<x> is a C<long> and C<q = NULL> is used to omit C<q>. Also available is C< B<matpascal>(x)>X<matpascal>. =head2 X<matrank>matrankC<(x)> rank of the matrix C<x>. X<rank>The library syntax is B<rank>C<(x)>, and the result is a C<long>. =head2 X<matrix>matrixC<(m,n,{X},{Y},{I<expr> = 0})> creation of the C<m x n> matrix whose coefficients are given by the expression I<expr>. There are two formal parameters in I<expr>, the first one (C<X>) corresponding to the rows, the second (C<Y>) to the columns, and C<X> goes from 1 to C<m>, C<Y> goes from 1 to C<n>. If one of the last 3 parameters is omitted, fill the matrix with zeroes. X<matrice>The library syntax is B<matrice>C<(GEN nlig,GEN ncol,entree *e1,entree *e2,char *expr)>. =head2 X<matrixqz>matrixqzC<(x,p)> C<x> being an C<m x n> matrix with C<m E<gt>= n> with rational or integer entries, this function has varying behaviour depending on the sign of C<p>: If C<p E<gt>= 0>, C<x> is assumed to be of maximal rank. This function returns a matrix having only integral entries, having the same image as C<x>, such that the GCD of all its C<n x n> subdeterminants is equal to 1 when C<p> is equal to 0, or not divisible by C<p> otherwise. Here C<p> must be a prime number (when it is non-zero). However, if the function is used when C<p> has no small prime factors, it will either work or give the message ``impossible inverse modulo'' and a non-trivial divisor of C<p>. If C<p = -1>, this function returns a matrix whose columns form a basis of the lattice equal to C<B<I<Z>>^n> intersected with the lattice generated by the columns of C<x>. If C<p = -2>, returns a matrix whose columns form a basis of the lattice equal to C<B<I<Z>>^n> intersected with the B<I<Q>>-vector space generated by the columns of C<x>. X<matrixqz0>The library syntax is B<matrixqz0>C<(x,p)>. =head2 X<matsize>matsizeC<(x)> C<x> being a vector or matrix, returns a row vector with two components, the first being the number of rows (1 for a row vector), the second the number of columns (1 for a column vector). X<matsize>The library syntax is B<matsize>C<(x)>. =head2 X<matsnf>matsnfC<(X,{I<flag> = 0})> if C<X> is a (singular or non-singular) matrix outputs the vector of elementary divisors of C<X> (i.e.S< >the diagonal of the X<Smith normal form>Smith normal form of C<X>). The binary digits of I<flag> mean: 1 (complete output): if set, outputs C<[U,V,D]>, where C<U> and C<V> are two unimodular matrices such that C<UXV> is the diagonal matrix C<D>. Otherwise output only the diagonal of C<D>. 2 (generic input): if set, allows polynomial entries, in which case the input matrix must be square. Otherwise, assume that C<X> has integer coefficients with arbitrary shape. 4 (cleanup): if set, cleans up the output. This means that elementary divisors equal to C<1> will be deleted, i.e.S< >outputs a shortened vector C<D'> instead of C<D>. If complete output was required, returns C<[U',V',D']> so that C<U'XV' = D'> holds. If this flag is set, C<X> is allowed to be of the form C<D> or C<[U,V,D]> as would normally be output with the cleanup flag unset. X<matsnf0>The library syntax is B<matsnf0>C<(X,I<flag>)>. Also available is C< B<smith>(X)>X<smith> (C<I<flag> = 0>). =head2 X<matsolve>matsolveC<(x,y)> C<x> being an invertible matrix and C<y> a column vector, finds the solution C<u> of C<x*u = y>, using Gaussian elimination. This has the same effect as, but is a bit faster, than C<x^{-1}*y>. X<gauss>The library syntax is B<gauss>C<(x,y)>. =head2 X<matsolvemod>matsolvemodC<(m,d,y,{I<flag> = 0})> C<m> being any integral matrix, C<d> a vector of positive integer moduli, and C<y> an integral column vector, gives a small integer solution to the system of congruences C<F<sum>_i m_{i,j}x_j = y_i (mod d_i)> if one exists, otherwise returns zero. Shorthand notation: C<y> (resp.S< >C<d>) can be given as a single integer, in which case all the C<y_i> (resp.S< >C<d_i>) above are taken to be equal to C<y> (resp.S< >C<d>). ? m = [1,2;3,4]; ? matsolvemod(m, [3,4], [1,2]~) %2 = [-2, 0]~ ? matsolvemod(m, 3, 1) \\ m X = [1,1]~ over F_3 %3 = [-1, 1]~ If C<I<flag> = 1>, all solutions are returned in the form of a two-component row vector C<[x,u]>, where C<x> is a small integer solution to the system of congruences and C<u> is a matrix whose columns give a basis of the homogeneous system (so that all solutions can be obtained by adding C<x> to any linear combination of columns of C<u>). If no solution exists, returns zero. X<matsolvemod0>The library syntax is B<matsolvemod0>C<(m,d,y,I<flag>)>. Also available are C< B<gaussmodulo>(m,d,y)>X<gaussmodulo> (C<I<flag> = 0>) and C< B<gaussmodulo2>(m,d,y)>X<gaussmodulo2> (C<I<flag> = 1>). =head2 X<matsupplement>matsupplementC<(x)> assuming that the columns of the matrix C<x> are linearly independent (if they are not, an error message is issued), finds a square invertible matrix whose first columns are the columns of C<x>, i.e.S< >supplement the columns of C<x> to a basis of the whole space. X<suppl>The library syntax is B<suppl>C<(x)>. =head2 X<mattranspose>mattransposeC<(x)> or C<x~> transpose of C<x>. This has an effect only on vectors and matrices. X<gtrans>The library syntax is B<gtrans>C<(x)>. =head2 X<minpoly>minpolyC<(A,{v = x},{I<flag> = 0})> X<minimal polynomial>minimal polynomial of C<A> with respect to the variable C<v>., i.e. the monic polynomial C<P> of minimal degree (in the variable C<v>) such that C<P(A) = 0>. X<minpoly>The library syntax is B<minpoly>C<(A,v)>, where C<v> is the variable number. =head2 X<qfgaussred>qfgaussredC<(q)> X<decomposition into squares>decomposition into squares of the quadratic form represented by the symmetric matrix C<q>. The result is a matrix whose diagonal entries are the coefficients of the squares, and the non-diagonal entries represent the bilinear forms. More precisely, if C<(a_{ij})> denotes the output, one has S< >C< q(x) = F<sum>_i a_{ii} (x_i + F<sum>_{j E<gt> i} a_{ij} x_j)^2 > X<sqred>The library syntax is B<sqred>C<(x)>. =head2 X<qfjacobi>qfjacobiC<(x)> C<x> being a real symmetric matrix, this gives a vector having two components: the first one is the vector of eigenvalues of C<x>, the second is the corresponding orthogonal matrix of eigenvectors of C<x>. The method used is Jacobi's method for symmetric matrices. X<jacobi>The library syntax is B<jacobi>C<(x)>. =head2 X<qflll>qflllC<(x,{I<flag> = 0})> X<LLL>LLL algorithm applied to the \emph{columns} of the matrix C<x>. The columns of C<x> must be linearly independent, unless specified otherwise below. The result is a unimodular transformation matrix C<T> such that C<x.T> is an LLL-reduced basis of the lattice generated by the column vectors of C<x>. If C<I<flag> = 0> (default), the computations are done with floating point numbers, using Householder matrices for orthogonalization. If C<x> has integral entries, then computations are nonetheless approximate, with precision varying as needed (Lehmer's trick, as generalized by Schnorr). If C<I<flag> = 1>, it is assumed that C<x> is integral. The computation is done entirely with integers. In this case, C<x> needs not be of maximal rank, but if it is not, C<T> will not be square. This is slower and no more accurate than C<I<flag> = 0> above if C<x> has small dimension (say C<100> or less). If C<I<flag> = 2>, C<x> should be an integer matrix whose columns are linearly independent. Returns a partially reduced basis for C<x>, using an unpublished algorithm by Peter Montgomery: a basis is said to be \emph{partially reduced} if C<|v_i F<+-> v_j| E<gt>= |v_i|> for any two distinct basis vectors C<v_i, v_j>. This is significantly faster than C<I<flag> = 1>, esp. when one row is huge compared to the other rows. Note that the resulting basis is \emph{not} LLL-reduced in general. If C<I<flag> = 4>, C<x> is assumed to have integral entries, but needs not be of maximal rank. The result is a two-component vector of matrices: the columns of the first matrix represent a basis of the integer kernel of C<x> (not necessarily LLL-reduced) and the second matrix is the transformation matrix C<T> such that C<x.T> is an LLL-reduced B<I<Z>>-basis of the image of the matrix C<x>. If C<I<flag> = 5>, case as case C<4>, but C<x> may have polynomial coefficients. If C<I<flag> = 8>, same as case C<0>, but C<x> may have polynomial coefficients. X<qflll0>The library syntax is B<qflll0>C<(x,I<flag>,I<prec>)>. Also available are C< B<lll>(x,I<prec>)>X<lll> (C<I<flag> = 0>), C< B<lllint>(x)>X<lllint> (C<I<flag> = 1>), and C< B<lllkerim>(x)>X<lllkerim> (C<I<flag> = 4>). =head2 X<qflllgram>qflllgramC<(G,{I<flag> = 0})> same as C<qflll>, except that the matrix C<G = x~ * x> is the Gram matrix of some lattice vectors C<x>, and not the coordinates of the vectors themselves. In particular, C<G> must now be a square symmetric real matrix, corresponding to a positive definite quadratic form. The result is a unimodular transformation matrix C<T> such that C<x.T> is an LLL-reduced basis of the lattice generated by the column vectors of C<x>. If C<I<flag> = 0> (default): the computations are done with floating point numbers, using Householder matrices for orthogonalization. If C<G> has integral entries, then computations are nonetheless approximate, with precision varying as needed (Lehmer's trick, as generalized by Schnorr). If C<I<flag> = 1>: C<G> has integer entries, still positive but not necessarily definite (i.eS< >C<x> needs not have maximal rank). The computations are all done in integers and should be slower than the default, unless the latter triggers accuracy problems. C<I<flag> = 4>: C<G> has integer entries, gives the kernel and reduced image of C<x>. C<I<flag> = 5>: same as case C<4>, but C<G> may have polynomial coefficients. X<qflllgram0>The library syntax is B<qflllgram0>C<(G,I<flag>,I<prec>)>. Also available are C< B<lllgram>(G,I<prec>)>X<lllgram> (C<I<flag> = 0>), C< B<lllgramint>(G)>X<lllgramint> (C<I<flag> = 1>), and C< B<lllgramkerim>(G)>X<lllgramkerim> (C<I<flag> = 4>). =head2 X<qfminim>qfminimC<(x,{b},{m},{I<flag> = 0})> C<x> being a square and symmetric matrix representing a positive definite quadratic form, this function deals with the vectors of C<x> whose norm is less than or equal to C<b>, enumerated using the Fincke-Pohst algorithm. The function searches for the minimal non-zero vectors if C<b> is omitted. The precise behaviour depends on C<I<flag>>. If C<I<flag> = 0> (default), seeks at most C<2m> vectors. The result is a three-component vector, the first component being the number of vectors found, the second being the maximum norm found, and the last vector is a matrix whose columns are the vectors found, only one being given for each pair C<F<+-> v> (at most C<m> such pairs). The vectors are returned in no particular order. In this variant, an explicit C<m> must be provided. If C<I<flag> = 1>, ignores C<m> and returns the first vector whose norm is less than C<b>. In this variant, an explicit C<b> must be provided. In both these cases, C<x> is assumed to have integral entries. The implementation uses low precision floating point computations for maximal speed, which gives incorrect result when C<x> has large entries. (The condition is checked in the code and the routine will raise an error if large rounding errors occur.) A more robust, but much slower, implementation is chosen if the following flag is used: If C<I<flag> = 2>, C<x> can have non integral real entries. In this case, if C<b> is omitted, the ``minimal'' vectors only have approximately the same norm. If C<b> is omitted, C<m> is an upper bound for the number of vectors that will be stored and returned, but all minimal vectors are nevertheless enumerated. If C<m> is omitted, all vectors found are stored and returned; note that this may be a huge vector! X<qfminim0>The library syntax is B<qfminim0>C<(x,b,m,I<flag>,I<prec>)>, also available are C< B<minim>(x,b,m)>X<minim> (C<I<flag> = 0>), C< B<minim2>(x,b,m)>X<minim2> (C<I<flag> = 1>). In all cases, an omitted C<b> or C<m> is coded as C<NULL>. =head2 X<qfperfection>qfperfectionC<(x)> C<x> being a square and symmetric matrix with integer entries representing a positive definite quadratic form, outputs the perfection rank of the form. That is, gives the rank of the family of the C<s> symmetric matrices C<v_iv_i^t>, where C<s> is half the number of minimal vectors and the C<v_i> (C<1 E<lt>= i E<lt>= s>) are the minimal vectors. As a side note to old-timers, this used to fail bluntly when C<x> had more than C<5000> minimal vectors. Beware that the computations can now be very lengthy when C<x> has many minimal vectors. X<perf>The library syntax is B<perf>C<(x)>. =head2 X<qfrep>qfrepC<(q, B, {I<flag> = 0})> C<q> being a square and symmetric matrix with integer entries representing a positive definite quadratic form, outputs the vector whose C<i>-th entry, C<1 E<lt>= i E<lt>= B> is half the number of vectors C<v> such that C<q(v) = i>. This routine uses a naive algorithm based on X<qfminim>C<qfminim>, and will fail if any entry becomes larger than C<2^{31}>. The binary digits of I<flag> mean: \item 1: count vectors of even norm from C<1> to C<2B>. \item 2: return a C<t_VECSMALL> instead of a C<t_GEN> X<qfrep0>The library syntax is B<qfrep0>C<(q, B, I<flag>)>. =head2 X<qfsign>qfsignC<(x)> signature of the quadratic form represented by the symmetric matrix C<x>. The result is a two-component vector. X<signat>The library syntax is B<signat>C<(x)>. =head2 X<setintersect>setintersectC<(x,y)> intersection of the two sets C<x> and C<y>. X<setintersect>The library syntax is B<setintersect>C<(x,y)>. =head2 X<setisset>setissetC<(x)> returns true (1) if C<x> is a set, false (0) if not. In PARI, a set is simply a row vector whose entries are strictly increasing. To convert any vector (and other objects) into a set, use the function C<Set>. X<setisset>The library syntax is B<setisset>C<(x)>, and this returns a C<long>. =head2 X<setminus>setminusC<(x,y)> difference of the two sets C<x> and C<y>, i.e.S< >set of elements of C<x> which do not belong to C<y>. X<setminus>The library syntax is B<setminus>C<(x,y)>. =head2 X<setsearch>setsearchC<(x,y,{I<flag> = 0})> searches if C<y> belongs to the set C<x>. If it does and C<I<flag>> is zero or omitted, returns the index C<j> such that C<x[j] = y>, otherwise returns 0. If C<I<flag>> is non-zero returns the index C<j> where C<y> should be inserted, and C<0> if it already belongs to C<x> (this is meant to be used in conjunction with C<listinsert>). This function works also if C<x> is a \emph{sorted} list (see C<listsort>). X<setsearch>The library syntax is B<setsearch>C<(x,y,I<flag>)> which returns a C<long> integer. =head2 X<setunion>setunionC<(x,y)> union of the two sets C<x> and C<y>. X<setunion>The library syntax is B<setunion>C<(x,y)>. =head2 X<trace>traceC<(x)> this applies to quite general C<x>. If C<x> is not a matrix, it is equal to the sum of C<x> and its conjugate, except for polmods where it is the trace as an algebraic number. For C<x> a square matrix, it is the ordinary trace. If C<x> is a non-square matrix (but not a vector), an error occurs. X<gtrace>The library syntax is B<gtrace>C<(x)>. =head2 X<vecextract>vecextractC<(x,y,{z})> extraction of components of the vector or matrix C<x> according to C<y>. In case C<x> is a matrix, its components are as usual the \emph{columns} of C<x>. The parameter C<y> is a component specifier, which is either an integer, a string describing a range, or a vector. If C<y> is an integer, it is considered as a mask: the binary bits of C<y> are read from right to left, but correspond to taking the components from left to right. For example, if C<y = 13 = (1101)_2> then the components 1,3 and 4 are extracted. If C<y> is a vector, which must have integer entries, these entries correspond to the component numbers to be extracted, in the order specified. If C<y> is a string, it can be \item a single (non-zero) index giving a component number (a negative index means we start counting from the end). \item a range of the form C<"a..b">, where C<a> and C<b> are indexes as above. Any of C<a> and C<b> can be omitted; in this case, we take as default values C<a = 1> and C<b = -1>, i.e.S< >the first and last components respectively. We then extract all components in the interval C<[a,b]>, in reverse order if C<b E<lt> a>. In addition, if the first character in the string is C<^>, the complement of the given set of indices is taken. If C<z> is not omitted, C<x> must be a matrix. C<y> is then the \emph{line} specifier, and C<z> the \emph{column} specifier, where the component specifier is as explained above. ? v = [a, b, c, d, e]; ? vecextract(v, 5) \\ mask %1 = [a, c] ? vecextract(v, [4, 2, 1]) \\ component list %2 = [d, b, a] ? vecextract(v, "2..4") \\ interval %3 = [b, c, d] ? vecextract(v, "-1..-3") \\ interval + reverse order %4 = [e, d, c] ? vecextract(v, "^2") \\ complement %5 = [a, c, d, e] ? vecextract(matid(3), "2..", "..") %6 = [0 1 0] [0 0 1] X<extract>The library syntax is B<extract>C<(x,y)> or C< B<matextract>(x,y,z)>X<matextract>. =head2 X<vecsort>vecsortC<(x,{k},{I<flag> = 0})> sorts the vector C<x> in ascending order, using a mergesort method. C<x> must be a vector, and its components integers, reals, or fractions. If C<k> is present and is an integer, sorts according to the value of the C<k>-th subcomponents of the components ofS< >C<x>. Note that mergesort is stable, hence is the initial ordering of "equal" entries (with respect to the sorting criterion) is not changed. C<k> can also be a vector, in which case the sorting is done lexicographically according to the components listed in the vector C<k>. For example, if C<k = [2,1,3]>, sorting will be done with respect to the second component, and when these are equal, with respect to the first, and when these are equal, with respect to the third. The binary digits of I<flag> mean: \item 1: indirect sorting of the vector C<x>, i.e.S< >if C<x> is an C<n>-component vector, returns a permutation of C<[1,2,...,n]> which applied to the components of C<x> sorts C<x> in increasing order. For example, C<vecextract(x, vecsort(x,,1))> is equivalent to C<vecsort(x)>. \item 2: sorts C<x> by ascending lexicographic order (as per the C<lex> comparison function). \item 4: use descending instead of ascending order. X<vecsort0>The library syntax is B<vecsort0>C<(x,k,flag)>. To omit C<k>, use C<NULL> instead. You can also use the simpler functions C< B<sort>(x)>X<sort> ( = C< B<vecsort0>(x,NULL,0)>X<vecsort0>). C< B<indexsort>(x)>X<indexsort> ( = C< B<vecsort0>(x,NULL,1)>X<vecsort0>). C< B<lexsort>(x)>X<lexsort> ( = C< B<vecsort0>(x,NULL,2)>X<vecsort0>). Also available are C< B<sindexsort>(x)>X<sindexsort> and C< B<sindexlexsort>(x)>X<sindexlexsort> which return a C<t_VECSMALL> C<v>, where C<v[1]...v[n]> contain the indices. =head2 X<vector>vectorC<(n,{X},{I<expr> = 0})> creates a row vector (type C<t_VEC>) with C<n> components whose components are the expression I<expr> evaluated at the integer points between 1 and C<n>. If one of the last two arguments is omitted, fill the vector with zeroes. Avoid modifying C<X> within I<expr>; if you do, the formal variable still runs from C<1> to C<n>. In particular, C<vector(n,i,expr)> is not equivalent to v = vector(n) for (i = 1, n, v[i] = expr) as the following example shows: n = 3 v = vector(n); vector(n, i, i++) ----> [2, 3, 4] v = vector(n); for (i = 1, n, v[i] = i++) ----> [2, 0, 4] X<vecteur>The library syntax is B<vecteur>C<(GEN nmax, entree *ep, char *expr)>. =head2 X<vectorsmall>vectorsmallC<(n,{X},{I<expr> = 0})> creates a row vector of small integers (type C<t_VECSMALL>) with C<n> components whose components are the expression I<expr> evaluated at the integer points between 1 and C<n>. If one of the last two arguments is omitted, fill the vector with zeroes. X<vecteursmall>The library syntax is B<vecteursmall>C<(GEN nmax, entree *ep, char *expr)>. =head2 X<vectorv>vectorvC<(n,X,I<expr>)> as X<vector>C<vector>, but returns a column vector (type C<t_COL>). X<vvecteur>The library syntax is B<vvecteur>C<(GEN nmax, entree *ep, char *expr)>. =head1 Sums, products, integrals and similar functions X<Label se:sums> Although the C<gp> calculator is programmable, it is useful to have preprogrammed a number of loops, including sums, products, and a certain number of recursions. Also, a number of functions from numerical analysis like numerical integration and summation of series will be described here. One of the parameters in these loops must be the control variable, hence a simple variable name. In the descriptions, the letter C<X> will always denote any simple variable name, and represents the formal parameter used in the function. The expression to be summed, integrated, etc. is any legal PARI expression, including of course expressions using loops. B<Library mode.> Since it is easier to program directly the loops in library mode, these functions are mainly useful for GP programming. Using them in library mode is tricky and we will not give any details, although the reader can try and figure it out by himself by checking the example given for X<sum>C<sum>. On the other hand, numerical routines code a function (to be integrated, summed, etc.) with two parameters named GEN (*eval)(GEN,void*) void *E; The second is meant to contain all auxilliary data needed by your function. The first is such that C<eval(x, E)> returns your function evaluated at C<x>. For instance, one may code the family of functions C<f_t: x \to (x+t)^2> via GEN f(GEN x, void *t) { return gsqr(gadd(x, (GEN)t)); } One can then integrate C<f_1> between C<a> and C<b> with the call intnum((void*)stoi(1), &fun, a, b, NULL, prec); Since you can set C<E> to a pointer to any C<struct> (typecast to C<void*>) the above mechanism handles arbitrary functions. For simple functions without extra parameters, you may set C<E = NULL> and ignore that argument in your function definition. B<Numerical integration.>X<numerical integration> Starting with version 2.2.9 the powerful ``double exponential'' univariate integration method is implemented in X<intnum>C<intnum> and its variants. Romberg integration is still available under the name C<intnumromb>, but superseded. It is possible to compute numerically integrals to thousands of decimal places in reasonable time, as long as the integrand is regular. It is also reasonable to compute numerically integrals in several variables, although more than two becomes lengthy. The integration domain may be non-compact, and the integrand may have reasonable singularities at endpoints. To use C<intnum>, the user must split the integral into a sum of subintegrals where the function has (possible) singularities only at the endpoints. Polynomials in logarithms are not considered singular, and neglecting these logs, singularities are assumed to be algebraic (in other words asymptotic to C<C(x-a)^{-F<alpha>}> for some C<F<alpha>> such that C<F<alpha> E<gt> -1> when C<x> is close to C<a>), or to correspond to simple discontinuities of some (higher) derivative of the function. For instance, the point C<0> is a singularity of C<abs(x)>. See also the discrete summation methods below (sharing the prefix C<sum>). =head2 X<intcirc>intcircC<(X = a,R,I<expr>, {I<tab>})> numerical integration of I<expr> with respect to C<X> on the circle C<|X-a |= R>, divided by C<2iF<Pi>>. In other words, when I<expr> is a meromorphic function, sum of the residues in the corresponding disk. I<tab> is as in C<intnum>, except that if computed with C<intnuminit> it should be with the endpoints C<[-1, 1]>. ? \p105 ? intcirc(s=1, 0.5, zeta(s)) - 1 time = 3,460 ms. %1 = -2.40... E-104 - 2.7... E-106*I X<intcirc>The library syntax is B<intcirc>C<(void *E, GEN (*eval)(GEN,void*), GEN a,GEN R,GEN tab, long prec)>. =head2 X<intfouriercos>intfouriercosC<(X = a,b,z,I<expr>,{I<tab>})> numerical integration of C<I<expr>(X) F<cos> (2F<Pi> zX)> from C<a> to C<b>, in other words Fourier cosine transform (from C<a> to C<b>) of the function represented by I<expr>. C<a> and C<b> are coded as in C<intnum>, and are not necessarily at infinity, but if they are, oscillations (i.e. C<[[F<+->1],F<alpha> I]>) are forbidden. X<intfouriercos>The library syntax is B<intfouriercos>C<(void *E, GEN (*eval)(GEN,void*), GEN a, GEN b, GEN z, GEN tab, long prec)>. =head2 X<intfourierexp>intfourierexpC<(X = a,b,z,I<expr>,{I<tab>})> numerical integration of C<I<expr>(X) F<exp> (-2F<Pi> zX)> from C<a> to C<b>, in other words Fourier transform (from C<a> to C<b>) of the function represented by I<expr>. Note the minus sign. C<a> and C<b> are coded as in C<intnum>, and are not necessarily at infinity but if they are, oscillations (i.e. C<[[F<+->1],F<alpha> I]>) are forbidden. X<intfourierexp>The library syntax is B<intfourierexp>C<(void *E, GEN (*eval)(GEN,void*), GEN a, GEN b, GEN z, GEN tab, long prec)>. =head2 X<intfouriersin>intfouriersinC<(X = a,b,z,I<expr>,{I<tab>})> numerical integration of C<I<expr>(X) F<sin> (2F<Pi> zX)> from C<a> to C<b>, in other words Fourier sine transform (from C<a> to C<b>) of the function represented by I<expr>. C<a> and C<b> are coded as in C<intnum>, and are not necessarily at infinity but if they are, oscillations (i.e. C<[[F<+->1],F<alpha> I]>) are forbidden. X<intfouriersin>The library syntax is B<intfouriersin>C<(void *E, GEN (*eval)(GEN,void*), GEN a, GEN b, GEN z, GEN tab, long prec)>. =head2 X<intfuncinit>intfuncinitC<(X = a,b,I<expr>,{I<flag> = 0},{m = 0})> initalize tables for use with integral transforms such as C<intmellininv>, etc., where C<a> and C<b> are coded as in C<intnum>, C<I<expr>> is the function C<s(X)> to which the integral transform is to be applied (which will multiply the weights of integration) and C<m> is as in C<intnuminit>. If C<I<flag>> is nonzero, assumes that C<s(-X) = \overline{s(X)}>, which makes the computation twice as fast. See C<intmellininvshort> for examples of the use of this function, which is particularly useful when the function C<s(X)> is lengthy to compute, such as a gamma product. X<intfuncinit>The library syntax is B<intfuncinit>C<(void *E, GEN (*eval)(GEN,void*), GEN a,GEN b,long m, long flag, long prec)>. Note that the order of C<m> and C<I<flag>> are reversed compared to the C<GP> syntax. =head2 X<intlaplaceinv>intlaplaceinvC<(X = sig,z,I<expr>,{I<tab>})> numerical integration of C<I<expr>(X)e^{Xz}> with respect to C<X> on the line C< F<Re> (X) = sig>, divided by C<2iF<Pi>>, in other words, inverse Laplace transform of the function corresponding to I<expr> at the value C<z>. C<sig> is coded as follows. Either it is a real number C<F<sigma>>, equal to the abcissa of integration, and then the function to be integrated is assumed to be slowly decreasing when the imaginary part of the variable tends to C<F<+-> oo >. Or it is a two component vector C<[F<sigma>,F<alpha>]>, where C<F<sigma>> is as before, and either C<F<alpha> = 0> for slowly decreasing functions, or C<F<alpha> E<gt> 0> for functions decreasing like C< F<exp> (-F<alpha> t)>. Note that it is not necessary to choose the exact value of C<F<alpha>>. I<tab> is as in C<intnum>. It is often a good idea to use this function with a value of C<m> one or two higher than the one chosen by default (which can be viewed thanks to the function C<intnumstep>), or to increase the abcissa of integration C<F<sigma>>. For example: ? \p 105 ? intlaplaceinv(x=2, 1, 1/x) - 1 time = 350 ms. %1 = 7.37... E-55 + 1.72... E-54*I \\ not so good ? m = intnumstep() %2 = 7 ? intlaplaceinv(x=2, 1, 1/x, m+1) - 1 time = 700 ms. %3 = 3.95... E-97 + 4.76... E-98*I \\ better ? intlaplaceinv(x=2, 1, 1/x, m+2) - 1 time = 1400 ms. %4 = 0.E-105 + 0.E-106*I \\ perfect but slow. ? intlaplaceinv(x=5, 1, 1/x) - 1 time = 340 ms. %5 = -5.98... E-85 + 8.08... E-85*I \\ better than %1 ? intlaplaceinv(x=5, 1, 1/x, m+1) - 1 time = 680 ms. %6 = -1.09... E-106 + 0.E-104*I \\ perfect, fast. ? intlaplaceinv(x=10, 1, 1/x) - 1 time = 340 ms. %7 = -4.36... E-106 + 0.E-102*I \\ perfect, fastest, but why sig = 10? ? intlaplaceinv(x=100, 1, 1/x) - 1 time = 330 ms. %7 = 1.07... E-72 + 3.2... E-72*I \\ too far now... X<intlaplaceinv>The library syntax is B<intlaplaceinv>C<(void *E, GEN (*eval)(GEN,void*), GEN sig,GEN z, GEN tab, long prec)>. =head2 X<intmellininv>intmellininvC<(X = sig,z,I<expr>,{I<tab>})> numerical integration of C<I<expr>(X)z^{-X}> with respect to C<X> on the line C< F<Re> (X) = sig>, divided by C<2iF<Pi>>, in other words, inverse Mellin transform of the function corresponding to I<expr> at the value C<z>. C<sig> is coded as follows. Either it is a real number C<F<sigma>>, equal to the abcissa of integration, and then the function to be integrated is assumed to decrease exponentially fast, of the order of C< F<exp> (-t)> when the imaginary part of the variable tends to C<F<+-> oo >. Or it is a two component vector C<[F<sigma>,F<alpha>]>, where C<F<sigma>> is as before, and either C<F<alpha> = 0> for slowly decreasing functions, or C<F<alpha> E<gt> 0> for functions decreasing like C< F<exp> (-F<alpha> t)>, such as gamma products. Note that it is not necessary to choose the exact value of C<F<alpha>>, and that C<F<alpha> = 1> (equivalent to C<sig> alone) is usually sufficient. I<tab> is as in C<intnum>. As all similar functions, this function is provided for the convenience of the user, who could use C<intnum> directly. However it is in general better to use C<intmellininvshort>. ? \p 105 ? intmellininv(s=2,4, gamma(s)^3); time = 1,190 ms. \\ reasonable. ? \p 308 ? intmellininv(s=2,4, gamma(s)^3); time = 51,300 ms. \\ slow because of Gamma(s)^3. X<intmellininv>The library syntax is B<intmellininv>C<(void *E, GEN (*eval)(GEN,void*), GEN sig, GEN z, GEN tab, long prec)>. =head2 X<intmellininvshort>intmellininvshortC<(sig,z,tab)> numerical integration of C<s(X)z^{-X}> with respect to C<X> on the line C< F<Re> (X) = sig>, divided by C<2iF<Pi>>, in other words, inverse Mellin transform of C<s(X)> at the value C<z>. Here C<s(X)> is implicitly contained in I<tab> in C<intfuncinit> format, typically tab = intfuncinit(T = [-1], [1], s(sig + I*T)) or similar commands. Take the example of the inverse Mellin transform of C<F<Gamma>(s)^3> given in C<intmellininv>: ? \p 105 ? oo = [1]; \\ for clarity ? A = intmellininv(s=2,4, gamma(s)^3); time = 2,500 ms. \\ not too fast because of Gamma(s)^3. \\ function of real type, decreasing as exp(-3Pi/2.|t|) ? tab = intfuncinit(t=[-oo, 3*Pi/2],[oo, 3*Pi/2], gamma(2+I*t)^3, 1); time = 1,370 ms. ? intmellininvshort(2,4, tab) - A time = 50 ms. %4 = -1.26... - 3.25...E-109*I \\ 50 times faster than A and perfect. ? tab2 = intfuncinit(t=-oo, oo, gamma(2+I*t)^3, 1); ? intmellininvshort(2,4, tab2) %6 = -1.2...E-42 - 3.2...E-109*I \\ 63 digits lost In the computation of I<tab>, it was not essential to include the \emph{exact} exponential decrease of C<F<Gamma>(2+it)^3>. But as the last example shows, a rough indication \emph{must} be given, otherwise slow decrease is assumed, resulting in catastrophic loss of accuracy. X<intmellininvshort>The library syntax is B<intmellininvshort>C<(GEN sig, GEN z, GEN tab, long prec)>. =head2 X<intnum>intnumC<(X = a,b,I<expr>,{I<tab>})> numerical integration of I<expr> on C<[a,b]> (possibly infinite interval) with respect to C<X>, where C<a> and C<b> are coded as explained below. The integrand may have values belonging to a vector space over the real numbers; in particular, it can be complex-valued or vector-valued. If I<tab> is omitted, necessary integration tables are computed using C<intnuminit> according to the current precision. It may be a positive integer C<m>, and tables are computed assuming the integration step is C<1/2^m>. Finally I<tab> can be a table output by C<intnuminit>, in which case it is used directly. This is important if several integrations of the same type are performed (on the same kind of interval and functions, and the same accuracy), since it saves expensive precomputations. If I<tab> is omitted the algorithm guesses a reasonable value for C<m> depending on the current precision. That value may be obtained as intnumstep() However this value may be off from the optimal one, and this is important since the integration time is roughly proportional to C<2^m>. One may try consecutive values of C<m> until they give the same value up to an accepted error. The endpoints C<a> and C<b> are coded as follows. If C<a> is not at C<F<+-> oo >, it is either coded as a scalar (real or complex), or as a two component vector C<[a,F<alpha>]>, where the function is assumed to have a singularity of the form C<(x-a)^{F<alpha>+\epsilon}> at C<a>, where C<\epsilon> indicates that powers of logarithms are neglected. In particular, C<[a,F<alpha>]> with C<F<alpha> E<gt>= 0> is equivalent to C<a>. If a wrong singularity exponent is used, the result will lose a catastrophic number of decimals, for instance approximately half the number of digits will be correct if C<F<alpha> = -1/2> is omitted. The endpoints of integration can be C<F<+-> oo >, which is coded as C<[F<+-> 1]> or as C<[[F<+->1],F<alpha>]>. Here C<F<alpha>> codes the behaviour of the function at C<F<+-> oo > as follows. \item C<F<alpha> = 0> (or no C<F<alpha>> at all, i.e. simply C<[F<+->1]>) assumes that the function to be integrated tends to zero, but not exponentially fast, and not oscillating such as C< F<sin> (x)/x>. \item C<F<alpha> E<gt> 0> assumes that the function tends to zero exponentially fast approximately as C< F<exp> (-F<alpha> x)>, including reasonably oscillating functions such as C< F<exp> (-x) F<sin> (x)>. The precise choice of C<F<alpha>>, while useful in extreme cases, is not critical, and may be off by a \emph{factor} of C<10> or more from the correct value. \item C<F<alpha> E<lt> -1> assumes that the function tends to C<0> slowly, like C<x^{F<alpha>}>. Here it is essential to give the correct C<F<alpha>>, if possible, but on the other hand C<F<alpha> E<lt>= -2> is equivalent to C<F<alpha> = 0>, in other words to no C<F<alpha>> at all. The last two codes are reserved for oscillating functions. Let C<k E<gt> 0> real, and C<g(x)> a nonoscillating function tending to C<0>, then \item C<F<alpha> = k I> assumes that the function behaves like C< F<cos> (kx)g(x)>. \item C<F<alpha> = -kI> assumes that the function behaves like C< F<sin> (kx)g(x)>. Here it is critical to give the exact value of C<k>. If the oscillating part is not a pure sine or cosine, one must expand it into a Fourier series, use the above codings, and sum the resulting contributions. Otherwise you will get nonsense. Note that C< F<cos> (kx)> (and similarly C< F<sin> (kx)>) means that very function, and not a translated version such as C< F<cos> (kx+a)>. If for instance C<f(x) = F<cos> (kx)g(x)> where C<g(x)> tends to zero exponentially fast as C< F<exp> (-F<alpha> x)>, it is up to the user to choose between C<[[F<+->1],F<alpha>]> and C<[[F<+->1],kI]>, but a good rule of thumb is that if the oscillations are much weaker than the exponential decrease, choose C<[[F<+->1],F<alpha>]>, otherwise choose C<[[F<+->1],kI]>, although the latter can reasonably be used in all cases, while the former cannot. To take a specific example, in the inverse Mellin transform, the function to be integrated is almost always exponentially decreasing times oscillating. If we choose the oscillating type of integral we perhaps obtain the best results, at the expense of having to recompute our functions for a different value of the variable C<z> giving the transform, preventing us to use a function such as C<intmellininvshort>. On the other hand using the exponential type of integral, we obtain less accurate results, but we skip expensive recomputations. See C<intmellininvshort> and C<intfuncinit> for more explanations. B<Note.> If you do not like the code C<[F<+->1]> for C<F<+-> oo >, you are welcome to set, e.g C<oo = [1]> or C<INFINITY = [1]>, then using C<+oo>, C<-oo>, C<-INFINITY>, etc. will have the expected behaviour. We shall now see many examples to get a feeling for what the various parameters achieve. All examples below assume precision is set to C<105> decimal digits. We first type ? \p 105 ? oo = [1] \\ for clarity B<Apparent singularities.> Even if the function C<f(x)> represented by I<expr> has no singularities, it may be important to define the function differently near special points. For instance, if C<f(x) = 1 /( F<exp> (x)-1) - F<exp> (-x)/x>, then C<F<int>_0^ oo f(x)dx = F<gamma>>, Euler's constant C<Euler>. But ? f(x) = 1/(exp(x)-1) - exp(-x)/x ? intnum(x = 0, [oo,1], f(x)) - Euler %1 = 6.00... E-67 thus only correct to C<76> decimal digits. This is because close to C<0> the function C<f> is computed with an enormous loss of accuracy. A better solution is ? f(x) = 1/(exp(x)-1)-exp(-x)/x ? F = truncate( f(t + O(t^7)) ); \\ expansion around t = 0 ? g(x) = if (x > 1e-18, f(x), subst(F,t,x)) \\ note that 6.18 > 105 ? intnum(x = 0, [oo,1], g(x)) - Euler %2 = 0.E-106 \\ perfect It is up to the user to determine constants such as the C<10^{-18}> and C<7> used above. B<True singularities.> With true singularities the result is much worse. For instance ? intnum(x = 0, 1, 1/sqrt(x)) - 2 %1 = -1.92... E-59 \\ only 59 correct decimals ? intnum(x = [0,-1/2], 1, 1/sqrt(x)) - 2 %2 = 0.E-105 \\ better B<Oscillating functions.> ? intnum(x = 0, oo, sin(x) / x) - Pi/2 %1 = 20.78.. \\ nonsense ? intnum(x = 0, [oo,1], sin(x)/x) - Pi/2 %2 = 0.004.. \\ bad ? intnum(x = 0, [oo,-I], sin(x)/x) - Pi/2 %3 = 0.E-105 \\ perfect ? intnum(x = 0, [oo,-I], sin(2*x)/x) - Pi/2 \\ oops, wrong k %4 = 0.07... ? intnum(x = 0, [oo,-2*I], sin(2*x)/x) - Pi/2 %5 = 0.E-105 \\ perfect ? intnum(x = 0, [oo,-I], sin(x)^3/x) - Pi/4 %6 = 0.0092... \\ bad ? sin(x)^3 - (3*sin(x)-sin(3*x))/4 %7 = O(x^17) We may use the above linearization and compute two oscillating integrals with ``infinite endpoints'' C<[oo, -I]> and C<[oo, -3*I]> respectively, or notice the obvious change of variable, and reduce to the single integral C<(1/2)F<int>_0^ oo F<sin> (x)/xdx>. We finish with some more complicated examples: ? intnum(x = 0, [oo,-I], (1-cos(x))/x^2) - Pi/2 %1 = -0.0004... \\ bad ? intnum(x = 0, 1, (1-cos(x))/x^2) \ + intnum(x = 1, oo, 1/x^2) - intnum(x = 1, [oo,I], cos(x)/x^2) - Pi/2 %2 = -2.18... E-106 \\ OK ? intnum(x = 0, [oo, 1], sin(x)^3*exp(-x)) - 0.3 %3 = 5.45... E-107 \\ OK ? intnum(x = 0, [oo,-I], sin(x)^3*exp(-x)) - 0.3 %4 = -1.33... E-89 \\ lost 16 decimals. Try higher m: ? m = intnumstep() %5 = 7 \\ the value of m actually used above. ? tab = intnuminit(0,[oo,-I], m+1); \\ try m one higher. ? intnum(x = 0, oo, sin(x)^3*exp(-x), tab) - 0.3 %6 = 5.45... E-107 \\ OK this time. B<Warning.> Like X<sumalt>C<sumalt>, C<intnum> often assigns a reasonable value to diverging integrals. Use these values at your own risk! For example: ? intnum(x = 0, [oo, -I], x^2*sin(x)) %1 = -2.0000000000... Note the formula S< >C< F<int>_0^ oo F<sin> (x)/x^sdx = F<cos> (F<Pi> s/2) F<Gamma>(1-s) , > a priori valid only for C<0 E<lt> F<Re> (s) E<lt> 2>, but the right hand side provides an analytic continuation which may be evaluated at C<s = -2>... B<Multivariate integration.> Using successive univariate integration with respect to different formal parameters, it is immediate to do naive multivariate integration. But it is important to use a suitable C<intnuminit> to precompute data for the \emph{internal} integrations at least! For example, to compute the double integral on the unit disc C<x^2+y^2 E<lt>= 1> of the function C<x^2+y^2>, we can write ? tab = intnuminit(-1,1); ? intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2, tab), tab) The first I<tab> is essential, the second optional. Compare: ? tab = intnuminit(-1,1); time = 30 ms. ? intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2)); time = 54,410 ms. \\ slow ? intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2, tab), tab); time = 7,210 ms. \\ faster However, the C<intnuminit> program is usually pessimistic when it comes to choosing the integration step C<2^{-m}>. It is often possible to improve the speed by trial and error. Continuing the above example: ? test(M) = { tab = intnuminit(-1,1, M); intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2,tab), tab) - Pi/2 } ? m = intnumstep() \\ what value of m did it take ? %1 = 7 ? test(m - 1) time = 1,790 ms. %2 = -2.05... E-104 \\ 4 = 2^2 times faster and still OK. ? test(m - 2) time = 430 ms. %3 = -1.11... E-104 \\ 16 = 2^4 times faster and still OK. ? test(m - 3) time = 120 ms. %3 = -7.23... E-60 \\ 64 = 2^6 times faster, lost 45 decimals. X<intnum>The library syntax is B<intnum>C<(void *E, GEN (*eval)(GEN,void*), GEN a,GEN b,GEN tab, long prec)>, where an omitted I<tab> is coded as C<NULL>. =head2 X<intnuminit>intnuminitC<(a,b,{m = 0})> initialize tables for integration from C<a> to C<b>, where C<a> and C<b> are coded as in C<intnum>. Only the compactness, the possible existence of singularities, the speed of decrease or the oscillations at infinity are taken into account, and not the values. For instance C<intnuminit(-1,1)> is equivalent to C<intnuminit(0,Pi)>, and C<intnuminit([0,-1/2],[1])> is equivalent to C< intnuminit([-1],[-1,-1/2])>. If C<m> is not given, it is computed according to the current precision. Otherwise the integration step is C<1/2^m>. Reasonable values of C<m> are C<m = 6> or C<m = 7> for C<100> decimal digits, and C<m = 9> for C<1000> decimal digits. The result is technical, but in some cases it is useful to know the output. Let C<x = F<phi>(t)> be the change of variable which is used. I<tab>[1] contains the integer C<m> as above, either given by the user or computed from the default precision, and can be recomputed directly using the function C<intnumstep>. I<tab>[2] and I<tab>[3] contain respectively the abcissa and weight corresponding to C<t = 0> (C<F<phi>(0)> and C<F<phi>'(0)>). I<tab>[4] and I<tab>[5] contain the abcissas and weights corresponding to positive C<t = nh> for C<1 E<lt>= n E<lt>= N> and C<h = 1/2^m> (C<F<phi>(nh)> and C<F<phi>'(nh)>). Finally I<tab>[6] and I<tab>[7] contain either the abcissas and weights corresponding to negative C<t = nh> for C<-N E<lt>= n E<lt>= -1>, or may be empty (but not always) if C<F<phi>(t)> is an odd function (implicitly we would have C<I<tab>[6] = -I<tab>[4]> and C<I<tab>[7] = I<tab>[5]>). X<intnuminit>The library syntax is B<intnuminit>C<(GEN a, GEN b, long m, long prec)>. =head2 X<intnumromb>intnumrombC<(X = a,b,I<expr>,{I<flag> = 0})> numerical integration of I<expr> (smooth in C<]a,b[>), with respect to C<X>. This function is deprecated, use X<intnum>C<intnum> instead. Set C<I<flag> = 0> (or omit it altogether) when C<a> and C<b> are not too large, the function is smooth, and can be evaluated exactly everywhere on the interval C<[a,b]>. If C<I<flag> = 1>, uses a general driver routine for doing numerical integration, making no particular assumption (slow). C<I<flag> = 2> is tailored for being used when C<a> or C<b> are infinite. One \emph{must} have C<ab E<gt> 0>, and in fact if for example C<b = + oo >, then it is preferable to have C<a> as large as possible, at least C<a E<gt>= 1>. If C<I<flag> = 3>, the function is allowed to be undefined (but continuous) at C<a> or C<b>, for example the function C< F<sin> (x)/x> at C<x = 0>. The user should not require too much accuracy: 18 or 28 decimal digits is OK, but not much more. In addition, analytical cleanup of the integral must have been done: there must be no singularities in the interval or at the boundaries. In practice this can be accomplished with a simple change of variable. Furthermore, for improper integrals, where one or both of the limits of integration are plus or minus infinity, the function must decrease sufficiently rapidly at infinity. This can often be accomplished through integration by parts. Finally, the function to be integrated should not be very small (compared to the current precision) on the entire interval. This can of course be accomplished by just multiplying by an appropriate constant. Note that X<infinity>infinity can be represented with essentially no loss of accuracy by 1e1000. However beware of real underflow when dealing with rapidly decreasing functions. For example, if one wants to compute the C<F<int>_0^ oo e^{-x^2}dx> to 28 decimal digits, then one should set infinity equal to 10 for example, and certainly not to 1e1000. X<intnumromb>The library syntax is B<intnumromb>C<(void *E, GEN (*eval)(GEN,void*), GEN a, GEN b, long flag, long prec)>, where C<eval(x, E)> returns the value of the function at C<x>. You may store any additional information required by C<eval> in C<E>, or set it to C<NULL>. =head2 X<intnumstep>intnumstepC<()> give the value of C<m> used in all the C<intnum> and C<sumnum> programs, hence such that the integration step is equal to C<1/2^m>. X<intnumstep>The library syntax is B<intnumstep>C<(long prec)>. =head2 X<prod>prodC<(X = a,b,I<expr>,{x = 1})> product of expression I<expr>, initialized at C<x>, the formal parameter C<X> going from C<a> to C<b>. As for C<sum>, the main purpose of the initialization parameter C<x> is to force the type of the operations being performed. For example if it is set equal to the integer 1, operations will start being done exactly. If it is set equal to the real C<1.>, they will be done using real numbers having the default precision. If it is set equal to the power series C<1+O(X^k)> for a certain C<k>, they will be done using power series of precision at most C<k>. These are the three most common initializations. As an extreme example, compare ? prod(i=1, 100, 1 - X^i); \\ this has degree 5050 !! time = 3,335 ms. ? prod(i=1, 100, 1 - X^i, 1 + O(X^101)) time = 43 ms. %2 = 1 - X - X^2 + X^5 + X^7 - X^12 - X^15 + X^22 + X^26 - X^35 - X^40 + \ X^51 + X^57 - X^70 - X^77 + X^92 + X^100 + O(X^101) X<produit>The library syntax is B<produit>C<(entree *ep, GEN a, GEN b, char *expr, GEN x)>. =head2 X<prodeuler>prodeulerC<(X = a,b,I<expr>)> product of expression I<expr>, initialized at 1. (i.e.S< >to a \emph{real} number equal to 1 to the current C<realprecision>), the formal parameter C<X> ranging over the prime numbers between C<a> and C<b>.X<Euler product> X<prodeuler>The library syntax is B<prodeuler>C<(void *E, GEN (*eval)(GEN,void*), GEN a,GEN b, long prec)>. =head2 X<prodinf>prodinfC<(X = a,I<expr>,{I<flag> = 0})> X<infinite product>infinite product of expression I<expr>, the formal parameter C<X> starting at C<a>. The evaluation stops when the relative error of the expression minus 1 is less than the default precision. The expressions must always evaluate to an element of B<I<C>>. If C<I<flag> = 1>, do the product of the (C<1+I<expr>>) instead. X<prodinf>The library syntax is B<prodinf>C<(void *E, GEN (*eval)(GEN, void*), GEN a, long prec)> (C<I<flag> = 0>), or X<prodinf1>B<prodinf1> with the same arguments (C<I<flag> = 1>). =head2 X<solve>solveC<(X = a,b,I<expr>)> find a real root of expression I<expr> between C<a> and C<b>, under the condition C<I<expr>(X = a) * I<expr>(X = b) E<lt>= 0>. This routine uses Brent's method and can fail miserably if I<expr> is not defined in the whole of C<[a,b]> (try C<solve(x = 1, 2, tan(x)>). X<zbrent>The library syntax is B<zbrent>C<(void *E,GEN (*eval)(GEN,void*),GEN a,GEN b,long prec)>. =head2 X<sum>sumC<(X = a,b,I<expr>,{x = 0})> sum of expression I<expr>, initialized at C<x>, the formal parameter going from C<a> to C<b>. As for C<prod>, the initialization parameter C<x> may be given to force the type of the operations being performed. As an extreme example, compare ? sum(i=1, 5000, 1/i); \\ rational number: denominator has 2166 digits. time = 1,241 ms. ? sum(i=1, 5000, 1/i, 0.) time = 158 ms. %2 = 9.094508852984436967261245533 X<somme>The library syntax is B<somme>C<(entree *ep, GEN a, GEN b, char *expr, GEN x)>. This is to be used as follows: C<ep> represents the dummy variable used in the expression C<expr> /* compute a^2 + ... + b^2 */ { /* define the dummy variable "i" */ entree *ep = is_entry("i"); /* sum for a <= i <= b */ return somme(ep, a, b, "i^2", gen_0); } =head2 X<sumalt>sumaltC<(X = a,I<expr>,{I<flag> = 0})> numerical summation of the series I<expr>, which should be an X<alternating series>alternating series, the formal variable C<X> starting at C<a>. Use an algorithm of F.S< >Villegas as modified by D.S< >Zagier (improves on X<Euler>Euler-X<Van Wijngaarden>Van Wijngaarden method). If C<I<flag> = 1>, use a variant with slightly different polynomials. Sometimes faster. Divergent alternating series can sometimes be summed by this method, as well as series which are not exactly alternating (see for example L<Label se:user_defined>). If the series already converges geometrically, X<suminf>C<suminf> is often a better choice: ? \p28 ? sumalt(i = 1, -(-1)^i / i) - log(2) time = 0 ms. %1 = -2.524354897 E-29 ? suminf(i = 1, -(-1)^i / i) *** suminf: user interrupt after 10min, 20,100 ms. ? \p1000 ? sumalt(i = 1, -(-1)^i / i) - log(2) time = 90 ms. %2 = 4.459597722 E-1002 ? sumalt(i = 0, (-1)^i / i!) - exp(-1) time = 670 ms. %3 = -4.03698781490633483156497361352190615794353338591897830587 E-944 ? suminf(i = 0, (-1)^i / i!) - exp(-1) time = 110 ms. %4 = -8.39147638 E-1000 \\ faster and more accurate X<sumalt>The library syntax is B<sumalt>C<(void *E, GEN (*eval)(GEN,void*),GEN a,long prec)>. Also available is X<sumalt2>C<sumalt2> with the same arguments (C<I<flag> = 1>). =head2 X<sumdiv>sumdivC<(n,X,I<expr>)> sum of expression I<expr> over the positive divisors of C<n>. Arithmetic functions like X<sigma>C<sigma> use the multiplicativity of the underlying expression to speed up the computation. In the present version B<2.2.0>, there is no way to indicate that I<expr> is multiplicative in C<n>, hence specialized functions should be preferred whenever possible. X<divsum>The library syntax is B<divsum>C<(entree *ep, GEN num, char *expr)>. =head2 X<suminf>suminfC<(X = a,I<expr>)> X<infinite sum>infinite sum of expression I<expr>, the formal parameter C<X> starting at C<a>. The evaluation stops when the relative error of the expression is less than the default precision for 3 consecutive evaluations. The expressions must always evaluate to a complex number. If the series converges slowly, make sure C<realprecision> is low (even 28 digits may be too much). In this case, if the series is alternating or the terms have a constant sign, X<sumalt>C<sumalt> and X<sumpos>C<sumpos> should be used instead. ? \p28 ? suminf(i = 1, -(-1)^i / i) *** suminf: user interrupt after 10min, 20,100 ms. ? sumalt(i = 1, -(-1)^i / i) - log(2) time = 0 ms. %1 = -2.524354897 E-29 X<suminf>The library syntax is B<suminf>C<(void *E, GEN (*eval)(GEN,void*), GEN a, long prec)>. =head2 X<sumnum>sumnumC<(X = a,sig,I<expr>,{I<tab>}),{I<flag> = 0}> numerical summation of I<expr>, the variable C<X> taking integer values from ceiling of C<a> to C<+ oo >, where I<expr> is assumed to be a holomorphic function C<f(X)> for C< F<Re> (X) E<gt>= F<sigma>>. The parameter C<F<sigma> belongs to B<I<R>>> is coded in the argument C<sig> as follows: it is either \item a real number C<F<sigma>>. Then the function C<f> is assumed to decrease at least as C<1/X^2> at infinity, but not exponentially; \item a two-component vector C<[F<sigma>,F<alpha>]>, where C<F<sigma>> is as before, C<F<alpha> E<lt> -1>. The function C<f> is assumed to decrease like C<X^{F<alpha>}>. In particular, C<F<alpha> E<lt>= -2> is equivalent to no C<F<alpha>> at all. \item a two-component vector C<[F<sigma>,F<alpha>]>, where C<F<sigma>> is as before, C<F<alpha> E<gt> 0>. The function C<f> is assumed to decrease like C< F<exp> (-F<alpha> X)>. In this case it is essential that C<F<alpha>> be exactly the rate of exponential decrease, and it is usually a good idea to increase the default value of C<m> used for the integration step. In practice, if the function is exponentially decreasing C<sumnum> is slower and less accurate than C<sumpos> or C<suminf>, so should not be used. The function uses the X<intnum>C<intnum> routines and integration on the line C< F<Re> (s) = F<sigma>>. The optional argument I<tab> is as in intnum, except it must be initialized with C<sumnuminit> instead of C<intnuminit>. When I<tab> is not precomputed, C<sumnum> can be slower than C<sumpos>, when the latter is applicable. It is in general faster for slowly decreasing functions. Finally, if C<I<flag>> is nonzero, we assume that the function C<f> to be summed is of real type, i.e. satisfies C<\overline{f(z)} = f(\overline{z})>, which speeds up the computation. ? \p 308 ? a = sumpos(n=1, 1/(n^3+n+1)); time = 1,410 ms. ? tab = sumnuminit(2); time = 1,620 ms. \\ slower but done once and for all. ? b = sumnum(n=1, 2, 1/(n^3+n+1), tab); time = 460 ms. \\ 3 times as fast as sumpos ? a - b %4 = -1.0... E-306 + 0.E-320*I \\ perfect. ? sumnum(n=1, 2, 1/(n^3+n+1), tab, 1) - a; \\ function of real type time = 240 ms. %2 = -1.0... E-306 \\ twice as fast, no imaginary part. ? c = sumnum(n=1, 2, 1/(n^2+1), tab, 1); time = 170 ms. \\ fast ? d = sumpos(n=1, 1 / (n^2+1)); time = 2,700 ms. \\ slow. ? d - c time = 0 ms. %5 = 1.97... E-306 \\ perfect. For slowly decreasing function, we must indicate singularities: ? \p 308 ? a = sumnum(n=1, 2, n^(-4/3)); time = 9,930 ms. \\ slow because of the computation of n^{-4/3}. ? a - zeta(4/3) time = 110 ms. %1 = -2.42... E-107 \\ lost 200 decimals because of singularity at oo ? b = sumnum(n=1, [2,-4/3], n^(-4/3), /*omitted*/, 1); \\ of real type time = 12,210 ms. ? b - zeta(4/3) %3 = 1.05... E-300 \\ better Since the \emph{complex} values of the function are used, beware of determination problems. For instance: ? \p 308 ? tab = sumnuminit([2,-3/2]); time = 1,870 ms. ? sumnum(n=1,[2,-3/2], 1/(n*sqrt(n)), tab,1) - zeta(3/2) time = 690 ms. %1 = -1.19... E-305 \\ fast and correct ? sumnum(n=1,[2,-3/2], 1/sqrt(n^3), tab,1) - zeta(3/2) time = 730 ms. %2 = -1.55... \\ nonsense. However ? sumnum(n=1,[2,-3/2], 1/n^(3/2), tab,1) - zeta(3/2) time = 8,990 ms. %3 = -1.19... E-305 \\ perfect, as 1/(n*sqrt{n}) above but much slower For exponentially decreasing functions, C<sumnum> is given for completeness, but one of X<suminf>C<suminf> or X<sumpos>C<sumpos> should always be preferred. If you experiment with such functions and C<sumnum> anyway, indicate the exact rate of decrease and increase C<m> by C<1> or C<2>: ? suminf(n=1, 2^(-n)) - 1 time = 10 ms. %1 = -1.11... E-308 \\ fast and perfect ? sumpos(n=1, 2^(-n)) - 1 time = 10 ms. %2 = -2.78... E-308 \\ also fast and perfect ? sumnum(n=1,2, 2^(-n)) - 1 *** sumnum: precision too low in mpsc1 \\ nonsense ? sumnum(n=1, [2,log(2)], 2^(-n), /*omitted*/, 1) - 1 \\ of real type time = 5,860 ms. %3 = -1.5... E-236 \\ slow and lost 70 decimals ? m = intnumstep() %4 = 9 ? sumnum(n=1,[2,log(2)], 2^(-n), m+1, 1) - 1 time = 11,770 ms. %5 = -1.9... E-305 \\ now perfect, but slow. X<sumnum>The library syntax is B<sumnum>C<(void *E, GEN (*eval)(GEN,void*), GEN a,GEN sig,GEN tab,long flag, long prec)>. =head2 X<sumnumalt>sumnumaltC<(X = a,sig,I<expr>,{I<tab>},{I<flag> = 0})> numerical summation of C<(-1)^XI<expr>(X)>, the variable C<X> taking integer values from ceiling of C<a> to C<+ oo >, where I<expr> is assumed to be a holomorphic function for C< F<Re> (X) E<gt>= sig> (or C<sig[1]>). B<Warning.> This function uses the C<intnum> routines and is orders of magnitude slower than C<sumalt>. It is only given for completeness and should not be used in practice. B<Warning2.> The expression I<expr> must \emph{not} include the C<(-1)^X> coefficient. Thus C<sumalt(n = a,(-1)^nf(n))> is (approximately) equal to C<sumnumalt(n = a,sig,f(n))>. C<sig> is coded as in C<sumnum>. However for slowly decreasing functions (where C<sig> is coded as C<[F<sigma>,F<alpha>]> with C<F<alpha> E<lt> -1>), it is not really important to indicate C<F<alpha>>. In fact, as for C<sumalt>, the program will often give meaningful results (usually analytic continuations) even for divergent series. On the other hand the exponential decrease must be indicated. I<tab> is as in C<intnum>, but if used must be initialized with C<sumnuminit>. If C<I<flag>> is nonzero, assumes that the function C<f> to be summed is of real type, i.e. satisfies C<\overline{f(z)} = f(\overline{z})>, and then twice faster when I<tab> is precomputed. ? \p 308 ? tab = sumnuminit(2, /*omitted*/, -1); \\ abcissa sigma = 2, alternating sums. time = 1,620 ms. \\ slow, but done once and for all. ? a = sumnumalt(n=1, 2, 1/(n^3+n+1), tab, 1); time = 230 ms. \\ similar speed to sumnum ? b = sumalt(n=1, (-1)^n/(n^3+n+1)); time = 0 ms. \\ infinitely faster! ? a - b time = 0 ms. %1 = -1.66... E-308 \\ perfect X<sumnumalt>The library syntax is B<sumnumalt>C<(void *E, GEN (*eval)(GEN,void*), GEN a, GEN sig, GEN tab, long flag, long prec)>. =head2 X<sumnuminit>sumnuminitC<(sig,{m = 0},{sgn = 1})> initialize tables for numerical summation using C<sumnum> (with C<I<sgn> = 1>) or C<sumnumalt> (with C<I<sgn> = -1>), C<sig> is the abcissa of integration coded as in C<sumnum>, and C<m> is as in C<intnuminit>. X<sumnuminit>The library syntax is B<sumnuminit>C<(GEN sig, long m, long sgn, long prec)>. =head2 X<sumpos>sumposC<(X = a,I<expr>,{I<flag> = 0})> numerical summation of the series I<expr>, which must be a series of terms having the same sign, the formal variable C<X> starting at C<a>. The algorithm used is Van Wijngaarden's trick for converting such a series into an alternating one, and is quite slow. For regular functions, the function C<sumnum> is in general much faster once the initializations have been made using C<sumnuminit>. If C<I<flag> = 1>, use slightly different polynomials. Sometimes faster. X<sumpos>The library syntax is B<sumpos>C<(void *E, GEN (*eval)(GEN,void*),GEN a,long prec)>. Also available is X<sumpos2>C<sumpos2> with the same arguments (C<I<flag> = 1>). =head1 Plotting functions Although plotting is not even a side purpose of PARI, a number of plotting functions are provided. Moreover, a lot of people suggested ideas or submitted patches for this section of the code. Among these, special thanks go to Klaus-Peter Nischke who suggested the recursive plotting and the forking/resizing stuff under X11, and Ilya Zakharevich who undertook a complete rewrite of the graphic code, so that most of it is now platform-independent and should be easy to port or expand. There are three types of graphic functions. =head2 High-level plotting functions (all the functions starting with C<ploth>) in which the user has little to do but explain what type of plot he wants, and whose syntax is similar to the one used in the preceding section. =head2 Low-level plotting functions (called I<rectplot> functions, sharing the prefix C<plot>), where every drawing primitive (point, line, box, etc.) is specified by the user. These low-level functions work as follows. You have at your disposal 16 virtual windows which are filled independently, and can then be physically ORed on a single window at user-defined positions. These windows are numbered from 0 to 15, and must be initialized before being used by the function C<plotinit>, which specifies the height and width of the virtual window (called a I<rectwindow> in the sequel). At all times, a virtual cursor (initialized at C<[0,0]>) is associated to the window, and its current value can be obtained using the function C<plotcursor>. A number of primitive graphic objects (called I<rect> objects) can then be drawn in these windows, using a default color associated to that window (which can be changed under X11, using the C<plotcolor> function, black otherwise) and only the part of the object which is inside the window will be drawn, with the exception of polygons and strings which are drawn entirely. The ones sharing the prefix C<plotr> draw relatively to the current position of the virtual cursor, the others use absolute coordinates. Those having the prefix C<plotrecth> put in the rectwindow a large batch of rect objects corresponding to the output of the related C<ploth> function. Finally, the actual physical drawing is done using the function C<plotdraw>. The rectwindows are preserved so that further drawings using the same windows at different positions or different windows can be done without extra work. To erase a window (and free the corresponding memory), use the function C<plotkill>. It is not possible to partially erase a window. Erase it completely, initialize it again and then fill it with the graphic objects that you want to keep. In addition to initializing the window, you may use a scaled window to avoid unnecessary conversions. For this, use the function C<plotscale> below. As long as this function is not called, the scaling is simply the number of pixels, the origin being at the upper left and the C<y>-coordinates going downwards. Note that in the present version B<2.2.0> all plotting functions (both low and high level) are written for the X11-window system (hence also for GUI's based on X11 such as Openwindows and Motif) only, though little code remains which is actually platform-dependent. It is also possible to compile C<gp> with either of the Qt or FLTK graphical libraries. A Suntools/Sunview, Macintosh, and an Atari/Gem port were provided for previous versions, but are now obsolete. Under X11, the physical window (opened by C<plotdraw> or any of the C<ploth*> functions) is completely separated from C<gp> (technically, a C<fork> is done, and the non-graphical memory is immediately freed in the child process), which means you can go on working in the current C<gp> session, without having to kill the window first. Under X11, this window can be closed, enlarged or reduced using the standard window manager functions. No zooming procedure is implemented though (yet). =head2 Functions for PostScript output: in the same way that C<printtex> allows you to have a TeX output corresponding to printed results, the functions starting with C<ps> allow you to have X<PostScript>C<PostScript> output of the plots. This will not be absolutely identical with the screen output, but will be sufficiently close. Note that you can use PostScript output even if you do not have the plotting routines enabled. The PostScript output is written in a file whose name is derived from the X<psfile>C<psfile> default (C<./pari.ps> if you did not tamper with it). Each time a new PostScript output is asked for, the PostScript output is appended to that file. Hence you probably want to remove this file, or change the value of C<psfile>, in between plots. On the other hand, in this manner, as many plots as desired can be kept in a single file. =head2 And library mode ? \emph{None of the graphic functions are available within the PARI library, you must be under C<gp> to use them}. The reason for that is that you really should not use PARI for heavy-duty graphical work, there are better specialized alternatives around. This whole set of routines was only meant as a convenient, but simple-minded, visual aid. If you really insist on using these in your program (we warned you), the source (C<plot*.c>) should be readable enough for you to achieve something. =head2 X<plot>plotC<(X = a,b,I<expr>,{I<Ymin>},{I<Ymax>})> crude ASCII plot of the function represented by expression I<expr> from C<a> to C<b>, with I<Y> ranging from I<Ymin> to I<Ymax>. If I<Ymin> (resp. I<Ymax>) is not given, the minima (resp. the maxima) of the computed values of the expression is used instead. =head2 X<plotbox>plotboxC<(w,x2,y2)> let C<(x1,y1)> be the current position of the virtual cursor. Draw in the rectwindow C<w> the outline of the rectangle which is such that the points C<(x1,y1)> and C<(x2,y2)> are opposite corners. Only the part of the rectangle which is in C<w> is drawn. The virtual cursor does \emph{not} move. =head2 X<plotclip>plotclipC<(w)> `clips' the content of rectwindow C<w>, i.e remove all parts of the drawing that would not be visible on the screen. Together with X<plotcopy>C<plotcopy> this function enables you to draw on a scratchpad before commiting the part you're interested in to the final picture. =head2 X<plotcolor>plotcolorC<(w,c)> set default color to C<c> in rectwindow C<w>. In present version B<2.2.0>, this is only implemented for the X11 window system, and you only have the following palette to choose from: 1 = black, 2 = blue, 3 = sienna, 4 = red, 5 = green, 6 = grey, 7 = gainsborough. Note that it should be fairly easy for you to hardwire some more colors by tweaking the files C<rect.h> and C<plotX.c>. User-defined colormaps would be nice, and \emph{may} be available in future versions. =head2 X<plotcopy>plotcopyC<(w1,w2,dx,dy)> copy the contents of rectwindow C<w1> to rectwindow C<w2>, with offset C<(dx,dy)>. =head2 X<plotcursor>plotcursorC<(w)> give as a 2-component vector the current (scaled) position of the virtual cursor corresponding to the rectwindow C<w>. =head2 X<plotdraw>plotdrawC<(list)> physically draw the rectwindows given in C<list> which must be a vector whose number of components is divisible by 3. If C<list = [w1,x1,y1,w2,x2,y2,...]>, the windows C<w1>, C<w2>, etc.S< >are physically placed with their upper left corner at physical position C<(x1,y1)>, C<(x2,y2)>,...respectively, and are then drawn together. Overlapping regions will thus be drawn twice, and the windows are considered transparent. Then display the whole drawing in a special window on your screen. =head2 X<ploth>plothC<(X = a,b,I<expr>,{I<flag> = 0},{n = 0})> high precision plot of the function C<y = f(x)> represented by the expression I<expr>, C<x> going from C<a> to C<b>. This opens a specific window (which is killed whenever you click on it), and returns a four-component vector giving the coordinates of the bounding box in the form C<[I<xmin>,I<xmax>,I<ymin>,I<ymax>]>. B<Important note>: Since this may involve a lot of function calls, it is advised to keep the current precision to a minimum (e.g.S< >9) before calling this function. C<n> specifies the number of reference point on the graph (0 means use the hardwired default values, that is: 1000 for general plot, 1500 for parametric plot, and 15 for recursive plot). If no C<I<flag>> is given, I<expr> is either a scalar expression C<f(X)>, in which case the plane curve C<y = f(X)> will be drawn, or a vector C<[f_1(X),...,f_k(X)]>, and then all the curves C<y = f_i(X)> will be drawn in the same window. The binary digits of C<I<flag>> mean: \item C<1 = Parametric>: X<parametric plot>I<parametric plot>. Here I<expr> must be a vector with an even number of components. Successive pairs are then understood as the parametric coordinates of a plane curve. Each of these are then drawn. For instance: C<ploth(X = 0,2*Pi,[sin(X),cos(X)],1)> will draw a circle. C<ploth(X = 0,2*Pi,[sin(X),cos(X)])> will draw two entwined sinusoidal curves. C<ploth(X = 0,2*Pi,[X,X,sin(X),cos(X)],1)> will draw a circle and the line C<y = x>. \item C<2 = Recursive>: X<recursive plot>I<recursive plot>. If this flag is set, only \emph{one} curve can be drawn at a time, i.e.S< >I<expr> must be either a two-component vector (for a single parametric curve, and the parametric flag \emph{has} to be set), or a scalar function. The idea is to choose pairs of successive reference points, and if their middle point is not too far away from the segment joining them, draw this as a local approximation to the curve. Otherwise, add the middle point to the reference points. This is fast, and usually more precise than usual plot. Compare the results of S< >C<ploth(X = -1,1,sin(1/X),2) and ploth(X = -1,1,sin(1/X))> for instance. But beware that if you are extremely unlucky, or choose too few reference points, you may draw some nice polygon bearing little resemblance to the original curve. For instance you should \emph{never} plot recursively an odd function in a symmetric interval around 0. Try ploth(x = -20, 20, sin(x), 2) to see why. Hence, it's usually a good idea to try and plot the same curve with slightly different parameters. The other values toggle various display options: \item C<4 = no_Rescale>: do not rescale plot according to the computed extrema. This is meant to be used when graphing multiple functions on a rectwindow (as a X<plotrecth>C<plotrecth> call), in conjunction with X<plotscale>C<plotscale>. \item C<8 = no_X_axis>: do not print the C<x>-axis. \item C<16 = no_Y_axis>: do not print the C<y>-axis. \item C<32 = no_Frame>: do not print frame. \item C<64 = no_Lines>: only plot reference points, do not join them. \item C<128 = Points_too>: plot both lines and points. \item C<256 = Splines>: use splines to interpolate the points. \item C<512 = no_X_ticks>: plot no C<x>-ticks. \item C<1024 = no_Y_ticks>: plot no C<y>-ticks. \item C<2048 = Same_ticks>: plot all ticks with the same length. =head2 X<plothraw>plothrawC<(I<listx>,I<listy>,{I<flag> = 0})> given I<listx> and I<listy> two vectors of equal length, plots (in high precision) the points whose C<(x,y)>-coordinates are given in I<listx> and I<listy>. Automatic positioning and scaling is done, but with the same scaling factor on C<x> and C<y>. If C<I<flag>> is 1, join points, other non-0 flags toggle display options and should be combinations of bits C<2^k>, C<k E<gt>= 3> as in C<ploth>. =head2 X<plothsizes>plothsizesC<()> return data corresponding to the output window in the form of a 6-component vector: window width and height, sizes for ticks in horizontal and vertical directions (this is intended for the C<gnuplot> interface and is currently not significant), width and height of characters. =head2 X<plotinit>plotinitC<(w,x,y,{I<flag>})> initialize the rectwindow C<w>, destroying any rect objects you may have already drawn in C<w>. The virtual cursor is set to C<(0,0)>. The rectwindow size is set to width C<x> and height C<y>. If C<I<flag> = 0>, C<x> and C<y> represent pixel units. Otherwise, C<x> and C<y> are understood as fractions of the size of the current output device (hence must be between C<0> and C<1>) and internally converted to pixels. The plotting device imposes an upper bound for C<x> and C<y>, for instance the number of pixels for screen output. These bounds are available through the X<plothsizes>C<plothsizes> function. The following sequence initializes in a portable way (i.e independent of the output device) a window of maximal size, accessed through coordinates in the C<[0,1000] x [0,1000]> range: s = plothsizes(); plotinit(0, s[1]-1, s[2]-1); plotscale(0, 0,1000, 0,1000); =head2 X<plotkill>plotkillC<(w)> erase rectwindow C<w> and free the corresponding memory. Note that if you want to use the rectwindow C<w> again, you have to use C<plotinit> first to specify the new size. So it's better in this case to use C<plotinit> directly as this throws away any previous work in the given rectwindow. =head2 X<plotlines>plotlinesC<(w,X,Y,{I<flag> = 0})> draw on the rectwindow C<w> the polygon such that the (x,y)-coordinates of the vertices are in the vectors of equal length C<X> and C<Y>. For simplicity, the whole polygon is drawn, not only the part of the polygon which is inside the rectwindow. If C<I<flag>> is non-zero, close the polygon. In any case, the virtual cursor does not move. C<X> and C<Y> are allowed to be scalars (in this case, both have to). There, a single segment will be drawn, between the virtual cursor current position and the point C<(X,Y)>. And only the part thereof which actually lies within the boundary of C<w>. Then \emph{move} the virtual cursor to C<(X,Y)>, even if it is outside the window. If you want to draw a line from C<(x1,y1)> to C<(x2,y2)> where C<(x1,y1)> is not necessarily the position of the virtual cursor, use C<plotmove(w,x1,y1)> before using this function. =head2 X<plotlinetype>plotlinetypeC<(w,I<type>)> change the type of lines subsequently plotted in rectwindow C<w>. I<type> C<-2> corresponds to frames, C<-1> to axes, larger values may correspond to something else. C<w = -1> changes highlevel plotting. This is only taken into account by the C<gnuplot> interface. =head2 X<plotmove>plotmoveC<(w,x,y)> move the virtual cursor of the rectwindow C<w> to position C<(x,y)>. =head2 X<plotpoints>plotpointsC<(w,X,Y)> draw on the rectwindow C<w> the points whose C<(x,y)>-coordinates are in the vectors of equal length C<X> and C<Y> and which are inside C<w>. The virtual cursor does \emph{not} move. This is basically the same function as C<plothraw>, but either with no scaling factor or with a scale chosen using the function C<plotscale>. As was the case with the C<plotlines> function, C<X> and C<Y> are allowed to be (simultaneously) scalar. In this case, draw the single point C<(X,Y)> on the rectwindow C<w> (if it is actually inside C<w>), and in any case \emph{move} the virtual cursor to position C<(x,y)>. =head2 X<plotpointsize>plotpointsizeC<(w,size)> changes the ``size'' of following points in rectwindow C<w>. If C<w = -1>, change it in all rectwindows. This only works in the C<gnuplot> interface. =head2 X<plotpointtype>plotpointtypeC<(w,I<type>)> change the type of points subsequently plotted in rectwindow C<w>. C<I<type> = -1> corresponds to a dot, larger values may correspond to something else. C<w = -1> changes highlevel plotting. This is only taken into account by the C<gnuplot> interface. =head2 X<plotrbox>plotrboxC<(w,dx,dy)> draw in the rectwindow C<w> the outline of the rectangle which is such that the points C<(x1,y1)> and C<(x1+dx,y1+dy)> are opposite corners, where C<(x1,y1)> is the current position of the cursor. Only the part of the rectangle which is in C<w> is drawn. The virtual cursor does \emph{not} move. =head2 X<plotrecth>plotrecthC<(w,X = a,b,I<expr>,{I<flag> = 0},{n = 0})> writes to rectwindow C<w> the curve output of C<ploth>C<(w,X = a,b,I<expr>,I<flag>,n)>. =head2 X<plotrecthraw>plotrecthrawC<(w,I<data>,{I<flag> = 0})> plot graph(s) for I<data> in rectwindow C<w>. C<I<flag>> has the same significance here as in C<ploth>, though recursive plot is no more significant. I<data> is a vector of vectors, each corresponding to a list a coordinates. If parametric plot is set, there must be an even number of vectors, each successive pair corresponding to a curve. Otherwise, the first one contains the C<x> coordinates, and the other ones contain the C<y>-coordinates of curves to plot. =head2 X<plotrline>plotrlineC<(w,dx,dy)> draw in the rectwindow C<w> the part of the segment C<(x1,y1)-(x1+dx,y1+dy)> which is inside C<w>, where C<(x1,y1)> is the current position of the virtual cursor, and move the virtual cursor to C<(x1+dx,y1+dy)> (even if it is outside the window). =head2 X<plotrmove>plotrmoveC<(w,dx,dy)> move the virtual cursor of the rectwindow C<w> to position C<(x1+dx,y1+dy)>, where C<(x1,y1)> is the initial position of the cursor (i.e.S< >to position C<(dx,dy)> relative to the initial cursor). =head2 X<plotrpoint>plotrpointC<(w,dx,dy)> draw the point C<(x1+dx,y1+dy)> on the rectwindow C<w> (if it is inside C<w>), where C<(x1,y1)> is the current position of the cursor, and in any case move the virtual cursor to position C<(x1+dx,y1+dy)>. =head2 X<plotscale>plotscaleC<(w,x1,x2,y1,y2)> scale the local coordinates of the rectwindow C<w> so that C<x> goes from C<x1> to C<x2> and C<y> goes from C<y1> to C<y2> (C<x2 E<lt> x1> and C<y2 E<lt> y1> being allowed). Initially, after the initialization of the rectwindow C<w> using the function C<plotinit>, the default scaling is the graphic pixel count, and in particular the C<y> axis is oriented downwards since the origin is at the upper left. The function C<plotscale> allows to change all these defaults and should be used whenever functions are graphed. =head2 X<plotstring>plotstringC<(w,x,{I<flag> = 0})> draw on the rectwindow C<w> the String C<x> (see L<Label se:strings>), at the current position of the cursor. I<flag> is used for justification: bits 1 and 2 regulate horizontal alignment: left if 0, right if 2, center if 1. Bits 4 and 8 regulate vertical alignment: bottom if 0, top if 8, v-center if 4. Can insert additional small gap between point and string: horizontal if bit 16 is set, vertical if bit 32 is set (see the tutorial for an example). =head2 X<psdraw>psdrawC<(I<list>)> same as C<plotdraw>, except that the output is a PostScript program appended to the C<psfile>. =head2 X<psploth>psplothC<(X = a,b,I<expr>)> same as C<ploth>, except that the output is a PostScript program appended to the C<psfile>. =head2 X<psplothraw>psplothrawC<(I<listx>,I<listy>)> same as C<plothraw>, except that the output is a PostScript program appended to the C<psfile>. =head1 Programming in GP X<programming>X<Label se:programming> =head2 Control statements. A number of control statements are available in GP. They are simpler and have a syntax slightly different from their C counterparts, but are quite powerful enough to write any kind of program. Some of them are specific to GP, since they are made for number theorists. As usual, C<X> will denote any simple variable name, and I<seq> will always denote a sequence of expressions, including the empty sequence. B<Caveat:> in constructs like for (X = a,b, seq) the variable C<X> is considered local to the loop, leading to possibly unexpected behaviour: n = 5; for (n = 1, 10, if (something_nice(), break); ); \\ at this point n is 5 ! If the sequence C<seq> modifies the loop index, then the loop is modified accordingly: ? for (n = 1, 10, n += 2; print(n)) 3 6 9 12 =item X<break>breakC<({n = 1})> interrupts execution of current I<seq>, and immediately exits from the C<n> innermost enclosing loops, within the current function call (or the top level loop). C<n> must be bigger than 1. If C<n> is greater than the number of enclosing loops, all enclosing loops are exited. =item X<for>forC<(X = a,b,I<seq>)> evaluates I<seq>, where the formal variable C<X> goes from C<a> to C<b>. Nothing is done if C<a E<gt> b>. C<a> and C<b> must be in B<I<R>>. =item X<fordiv>fordivC<(n,X,I<seq>)> evaluates I<seq>, where the formal variable C<X> ranges through the divisors of C<n> (see X<divisors>C<divisors>, which is used as a subroutine). It is assumed that C<factor> can handle C<n>, without negative exponents. Instead of C<n>, it is possible to input a factorization matrix, i.e. the output of C<factor(n)>. This routine uses C<divisors> as a subroutine, then loops over the divisors. In particular, if C<n> is an integer, divisors are sorted by increasing size. To avoid storing all divisors, possibly using a lot of memory, the following (much slower) routine loops over the divisors using essentially constant space: FORDIV(N)= { local(P, E); P = factor(N); E = P[,2]; P = P[,1]; forvec( v = vector(#E, i, [0,E[i]]), X = factorback(P, v) \\ ... ); } ? for(i=1,10^5, FORDIV(i)) time = 3,445 ms. ? for(i=1,10^5, fordiv(i, d, )) time = 490 ms. =item X<forell>forellC<(E,a,b,I<seq>)> evaluates I<seq>, where the formal variable C<E> ranges through all elliptic curves of conductors from C<a> to C<b>. Th X<elldata>C<elldata> database must be installed and contain data for the specified conductors. =item X<forprime>forprimeC<(X = a,b,I<seq>)> evaluates I<seq>, where the formal variable C<X> ranges over the prime numbers between C<a> to C<b> (including C<a> and C<b> if they are prime). More precisely, the value of C<X> is incremented to the smallest prime strictly larger than C<X> at the end of each iteration. Nothing is done if C<a E<gt> b>. Note that C<a> and C<b> must be in B<I<R>>. ? { forprime(p = 2, 12, print(p); if (p == 3, p = 6); ) } 2 3 7 11 =item X<forstep>forstepC<(X = a,b,s,I<seq>)> evaluates I<seq>, where the formal variable C<X> goes from C<a> to C<b>, in increments of C<s>. Nothing is done if C<s E<gt> 0> and C<a E<gt> b> or if C<s E<lt> 0> and C<a E<lt> b>. C<s> must be in C<B<I<R>>^*> or a vector of steps C<[s_1,...,s_n]>. In the latter case, the successive steps are used in the order they appear in C<s>. ? forstep(x=5, 20, [2,4], print(x)) 5 7 11 13 17 19 =item X<forsubgroup>forsubgroupC<(H = G,{B},I<seq>)> evaluates I<seq> for each subgroup C<H> of the \emph{abelian} group C<G> (given in SNFX<Smith normal form> form or as a vector of elementary divisors), whose index is bounded by C<B>. The subgroups are not ordered in any obvious way, unless C<G> is a C<p>-group in which case Birkhoff's algorithm produces them by decreasing index. A X<subgroup>subgroup is given as a matrix whose columns give its generators on the implicit generators of C<G>. For example, the following prints all subgroups of index less than 2 in C<G = B<I<Z>>/2B<I<Z>> g_1 x B<I<Z>>/2B<I<Z>> g_2>: ? G = [2,2]; forsubgroup(H=G, 2, print(H)) [1; 1] [1; 2] [2; 1] [1, 0; 1, 1] The last one, for instance is generated by C<(g_1, g_1 + g_2)>. This routine is intended to treat huge groups, when X<subgrouplist>C<subgrouplist> is not an option due to the sheer size of the output. For maximal speed the subgroups have been left as produced by the algorithm. To print them in canonical form (as left divisors of C<G> in HNF form), one can for instance use ? G = matdiagonal([2,2]); forsubgroup(H=G, 2, print(mathnf(concat(G,H)))) [2, 1; 0, 1] [1, 0; 0, 2] [2, 0; 0, 1] [1, 0; 0, 1] Note that in this last representation, the index C<[G:H]> is given by the determinant. See X<galoissubcyclo>C<galoissubcyclo> and X<galoisfixedfield>C<galoisfixedfield> for X<nfsubfields>C<nfsubfields> applications to X<Galois>Galois theory. B<Warning:> the present implementation cannot treat a group C<G>, if one of its C<p>-Sylow subgroups has a cyclic factor with more than C<2^{31}>, resp.S< >C<2^{63}> elements on a C<32>-bit, resp.S< >C<64>-bit architecture. =item X<forvec>forvecC<(X = v,I<seq>,{I<flag> = 0})> Let C<v> be an C<n>-component vector (where C<n> is arbitrary) of two-component vectors C<[a_i,b_i]> for C<1 E<lt>= i E<lt>= n>. This routine evaluates I<seq>, where the formal variables C<X[1],..., X[n]> go from C<a_1> to C<b_1>,..., from C<a_n> to C<b_n>, i.e.S< >C<X> goes from C<[a_1,...,a_n]> to C<[b_1,...,b_n]> with respect to the lexicographic ordering. (The formal variable with the highest index moves the fastest.) If C<I<flag> = 1>, generate only nondecreasing vectors C<X>, and if C<I<flag> = 2>, generate only strictly increasing vectors C<X>. =item X<if>ifC<(a,{I<seq1>},{I<seq2>})> evaluates the expression sequence I<seq1> if C<a> is non-zero, otherwise the expression I<seq2>. Of course, I<seq1> or I<seq2> may be empty: C<if (a,I<seq>)> evaluates I<seq> if C<a> is not equal to zero (you don't have to write the second comma), and does nothing otherwise, C<if (a,,I<seq>)> evaluates I<seq> if C<a> is equal to zero, and does nothing otherwise. You could get the same result using the C<!> (C<not>) operator: C<if (!a,I<seq>)>. Note that the boolean operators C<&&> and C<||> are evaluated according to operator precedence as explained in L<Label se:operators>, but that, contrary to other operators, the evaluation of the arguments is stopped as soon as the final truth value has been determined. For instance if (reallydoit && longcomplicatedfunction(), ...)% is a perfectly safe statement. Recall that functions such as C<break> and C<next> operate on \emph{loops} (such as C<forxxx>, C<while>, C<until>). The C<if> statement is \emph{not} a loop (obviously!). =item X<next>nextC<({n = 1})> interrupts execution of current C<seq>, resume the next iteration of the innermost enclosing loop, within the current function call (or top level loop). If C<n> is specified, resume at the C<n>-th enclosing loop. If C<n> is bigger than the number of enclosing loops, all enclosing loops are exited. =item X<return>returnC<({x = 0})> returns from current subroutine, with result C<x>. If C<x> is omitted, return the C<(void)> value (return no result, like C<print>). =item X<until>untilC<(a,I<seq>)> evaluates I<seq> until C<a> is not equal to 0 (i.e.S< >until C<a> is true). If C<a> is initially not equal to 0, I<seq> is evaluated once (more generally, the condition on C<a> is tested \emph{after} execution of the I<seq>, not before as in C<while>). =item X<while>whileC<(a,I<seq>)> while C<a> is non-zero, evaluates the expression sequence I<seq>. The test is made \emph{before} evaluating the C<seq>, hence in particular if C<a> is initially equal to zero the I<seq> will not be evaluated at all. =head2 Specific functions used in GP programming X<Label se:gp_program> In addition to the general PARI functions, it is necessary to have some functions which will be of use specifically for C<gp>, though a few of these can be accessed under library mode. Before we start describing these, we recall the difference between \emph{strings} and \emph{keywords} (see L<Label se:strings>): the latter don't get expanded at all, and you can type them without any enclosing quotes. The former are dynamic objects, where everything outside quotes gets immediately expanded. =item X<addhelp>addhelpC<(S,I<str>)> X<Label se:addhelp> changes the help message for the symbol C<S>. The string I<str> is expanded on the spot and stored as the online help for C<S>. If C<S> is a function \emph{you} have defined, its definition will still be printed before the message I<str>. It is recommended that you document global variables and user functions in this way. Of course C<gp> will not protest if you skip this. Nothing prevents you from modifying the help of built-in PARI functions. (But if you do, we would like to hear why you needed to do it!) =item X<alias>aliasC<(I<newkey>,I<key>)> defines the keyword I<newkey> as an alias for keyword I<key>. I<key> must correspond to an existing \emph{function} name. This is different from the general user macros in that alias expansion takes place immediately upon execution, without having to look up any function code, and is thus much faster. A sample alias file C<misc/gpalias> is provided with the standard distribution. Alias commands are meant to be read upon startup from the C<.gprc> file, to cope with function names you are dissatisfied with, and should be useless in interactive usage. =item X<allocatemem>allocatememC<({x = 0})> this is a very special operation which allows the user to change the stack size \emph{after} initialization. C<x> must be a non-negative integer. If C<x ! = 0>, a new stack of size C<16*\ceil{x/16}> bytes is allocated, all the PARI data on the old stack is moved to the new one, and the old stack is discarded. If C<x = 0>, the size of the new stack is twice the size of the old one. Although it is a function, C<allocatemem> cannot be used in loop-like constructs, or as part of a larger expression, e.g C<2 + allocatemem()>. Such an attempt will raise an error. The technical reason is that this routine usually moves the stack, so objects from the current expression may not be correct anymore, e.g. loop indexes. X<allocatemoremem>The library syntax is B<allocatemoremem>C<(x)>, where C<x> is an unsigned long, and the return type is void. C<gp> uses a variant which makes sure it was not called within a loop. =item X<default>defaultC<({I<key>},{I<val>})> returns the default corresponding to keyword I<key>. If I<val> is present, sets the default to I<val> first (which is subject to string expansion first). Typing C<default()> (or C<\d>) yields the complete default list as well as their current values.X<Label se:default> See L<Label se:defaults> for a list of available defaults, and L<Label se:meta> for some shortcut alternatives. Note that the shortcut are meant for interactive use and usually display more information than C<default>. X<gp_default>The library syntax is B<gp_default>C<(key, val)>, where I<key> and I<val> are C<char *>. =item X<error>errorC<({I<str>}*)> outputs its argument list (each of them interpreted as a string), then interrupts the running C<gp> program, returning to the input prompt. For instance error("n = ", n, " is not squarefree !") =item X<extern>externC<(I<str>)> the string I<str> is the name of an external command (i.e.S< >one you would type from your UNIX shell prompt). This command is immediately run and its input fed into C<gp>, just as if read from a file. X<extern0>The library syntax is B<extern0>C<(str)>, where I<str> is a C<char *>. =item X<getheap>getheapC<()> returns a two-component row vector giving the number of objects on the heap and the amount of memory they occupy in long words. Useful mainly for debugging purposes. X<getheap>The library syntax is B<getheap>C<()>. =item X<getrand>getrandC<()> returns the current value of the random number seed. Useful mainly for debugging purposes. X<getrand>The library syntax is B<getrand>C<()>, returns a C long. =item X<getstack>getstackC<()> returns the current value of C<top-avma>, i.e.S< >the number of bytes used up to now on the stack. Should be equal to C<0> in between commands. Useful mainly for debugging purposes. X<getstack>The library syntax is B<getstack>C<()>, returns a C long. =item X<gettime>gettimeC<()> returns the time (in milliseconds) elapsed since either the last call to C<gettime>, or to the beginning of the containing GP instruction (if inside C<gp>), whichever came last. X<gettime>The library syntax is B<gettime>C<()>, returns a C long. =item X<global>globalC<(I<list of variables>)> X<Label se:global> declares the corresponding variables to be global. From now on, you will be forbidden to use them as formal parameters for function definitions or as loop indexes. This is especially useful when patching together various scripts, possibly written with different naming conventions. For instance the following situation is dangerous: p = 3 \\ fix characteristic ... forprime(p = 2, N, ...) f(p) = ... since within the loop or within the function's body (even worse: in the subroutines called in that scope), the true global value of C<p> will be hidden. If the statement C<global(p = 3)> appears at the beginning of the script, then both expressions will trigger syntax errors. Calling C<global> without arguments prints the list of global variables in use. In particular, C<eval(global)> will output the values of all global variables. =item X<input>inputC<()> reads a string, interpreted as a GP expression, from the input file, usually standard input (i.e.S< >the keyboard). If a sequence of expressions is given, the result is the result of the last expression of the sequence. When using this instruction, it is useful to prompt for the string by using the C<print1> function. Note that in the present version 2.19 of C<pari.el>, when using C<gp> under GNU Emacs (see L<Label se:emacs>) one \emph{must} prompt for the string, with a string which ends with the same prompt as any of the previous ones (a C<"? "> will do for instance). =item X<install>installC<(I<name>,I<code>,{I<gpname>},{I<lib>})> loads from dynamic library I<lib> the function I<name>. Assigns to it the name I<gpname> in this C<gp> session, with argument code I<code> (see the Libpari Manual for an explanation of those). If I<lib> is omitted, uses C<libpari.so>. If I<gpname> is omitted, uses I<name>.X<Label se:install> This function is useful for adding custom functions to the C<gp> interpreter, or picking useful functions from unrelated libraries. For instance, it makes the function X<system>C<system> obsolete: ? install(system, vs, sys, "libc.so") ? sys("ls gp*") gp.c gp.h gp_rl.c But it also gives you access to all (non static) functions defined in the PARI library. For instance, the function C<GEN addii(GEN x, GEN y)> adds two PARI integers, and is not directly accessible under C<gp> (it's eventually called by the C<+> operator of course): ? install("addii", "GG") ? addii(1, 2) %1 = 3 Re-installing a function will print a Warning, and update the prototype code if needed, but will reload a symbol from the library, even it the latter has been recompiled. B<Caution:> This function may not work on all systems, especially when C<gp> has been compiled statically. In that case, the first use of an installed function will provoke a Segmentation Fault, i.e.S< >a major internal blunder (this should never happen with a dynamically linked executable). Hence, if you intend to use this function, please check first on some harmless example such as the ones above that it works properly on your machine. =item X<kill>killC<(s)> X<Label se:kill> kills the present value of the variable, alias or user-defined function C<s>. The corresponding identifier can now be used to name any GP object (variable or function). This is the only way to replace a variable by a function having the same name (or the other way round), as in the following example: ? f = 1 %1 = 1 ? f(x) = 0 *** unused characters: f(x)=0 ^---- ? kill(f) ? f(x) = 0 ? f() %2 = 0 When you kill a variable, all objects that used it become invalid. You can still display them, even though the killed variable will be printed in a funny way. For example: ? a^2 + 1 %1 = a^2 + 1 ? kill(a) ? %1 %2 = #<1>^2 + 1 If you simply want to restore a variable to its ``undefined'' value (monomial of degree one), use the X<quote>quote operator: C<a = 'a>. Predefined symbols (C<x> and GP function names) cannot be killed. =item X<print>printC<({I<str>}*)> outputs its (string) arguments in raw format, ending with a newline. =item X<print1>print1C<({I<str>}*)> outputs its (string) arguments in raw format, without ending with a newline (note that you can still embed newlines within your strings, using the C<\n> notationS< >!). =item X<printp>printpC<({I<str>}*)> outputs its (string) arguments in prettyprint (beautified) format, ending with a newline. =item X<printp1>printp1C<({I<str>}*)> outputs its (string) arguments in prettyprint (beautified) format, without ending with a newline. =item X<printtex>printtexC<({I<str>}*)> outputs its (string) arguments in TeX format. This output can then be used in a TeX manuscript. The printing is done on the standard output. If you want to print it to a file you should use C<writetex> (see there). Another possibility is to enable the X<log>C<log> default (seeS< >L<Label se:defaults>). You could for instance do:X<logfile> default(logfile, "new.tex"); default(log, 1); printtex(result); =item X<quit>quitC<()> exits C<gp>.X<Label se:quit> =item X<read>readC<({I<filename>})> reads in the file I<filename> (subject to string expansion). If I<filename> is omitted, re-reads the last file that was fed into C<gp>. The return value is the result of the last expression evaluated.X<Label se:read> If a GP X<binary file>C<binary file> is read using this command (see L<Label se:writebin>), the file is loaded and the last object in the file is returned. =item X<readvec>readvecC<({I<str>})> reads in the file I<filename> (subject to string expansion). If I<filename> is omitted, re-reads the last file that was fed into C<gp>. The return value is a vector whose components are the evaluation of all sequences of instructions contained in the file. For instance, if I<file> contains 1 2 3 then we will get: ? \r a %1 = 1 %2 = 2 %3 = 3 ? read(a) %4 = 3 ? readvec(a) %5 = [1, 2, 3] In general a sequence is just a single line, but as usual braces and C<\\> may be used to enter multiline sequences. =item X<reorder>reorderC<({x = []})> C<x> must be a vector. If C<x> is the empty vector, this gives the vector whose components are the existing variables in increasing order (i.e.S< >in decreasing importance). Killed variables (see C<kill>) will be shown as C<0>. If C<x> is non-empty, it must be a permutation of variable names, and this permutation gives a new order of importance of the variables, \emph{for output only}. For example, if the existing order is C<[x,y,z]>, then after C<reorder([z,x])> the order of importance of the variables, with respect to output, will be C<[z,y,x]>. The internal representation is unaffected. X<Label se:reorder> =item X<setrand>setrandC<(n)> reseeds the random number generator to the value C<n>. The initial seed is C<n = 1>. X<setrand>The library syntax is B<setrand>C<(n)>, where C<n> is a C<long>. Returns C<n>. =item X<system>systemC<(I<str>)> I<str> is a string representing a system command. This command is executed, its output written to the standard output (this won't get into your logfile), and control returns to the PARI system. This simply calls the C C<system> command. =item X<trap>trapC<({e}, {I<rec>}, {I<seq>})> tries to evaluate I<seq>, trapping error C<e>, that is effectively preventing it from aborting computations in the usual way; the recovery sequence I<rec> is executed if the error occurs and the evaluation of I<rec> becomes the result of the command. If C<e> is omitted, all exceptions are trapped. Note in particular that hitting C<^C> (Control-C) raises an exception. See L<Label se:errorrec> for an introduction to error recovery under C<gp>. ? \\ trap division by 0 ? inv(x) = trap (gdiver, INFINITY, 1/x) ? inv(2) %1 = 1/2 ? inv(0) %2 = INFINITY If I<seq> is omitted, defines I<rec> as a default action when catching exception C<e>, provided no other trap as above intercepts it first. The error message is printed, as well as the result of the evaluation of I<rec>, and control is given back to the C<gp> prompt. In particular, current computation is then lost. The following error handler prints the list of all user variables, then stores in a file their name and their values:X<writebin> ? { trap( , print(reorder); writebin("crash")) } If no recovery code is given (I<rec> is omitted) a X<break loop>I<break loop> will be started (see L<Label se:breakloop>). In particular ? trap() by itself installs a default error handler, that will start a break loop whenever an exception is raised. If I<rec> is the empty string C<""> the default handler (for that error if C<e> is present) is disabled. B<Note:> The interface is currently not adequate for trapping individual exceptions. In the current version B<2.2.0>, the following keywords are recognized, but the name list will be expanded and changed in the future (all library mode errors can be trapped: it's a matter of defining the keywords to C<gp>, and there are currently far too many useless ones): C<accurer>: accuracy problem C<archer>: not available on this architecture or operating system C<errpile>: the PARI stack overflows C<gdiver>: division by 0 C<invmoder>: impossible inverse modulo C<siginter>: SIGINT received (usually from Control-C) C<talker>: miscellaneous error C<typeer>: wrong type C<user>: user error (from the C<error> function) =item X<type>typeC<(x)> this is useful only under C<gp>. Returns the internal type name of the PARI object C<x> as a string. Check out existing type names with the metacommand C<\t>.X<Label se:gptype> For example C<type(1)> will return "C<t_INT>". X<type0>The library syntax is B<type0>C<(I<x>)>, though the macro C<typ> is usually simpler to use since it return an integer that can easily be matched with the symbols C<t_*>. The name C<type> was avoided due to the fact that C<type> is a reserved identifier for some C(++) compilers. =item X<version>versionC<()> Returns the current version number as a C<t_VEC> with three integer components: major version number, minor version number and patchlevel. To check against a particular version number, you can use: if (lex(version(), [2,2,0]) >= 0, \\ code to be executed if we are running 2.2.0 or more recent. , \\ compatibility code ); =item X<whatnow>whatnowC<(I<key>)> if keyword I<key> is the name of a function that was present in GP version 1.39.15 or lower, outputs the new function name and syntax, if it changed at all (C<387> out of C<560> did).X<Label se:whatnow> =item X<write>writeC<(I<filename>,{I<str>}*)> writes (appends) to I<filename> the remaining arguments, and appends a newline (same output as C<print>).X<Label se:write> =item X<write1>write1C<(I<filename>,{I<str>}*)> writes (appends) to I<filename> the remaining arguments without a trailing newline (same output as C<print1>). =item X<writebin>writebinC<(I<filename>,{x})> writes (appends) to I<filename> the object C<x> in binary format. This format is not human readable, but contains the exact internal structure of C<x>, and is much faster to save/load than a string expression, as would be produced by X<write>C<write>. The binary file format includes a magic number, so that such a file can be recognized and correctly input by the regular X<read>C<read> or C<\r> function. If saved objects refer to (polynomial) variables that are not defined in the new session, they will be displayed in a funny way (see L<Label se:kill>). If C<x> is omitted, saves all user variables from the session, together with their names. Reading such a ``named object'' back in a C<gp> session will set the corresponding user variable to the saved value. E.g after x = 1; writebin("log") reading C<log> into a clean session will set C<x> to C<1>. The relative variables priorities (see L<Label se:priority>) of new variables set in this way remain the same (preset variables retain their former priority, but are set to the new value). In particular, reading such a session log into a clean session will restore all variables exactly as they were in the original one. User functions, installed functions and history objects can not be saved via this function. Just as a regular input file, a binary file can be compressed using X<gzip>C<gzip>, provided the file name has the standard C<.gz> extension. X<Label se:writebin>X<binary file> In the present implementation, the binary files are architecture dependent and compatibility with future versions of C<gp> is not guaranteed. Hence binary files should not be used for long term storage (also, they are larger and harder to compress than text files). =item X<writetex>writetexC<(I<filename>,{I<str>}*)> as C<write>, in TeX format.X<Label se:writetex>