Polynomials
In this section we illustrate how to create and use polynomials in Sage.
Univariate Polynomials
There are three ways to create polynomial rings.
This creates a polynomial ring and tells Sage to use (the string) ‘t’ as the indeterminate when printing to the screen. However, this does not define the symbol "t" for use in Sage, so you cannot use it to enter a polynomial (such as ) belonging to "R".
An alternate way is
This has the same issue regarding "t".
A third very convenient way is
or
or even
This has the additional side effect that it defines the variable "t" to be the indeterminate of the polynomial ring, so you can easily construct elements of "R", as follows. (Note that the third way is very similar to the constructor notation in Magma, and just as in Magma it can be used for a wide range of objects.)
Whatever method you use to define a polynomial ring, you can recover the indeterminate as the generator:
Note that a similar construction works with the complex numbers: the complex numbers can be viewed as being generated over the real numbers by the symbol "i"; thus we have the following:
For polynomial rings, you can obtain both the ring and its generator, or just the generator, during ring creation as follows:
Finally we do some arithmetic in .
Notice that the factorization correctly takes into account and records the unit part.
If you were to use, e.g., the "R.cyclotomic_polynomial" function a lot for some research project, in addition to citing Sage you should make an attempt to find out what component of Sage is being used to actually compute the cyclotomic polynomial and cite that as well. In this case, if you type "R.cyclotomic_polynomial??" to see the source code, you’ll quickly see a line "f = pari.polcyclo(n)" which means that PARI is being used for computation of the cyclotomic polynomial. Cite PARI in your work as well.
Dividing two polynomials constructs an element of the fraction field (which Sage creates automatically).
Using Laurent series, one can compute series expansions in the fraction field of "QQ":
If we name the variable differently, we obtain a different univariate polynomial ring.
The ring is determined by the variable. Note that making another ring with variable called "x" does not return a different ring.
Sage also has support for power series and Laurent series rings over any base ring. In the following example, we create an element of and divide to create an element of .
You can also create power series rings using a double-brackets shorthand:
Multivariate Polynomials
To work with polynomials of several variables, we declare the polynomial ring and variables first.
Just as for defining univariate polynomial rings, there are alternative ways:
Also, if you want the variable names to be single letters then you can use the following shorthand:
Next let’s do some arithmetic.
You can also use more mathematical notation to construct a polynomial ring.
Multivariate polynomials are implemented in Sage using Python dictionaries and the “distributive representation” of a polynomial. Sage makes some use of Singular [Si], e.g., for computation of gcd’s and Gröbner basis of ideals.
Next we create the ideal generated by and , by simply multiplying "(f,g)" by "R" (we could also write "ideal([f,g])" or "ideal(f,g)").
Incidentally, the Gröbner basis above is not a list but an immutable sequence. This means that it has a universe, parent, and cannot be changed (which is good because changing the basis would break other routines that use the Gröbner basis).
Some (read: not as much as we would like) commutative algebra is available in Sage, implemented via Singular. For example, we can compute the primary decomposition and associated primes of :