Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

SAGE Tutorial 2.7 Polynomials - Examples

55 views
# ****************************************************** # SAGE Tutorial 2.7 Polynomials (Examples) # # # ****************************************************** # ************ 1. Univariate Polynomials ********** R=PolynomialRing(QQ,'t') R # Alternate way: S=QQ['t'] S # 3rd way: T.<t>=PolynomialRing(QQ) # or =QQ['t'] or =QQ[] # Are they the same object? S==R R==T # ************ 2. Indeterminate Variable ********** # They define the indeterminate variable t poly=(t+1)*(t+2); poly poly in R # The generator can be recovered as R.0 t=R.0; t in R
Univariate Polynomial Ring in t over Rational Field Univariate Polynomial Ring in t over Rational Field True True t^2 + 3*t + 2 True True
# *************** 3. More examples: complex numbers, finite fields **************** # Complex Numbers are RR[i], therefore inherit the "continuum" deficiencies: # we need to truncate and use a finite precission, here 53 bits! CC CC.0 # generator of C over R, i.e. "i=sqrt(-1)" # Alternatively: print "I=", I, ", I^2=", I^2, ", Checking Euler's Trademark Formula exp(i pi)+1=0 :", exp(I*pi)+1 # Galois Fields / Finite fields GF(p) K=GF(3); print K, "Generator:", K.0 g=K(1); g # converting Z -> Z/p print "2^3 in Z vs. 2^3 in F3:", 2^3, K(2)^3 # **************** 4. Arithmetic in Polynomial Rings ********************
Complex Field with 53 bits of precision 1.00000000000000*I I= I , I^2= -1 , Checking Euler's Trademark Formula exp(i pi)+1=0 : 0 Finite Field of size 3 Generator: 1 1 2^3 in Z vs. 2^3 in F3: 8 2
# More examples p.26 ... # Cyclotomic polynomials cyclo=R.cyclotomic_polynomial(7); cyclo g=cyclo*7*(t^2+1); g F=factor(g); F F.unit # group of units factor; depends on the ring.
t^6 + t^5 + t^4 + t^3 + t^2 + t + 1 7*t^8 + 7*t^7 + 14*t^6 + 14*t^5 + 14*t^4 + 14*t^3 + 14*t^2 + 7*t + 7 (7) * (t^2 + 1) * (t^6 + t^5 + t^4 + t^3 + t^2 + t + 1)
File: /ext/sage/sage-8.3_1804/local/lib/python2.7/site-packages/sage/structure/factorization.py Signature : F.unit # leading coefficient(self) Docstring : Return the unit part of this factorization. EXAMPLES: We create a polynomial over the real double field and factor it: sage: x = polygen(RDF, 'x') sage: F = factor(-2*x^2 - 1); F (-2.0) * (x^2 + 0.5000000000000001) Note that the unit part of the factorization is -2.0: sage: F.unit() -2.0 sage: F = factor(-2006); F -1 * 2 * 17 * 59 sage: F.unit() -1
# Side note about citations when doing research using SAGE ... # **************** 4. Fraction Field of Polynomilas (e.g. Rational polynomials) ********** # Dividing polynomials constructs elements of the corresponding fraction field x=QQ['x'].0 # redefines x as the independent variable of polynomials over Q f=x^3+1; g=x^2-17 h=f/g; h h.parent() # "Who do you belong to?"
(x^3 + 1)/(x^2 - 17) Fraction Field of Univariate Polynomial Ring in x over Rational Field
# *************** 5. Laurent Series ******************* R.<x>=LaurentSeriesRing(QQ); R 1/(1-x) + O(x^10) # specifies the truncation at degree 10
Laurent Series Ring in x over Rational Field 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + O(x^10)
# The name of the independent variable is part of the definition of the ring R.<x>=PolynomialRing(QQ) S.<y>=PolynomialRing(QQ) x==y R==S R(y^2-17) # Converts the y^2-17 polynomial of S into the corresponding element of R
False False x^2 - 17
# ************** 6. Power Series ************************* R.<T>=PowerSeriesRing(GF(7)); R f=T+3*T^2+T^3+O(T^4) # The "order of deformation" is part of the definition, via O(T^n) f^3 1/f parent(1/f)
Power Series Ring in T over Finite Field of size 7 T^3 + 2*T^4 + 2*T^5 + O(T^6) T^-1 + 4 + T + O(T^2) Laurent Series Ring in T over Finite Field of size 7
# ************** 7. Multivariate Polynomials *************** # Declaration R=PolynomialRing(GF(2),3,"z"); R # Here 3=number of variables - standard indexing GF(5)['z0,z1,z2'] # Alternative definition R.<z0,z1,z2>=GF(5)[]; R # Alternative syntax PolynomialRing(GF(5),3,'xyz') # single leters as variables # Warning: use a pair of ' and ', i.e. key with " and ', not ` # Examples of computations z=GF(5)['z0,z1,z2'].gens();z # z is a vector of variables z=(z0,z1,z2) (z[0]+z[1]+z[2])^2
Multivariate Polynomial Ring in z0, z1, z2 over Finite Field of size 2 Multivariate Polynomial Ring in z0, z1, z2 over Finite Field of size 5 Multivariate Polynomial Ring in z0, z1, z2 over Finite Field of size 5 Multivariate Polynomial Ring in x, y, z over Finite Field of size 5 (z0, z1, z2) z0^2 + 2*z0*z1 + z1^2 + 2*z0*z2 + 2*z1*z2 + z2^2
# Other examples QQ['x,y'].gens()
(x, y)
# **************** 8. Ideals ********************* # Define the ring R=QQ['x,y']; R # R, (x,y)=PolynomialRing(RationalField(),2,'xy').objgens(); R # Alternative syntax f=(x^3+2*y^2*x)^2; f g=x^2*y^2; print "f=", f, " g=", g, " gcd=", f.gcd(g) # gcd I=(f,g)*R; I # Defines the ideal
Multivariate Polynomial Ring in x, y over Rational Field x^6 + 4*x^4*y^2 + 4*x^2*y^4 f= x^6 + 4*x^4*y^2 + 4*x^2*y^4 g= x^2*y^2 gcd= x^2 Ideal (x^6 + 4*x^4*y^2 + 4*x^2*y^4, x^2*y^2) of Multivariate Polynomial Ring in x, y over Rational Field
# Grobner basis of an Ideal B=I.groebner_basis(); B x^2 in I
[x^6, x^2*y^2] False
# Recalling the context of the Grobner basis B.parent() B.universe() B[1]
<class 'sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic'> Multivariate Polynomial Ring in x, y over Rational Field x^2*y^2
B[1]=x # triggers an error: can't change the basis; it wouldn't be Grobner
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute flags=compile_flags) in namespace, locals File "", line 1, in <module> File "/ext/sage/sage-8.4_1804/local/lib/python2.7/site-packages/sage/structure/sequence.py", line 504, in __setitem__ self._require_mutable() File "/ext/sage/sage-8.4_1804/local/lib/python2.7/site-packages/sage/structure/sequence.py", line 741, in _require_mutable raise ValueError("object is immutable; please change a copy instead.") ValueError: object is immutable; please change a copy instead.
I.primary_decomposition() I.associated_primes()
[Ideal (x^2) of Multivariate Polynomial Ring in x, y over Rational Field, Ideal (y^2, x^6) of Multivariate Polynomial Ring in x, y over Rational Field] [Ideal (x) of Multivariate Polynomial Ring in x, y over Rational Field, Ideal (y, x) of Multivariate Polynomial Ring in x, y over Rational Field]