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.Tue, 26 Aug 2014 02:28:33 +0200Polynomial in $GF(p^2)$https://ask.sagemath.org/question/23920/polynomial-in-gfp2/Hello, I have a finite field $K=GF(p^2)$ and the polynomial ring $R=K[x,y]$. They are defined as such
p = 11;
K = GF(p^2,'t');
K.inject_variables();
R.<e1,e2> = K[];
f = (-4*t + 3)*e1*e2 + (2*t + 4)*e2^2 + (2*t - 4)*e1 + (-5*t + 3)
I would like to know if it is possible to group/order all the terms with respect to `t` instead of `e1` and `e2`. That is, I would like to see
g = -4*e1*e2 + 2*e2^2 + 2*e1 - 5;
h = 3*e1*e2 + 4e2^2 + 4*e1 + 3;
such that
g*t + h == f
Thanks for your help!Mon, 25 Aug 2014 10:03:34 +0200https://ask.sagemath.org/question/23920/polynomial-in-gfp2/Answer by FrédéricC for <p>Hello, I have a finite field $K=GF(p^2)$ and the polynomial ring $R=K[x,y]$. They are defined as such</p>
<pre><code>p = 11;
K = GF(p^2,'t');
K.inject_variables();
R.<e1,e2> = K[];
f = (-4*t + 3)*e1*e2 + (2*t + 4)*e2^2 + (2*t - 4)*e1 + (-5*t + 3)
</code></pre>
<p>I would like to know if it is possible to group/order all the terms with respect to <code>t</code> instead of <code>e1</code> and <code>e2</code>. That is, I would like to see</p>
<pre><code>g = -4*e1*e2 + 2*e2^2 + 2*e1 - 5;
h = 3*e1*e2 + 4e2^2 + 4*e1 + 3;
</code></pre>
<p>such that </p>
<pre><code>g*t + h == f
</code></pre>
<p>Thanks for your help!</p>
https://ask.sagemath.org/question/23920/polynomial-in-gfp2/?answer=23922#post-id-23922Something like that:
sage: f.map_coefficients(lambda p:p.polynomial().coefficients()[0])
3*e1*e2 + 4*e2^2 - 4*e1 + 3
sage: f.map_coefficients(lambda p:p.polynomial().coefficients()[1])
-4*e1*e2 + 2*e2^2 + 2*e1 - 5
Mon, 25 Aug 2014 12:26:18 +0200https://ask.sagemath.org/question/23920/polynomial-in-gfp2/?answer=23922#post-id-23922Comment by tmonteil for <p>Something like that:</p>
<pre><code>sage: f.map_coefficients(lambda p:p.polynomial().coefficients()[0])
3*e1*e2 + 4*e2^2 - 4*e1 + 3
sage: f.map_coefficients(lambda p:p.polynomial().coefficients()[1])
-4*e1*e2 + 2*e2^2 + 2*e1 - 5
</code></pre>
https://ask.sagemath.org/question/23920/polynomial-in-gfp2/?comment=23924#post-id-23924It seems we answered simultaneously. The problem with the ``coefficients()`` method is that it only considers the nonzero coefficients. Try with ``f = 4*e1 -5*t `` to see what happens. That said, ``f.map_coefficients(lambda p:p.polynomial()[0])`` should work.Mon, 25 Aug 2014 12:55:43 +0200https://ask.sagemath.org/question/23920/polynomial-in-gfp2/?comment=23924#post-id-23924Answer by tmonteil for <p>Hello, I have a finite field $K=GF(p^2)$ and the polynomial ring $R=K[x,y]$. They are defined as such</p>
<pre><code>p = 11;
K = GF(p^2,'t');
K.inject_variables();
R.<e1,e2> = K[];
f = (-4*t + 3)*e1*e2 + (2*t + 4)*e2^2 + (2*t - 4)*e1 + (-5*t + 3)
</code></pre>
<p>I would like to know if it is possible to group/order all the terms with respect to <code>t</code> instead of <code>e1</code> and <code>e2</code>. That is, I would like to see</p>
<pre><code>g = -4*e1*e2 + 2*e2^2 + 2*e1 - 5;
h = 3*e1*e2 + 4e2^2 + 4*e1 + 3;
</code></pre>
<p>such that </p>
<pre><code>g*t + h == f
</code></pre>
<p>Thanks for your help!</p>
https://ask.sagemath.org/question/23920/polynomial-in-gfp2/?answer=23923#post-id-23923You can split the components of ``f``, which is iterable:
sage: list(f)
[(7*t + 3, e1*e2), (2*t + 4, e2^2), (2*t + 7, e1), (6*t + 3, 1)]
Given an element of ``K``, you can get its components with respect to ``1`` and ``t``:
sage: z = 7*t + 3
sage: z.polynomial()
7*t + 3
sage: list(z.polynomial())
[3, 7]
With both ingredients, you can recombine ``f`` the way you want. For example:
sage: g = sum(coeff.polynomial()[0]*variable for coeff,variable in f)
sage: h = sum(coeff.polynomial()[1]*variable for coeff,variable in f)
sage: g + t*h
(-4*t + 3)*e1*e2 + (2*t + 4)*e2^2 + (2*t - 4)*e1 + (-5*t + 3)
sage: g + t*h == f
True
Mon, 25 Aug 2014 12:38:57 +0200https://ask.sagemath.org/question/23920/polynomial-in-gfp2/?answer=23923#post-id-23923Comment by Blackadder for <p>You can split the components of <code>f</code>, which is iterable:</p>
<pre><code>sage: list(f)
[(7*t + 3, e1*e2), (2*t + 4, e2^2), (2*t + 7, e1), (6*t + 3, 1)]
</code></pre>
<p>Given an element of <code>K</code>, you can get its components with respect to <code>1</code> and <code>t</code>:</p>
<pre><code>sage: z = 7*t + 3
sage: z.polynomial()
7*t + 3
sage: list(z.polynomial())
[3, 7]
</code></pre>
<p>With both ingredients, you can recombine <code>f</code> the way you want. For example:</p>
<pre><code>sage: g = sum(coeff.polynomial()[0]*variable for coeff,variable in f)
sage: h = sum(coeff.polynomial()[1]*variable for coeff,variable in f)
sage: g + t*h
(-4*t + 3)*e1*e2 + (2*t + 4)*e2^2 + (2*t - 4)*e1 + (-5*t + 3)
sage: g + t*h == f
True
</code></pre>
https://ask.sagemath.org/question/23920/polynomial-in-gfp2/?comment=23932#post-id-23932Thank you so much. SAGE would not be as good as it is without people like you.Tue, 26 Aug 2014 02:28:33 +0200https://ask.sagemath.org/question/23920/polynomial-in-gfp2/?comment=23932#post-id-23932