Exercice 1.1

Avec des polynômes symboliques

In [1]:
P1 = x^6 + 2*x^5 - 2*x^4 + 2*x^2 - 2*x - 1
P2 = x^5 + x^4 - 2*x^3 + x^2 + x- 2
In [2]:
parent(P1)
Out[2]:
Symbolic Ring
In [3]:
P = P1*P2
P
Out[3]:
(x^6 + 2*x^5 - 2*x^4 + 2*x^2 - 2*x - 1)*(x^5 + x^4 - 2*x^3 + x^2 + x - 2)
In [4]:
P.degree(x)
Out[4]:
11

pas très clair ce que fait leading_coeff, mieux vaut lire la doc

In [5]:
P.leading_coeff(x)
Out[5]:
0
In [6]:
P.list()
Out[6]:
[2, 3, -7, 2, 9, -13, -2, 9, -5, -2, 3, 1]
In [7]:
P.expand()
Out[7]:
x^11 + 3*x^10 - 2*x^9 - 5*x^8 + 9*x^7 - 2*x^6 - 13*x^5 + 9*x^4 + 2*x^3 - 7*x^2 + 3*x + 2

Avec des polynômes denses

In [8]:
A.<x> = QQ[]
In [9]:
parent(x)
Out[9]:
Univariate Polynomial Ring in x over Rational Field
In [10]:
P1 = x^6 + 2*x^5 - 2*x^4 + 2*x^2 - 2*x - 1
P2 = x^5 + x^4 - 2*x^3 + x^2 + x- 2
In [11]:
parent(P1)
Out[11]:
Univariate Polynomial Ring in x over Rational Field
In [12]:
P = P1*P2
P
Out[12]:
x^11 + 3*x^10 - 2*x^9 - 5*x^8 + 9*x^7 - 2*x^6 - 13*x^5 + 9*x^4 + 2*x^3 - 7*x^2 + 3*x + 2
In [13]:
P.degree(), P.leading_coefficient(), P.list()
Out[13]:
(11, 1, [2, 3, -7, 2, 9, -13, -2, 9, -5, -2, 3, 1])
In [14]:
P1 // P2, P1 % P2
Out[14]:
(x + 1, -x^4 + x^3 - x + 1)
In [15]:
P1 / P2
Out[15]:
(x^2 + 3*x + 1)/(x + 2)
In [16]:
parent(P1/P2)
Out[16]:
Fraction Field of Univariate Polynomial Ring in x over Rational Field
In [17]:
P1.quo_rem(P2)
Out[17]:
(x + 1, -x^4 + x^3 - x + 1)
In [18]:
Q = P1.gcd(P2)
Q
Out[18]:
x^4 - x^3 + x - 1
In [19]:
gcd(P1, P2)
Out[19]:
x^4 - x^3 + x - 1
In [20]:
f = P.factor()
f
Out[20]:
(x + 2) * (x - 1)^2 * (x + 1)^2 * (x^2 + 3*x + 1) * (x^2 - x + 1)^2

L'objet factorisation se comporte comme une liste de paires facteur-multiplicité

In [21]:
len(f)
Out[21]:
5
In [22]:
f[2]
Out[22]:
(x + 1, 2)
In [23]:
f[2][0]
Out[23]:
x + 1
In [24]:
P(2)
Out[24]:
3564

Exercice 1.3

In [25]:
A.<x> = ZZ[]
P = x^11 + x^10 + x^9 + 2*x^8 + 2*x^6 + 2*x^4 + x^2 + x^3 + x
P
Out[25]:
x^11 + x^10 + x^9 + 2*x^8 + 2*x^6 + 2*x^4 + x^3 + x^2 + x
In [26]:
P.factor()
Out[26]:
x * (x^2 + 1) * (x^2 + x + 1) * (x^6 - x^4 + 2*x^3 - x^2 + 1)
In [27]:
QQ[i]
Out[27]:
Number Field in I with defining polynomial x^2 + 1
In [28]:
B.<x> = QQ[i][]
P1 = x^11 + x^10 + x^9 + 2*x^8 + 2*x^6 + 2*x^4 + x^2 + x^3 + x
P1
Out[28]:
x^11 + x^10 + x^9 + 2*x^8 + 2*x^6 + 2*x^4 + x^3 + x^2 + x
In [29]:
P1.factor()
Out[29]:
(x - I) * x * (x + I) * (x^2 + x + 1) * (x^6 - x^4 + 2*x^3 - x^2 + 1)

Alternativement, on peut demander une copie de P avec un autre anneau de base

In [30]:
P1 = P.change_ring(QQ[i])
P1
Out[30]:
x^11 + x^10 + x^9 + 2*x^8 + 2*x^6 + 2*x^4 + x^3 + x^2 + x
In [31]:
parent(P1)
Out[31]:
Univariate Polynomial Ring in x over Number Field in I with defining polynomial x^2 + 1

change_ring n'a pas changé P

In [32]:
parent(P)
Out[32]:
Univariate Polynomial Ring in x over Integer Ring
In [33]:
P1.factor()
Out[33]:
(x - I) * x * (x + I) * (x^2 + x + 1) * (x^6 - x^4 + 2*x^3 - x^2 + 1)
In [34]:
P2 = P.change_ring(ZZ[i])
P2
Out[34]:
x^11 + x^10 + x^9 + 2*x^8 + 2*x^6 + 2*x^4 + x^3 + x^2 + x

La factorisation à coefficients dans $ℤ[i]$ n'est pas implantée dans Sage

In [35]:
P2.factor()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-35-816ca0c1a0fc> in <module>()
----> 1 P2.factor()

/local/SageMath-6.10/src/sage/rings/polynomial/polynomial_element.pyx in sage.rings.polynomial.polynomial_element.Polynomial.factor (/local/SageMath-6.10/src/build/cythonized/sage/rings/polynomial/polynomial_element.c:34889)()
   3742             # This was copied from the general multivariate implementation
   3743             try:
-> 3744                 if R.is_finite():
   3745                     if R.characteristic() > 1<<29:
   3746                         raise NotImplementedError("Factorization of multivariate polynomials over prime fields with characteristic > 2^29 is not implemented.")

/local/SageMath-6.10/src/sage/rings/ring.pyx in sage.rings.ring.Ring.is_finite (/local/SageMath-6.10/src/build/cythonized/sage/rings/ring.c:8412)()
    884         if self.is_zero():
    885             return True
--> 886         raise NotImplementedError
    887 
    888     def cardinality(self):

NotImplementedError: 
In [36]:
P1.factor()
Out[36]:
(x - I) * x * (x + I) * (x^2 + x + 1) * (x^6 - x^4 + 2*x^3 - x^2 + 1)
In [37]:
P3 = P.change_ring(GF(2))
P3.factor()
Out[37]:
x * (x + 1)^8 * (x^2 + x + 1)
In [38]:
P4 = P.change_ring(GF(4, 'i'))
P4.factor()
Out[38]:
x * (x + i) * (x + i + 1) * (x + 1)^8
In [39]:
P5 = P.change_ring(GF(5))
P5.factor()
Out[39]:
x * (x + 2) * (x + 3) * (x^2 + x + 1)^2 * (x^4 + 4*x^3 + 4*x^2 + 4*x + 1)

Exercice 1.4

In [40]:
A.<x> = ZZ[]
P = x^7 + x^5 + 2*x^3 + 2*x^2 + 3*x + 2
P
Out[40]:
x^7 + x^5 + 2*x^3 + 2*x^2 + 3*x + 2

On voit ici une autre façon de convertir un polynôme d'un anneau à un autre

In [41]:
B = GF(2)['x']
P2 = B(P)
P2
Out[41]:
x^7 + x^5 + x
In [42]:
P2.factor()
Out[42]:
x * (x^3 + x^2 + 1)^2
In [43]:
P7 = GF(7)['x'](P)
P7
Out[43]:
x^7 + x^5 + 2*x^3 + 2*x^2 + 3*x + 2
In [44]:
P7.factor()
Out[44]:
(x + 4) * (x^6 + 3*x^5 + 3*x^4 + 2*x^3 + x^2 + 5*x + 4)
In [ ]: