ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 22 Jun 2016 09:51:52 +0200Evaluating discriminant of a polynomial in Z_n[x]/<x^r-1>https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/Consider the following code
Zn=Zmod(n)
R = PolynomialRing(Zn,'x')
F = R.quotient((x**r)-1)
y=F((x+1))
f=F(y**n)
Clearly **f** will be a polynomial in xbar , I want to consider this polynomial as a polynomial in $ \mathbb{Z}[x] $ and evaluate its discriminant.
I tried **"f.polynomial()"** but it is not working. Any suggestions ? Wed, 22 Jun 2016 08:10:18 +0200https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/Answer by slelievre for <p>Consider the following code </p>
<pre><code>Zn=Zmod(n)
R = PolynomialRing(Zn,'x')
F = R.quotient((x**r)-1)
y=F((x+1))
f=F(y**n)
</code></pre>
<p>Clearly <strong>f</strong> will be a polynomial in xbar , I want to consider this polynomial as a polynomial in $ \mathbb{Z}[x] $ and evaluate its discriminant.</p>
<p>I tried <strong>"f.polynomial()"</strong> but it is not working. Any suggestions ? </p>
https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/?answer=33883#post-id-33883Your friend here is the `list` method, which will give you the coefficients of `f` as a polynomial in `xbar`.
Then you will be able to take its discriminant.
Let us illustrate this step by step.
To begin with, for reference, here is the Sage version used below.
sage: version()
'SageMath version 7.2, Release Date: 2016-05-15'
Let us set some values for `n` and `r` so that the code works and others can try it out.
sage: n = 13
sage: r = 7
Now define `Zn`, `R`, `F`, `y`, `f` as you did.
sage: Zn = Zmod(n)
sage: R = PolynomialRing(Zn, 'x')
sage: F = R.quotient(x**r-1)
sage: y = F(x+1)
sage: f = F(y**n)
We get:
sage: f
xbar^6 + 1
Get the coefficients:
sage: f.list()
[1, 0, 0, 0, 0, 0, 1]
Define the ring of polynomials over `ZZ`:
sage: Zx = PolynomialRing(ZZ, 'x')
The polynomial corresponding to `f`:
sage: ff = Zx(f.list())
sage: ff
x^6 + 1
The discriminant of this polynomial:
sage: ff.discriminant()
-46656
Wed, 22 Jun 2016 09:02:40 +0200https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/?answer=33883#post-id-33883Answer by B r u n o for <p>Consider the following code </p>
<pre><code>Zn=Zmod(n)
R = PolynomialRing(Zn,'x')
F = R.quotient((x**r)-1)
y=F((x+1))
f=F(y**n)
</code></pre>
<p>Clearly <strong>f</strong> will be a polynomial in xbar , I want to consider this polynomial as a polynomial in $ \mathbb{Z}[x] $ and evaluate its discriminant.</p>
<p>I tried <strong>"f.polynomial()"</strong> but it is not working. Any suggestions ? </p>
https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/?answer=33880#post-id-33880The method you are looking for is called `lift`:
sage: g = f.lift()
sage: g
7*x^9 + 9*x^8 + 9*x^7 + 7*x^6 + 8*x^5 + 8*x^4 + 8*x + 8
sage: g.parent()
Univariate Polynomial Ring in x over Ring of integers modulo 14
sage: g.discriminant()
0
*As a side comment:* I created `Zn = Zmod(14)`. If you want to work in a finite field with `p` elements, you should better use `K = GF(p)` than `Zn = Zmod(p)` since you are telling `Sage` that `K` is a field.
----------
**EDIT:** If you want the polynomial over $\mathbb{Z}$, you can do the following:
sage: h = g.change_ring(ZZ)
sage: h.discriminant()
19634094616613079744512
Wed, 22 Jun 2016 08:44:18 +0200https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/?answer=33880#post-id-33880Comment by slelievre for <p>The method you are looking for is called <code>lift</code>:</p>
<pre><code>sage: g = f.lift()
sage: g
7*x^9 + 9*x^8 + 9*x^7 + 7*x^6 + 8*x^5 + 8*x^4 + 8*x + 8
sage: g.parent()
Univariate Polynomial Ring in x over Ring of integers modulo 14
sage: g.discriminant()
0
</code></pre>
<p><em>As a side comment:</em> I created <code>Zn = Zmod(14)</code>. If you want to work in a finite field with <code>p</code> elements, you should better use <code>K = GF(p)</code> than <code>Zn = Zmod(p)</code> since you are telling <code>Sage</code> that <code>K</code> is a field.</p>
<hr/>
<p><strong>EDIT:</strong> If you want the polynomial over $\mathbb{Z}$, you can do the following:</p>
<pre><code>sage: h = g.change_ring(ZZ)
sage: h.discriminant()
19634094616613079744512
</code></pre>
https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/?comment=33884#post-id-33884Nice answer. Note that this gives a polynomial over `Zn`, and its discriminant is computed modulo `n`.Wed, 22 Jun 2016 09:09:58 +0200https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/?comment=33884#post-id-33884Comment by vishb for <p>The method you are looking for is called <code>lift</code>:</p>
<pre><code>sage: g = f.lift()
sage: g
7*x^9 + 9*x^8 + 9*x^7 + 7*x^6 + 8*x^5 + 8*x^4 + 8*x + 8
sage: g.parent()
Univariate Polynomial Ring in x over Ring of integers modulo 14
sage: g.discriminant()
0
</code></pre>
<p><em>As a side comment:</em> I created <code>Zn = Zmod(14)</code>. If you want to work in a finite field with <code>p</code> elements, you should better use <code>K = GF(p)</code> than <code>Zn = Zmod(p)</code> since you are telling <code>Sage</code> that <code>K</code> is a field.</p>
<hr/>
<p><strong>EDIT:</strong> If you want the polynomial over $\mathbb{Z}$, you can do the following:</p>
<pre><code>sage: h = g.change_ring(ZZ)
sage: h.discriminant()
19634094616613079744512
</code></pre>
https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/?comment=33885#post-id-33885Thanks a lot ! Can you kindly help me with [this](http://ask.sagemath.org/question/33734/taking-gcd-with-respect-to-one-variable/) question also.Wed, 22 Jun 2016 09:51:52 +0200https://ask.sagemath.org/question/33879/evaluating-discriminant-of-a-polynomial-in-z_nxxr-1/?comment=33885#post-id-33885