There are three ways to create polynomial rings.
sage: R = PolynomialRing(QQ, 't') sage: R Univariate Polynomial Ring in t over Rational Field
This creates a polynomial ring and tells Sage to use (the string) ``t'' as
the indeterminate when printing to the screen. The symbol
is not yet
known to Sage, so you cannot use it to enter a polynomial (such as
)
belonging to
.
An alternate way is
sage: S = QQ['t'] sage: S == R True
A third very convenient way is
sage: R.<t> = PolynomialRing(QQ)
sage: R.<t> = QQ['t']
sage: R.<t> = QQ[]
t to be the indeterminate of the polynomial
ring. (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.)
The indeterminate of the polynomial ring is the 0 th generator:
sage: R = PolynomialRing(QQ, 't') sage: t = R.0 sage: t in R True
Alternatively, you can obtain both the ring and its generator, or just the generator during ring creation as follows:
sage: R, t = QQ['t'].objgen() sage: t = QQ['t'].gen() sage: R, t = objgen(QQ['t']) sage: t = gen(QQ['t'])
Finally we do some arithmetic in
.
sage: R, t = QQ['t'].objgen()
sage: f = 2*t^7 + 3*t^2 - 15/19
sage: f^2
4*t^14 + 12*t^9 - 60/19*t^7 + 9*t^4 - 90/19*t^2 + 225/361
sage: cyclo = R.cyclotomic_polynomial(7); cyclo
t^6 + t^5 + t^4 + t^3 + t^2 + t + 1
sage: g = 7 * cyclo * t^5 * (t^5 + 10*t + 2)
sage: g
7*t^16 + 7*t^15 + 7*t^14 + 7*t^13 + 77*t^12 + 91*t^11 + 91*t^10 + 84*t^9
+ 84*t^8 + 84*t^7 + 84*t^6 + 14*t^5
sage: F = factor(g); F
(7) * t^5 * (t^5 + 10*t + 2) * (t^6 + t^5 + t^4 + t^3 + t^2 + t + 1)
sage: F.unit()
7
sage: list(F)
[(t, 5), (t^5 + 10*t + 2, 1), (t^6 + t^5 + t^4 + t^3 + t^2 + t + 1, 1)]
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).
sage: x = QQ['x'].0 sage: f = x^3 + 1; g = x^2 - 17 sage: h = f/g; h (x^3 + 1)/(x^2 - 17) sage: h.parent() Fraction Field of Univariate Polynomial Ring in x over Rational Field
Using Laurent series, one can compute series expansions in
the fraction field of QQ[x]:
sage: R.<x> = LaurentSeriesRing(QQ); R Laurent Series Ring in x over Rational Field sage: 1/(1-x) + O(x^10) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + O(x^10)
If we name the variable differently, we obtain a different univariate polynomial ring.
sage: R.<x> = PolynomialRing(QQ) sage: S.<y> = PolynomialRing(QQ) sage: x == y False sage: R == S False sage: R(y) x sage: R(y^2 - 17) x^2 - 17
The ring is determined by the variable.
Note that making another ring with variable
called x does not return a different
ring.
sage: R = PolynomialRing(QQ, "x") sage: T = PolynomialRing(QQ, "x") sage: R == T True sage: R is T True sage: R.0 == T.0 True
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
.
sage: R.<T> = PowerSeriesRing(GF(7)); R Power Series Ring in T over Finite Field of size 7 sage: f = T + 3*T^2 + T^3 + O(T^4) sage: f^3 T^3 + 2*T^4 + 2*T^5 + O(T^6) sage: 1/f T^-1 + 4 + T + O(T^2) sage: parent(1/f) Laurent Series Ring in T over Finite Field of size 7
You can also create power series rings using a double-brackets shorthand:
sage: GF(7)[['T']] Power Series Ring in T over Finite Field of size 7
See About this document... for information on suggesting changes.