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.Thu, 11 Jan 2018 23:00:46 +0100Quadratic extension field of a finite fieldhttps://ask.sagemath.org/question/40568/quadratic-extension-field-of-a-finite-field/ I want to create a quadratic extension of a finite field via `x^2 + 1`, and for that purpose I have the following Sage code:
proof.arithmetic(False)
# Parameters
f = 1
lA = 2
lB = 3
eA = 372
eB = 239
# Define the prime p
p = f*lA**eA*lB**eB-1
assert p.is_prime()
# Prime field of order p
Fp = GF(p)
# The quadratic extension via x^2 + 1 since p = 3 mod 4
Fp2.<i> = Fp.extension(x^2+1)
Though, the above code throws a rather cryptic error `UnboundLocalError: local variable 'E' referenced before assignment`. Any ideas how to solve the problem and create a quadratic extension field.Thu, 11 Jan 2018 16:22:01 +0100https://ask.sagemath.org/question/40568/quadratic-extension-field-of-a-finite-field/Answer by vdelecroix for <p>I want to create a quadratic extension of a finite field via <code>x^2 + 1</code>, and for that purpose I have the following Sage code:</p>
<pre><code>proof.arithmetic(False)
# Parameters
f = 1
lA = 2
lB = 3
eA = 372
eB = 239
# Define the prime p
p = f*lA**eA*lB**eB-1
assert p.is_prime()
# Prime field of order p
Fp = GF(p)
# The quadratic extension via x^2 + 1 since p = 3 mod 4
Fp2.<i> = Fp.extension(x^2+1)
</code></pre>
<p>Though, the above code throws a rather cryptic error <code>UnboundLocalError: local variable 'E' referenced before assignment</code>. Any ideas how to solve the problem and create a quadratic extension field.</p>
https://ask.sagemath.org/question/40568/quadratic-extension-field-of-a-finite-field/?answer=40573#post-id-40573The error is indeed cryptic (see [trac ticket #24526](https://trac.sagemath.org/ticket/24526)). The problem comes from the fact that your expression `x^2 + 1` is not a proper polynomial with coefficients in the base field but a symbolic expression. You should do
sage: K = GF(3)
sage: R.<t> = PolynomialRing(K)
sage: K.extension(t^2 + 1, 'a')
Finite Field in a of size 3^2
You can compare
sage: parent(x)
Symbolic Ring
sage: parent(t)
Univariate Polynomial Ring in t over Finite Field of size 3
Thu, 11 Jan 2018 20:46:54 +0100https://ask.sagemath.org/question/40568/quadratic-extension-field-of-a-finite-field/?answer=40573#post-id-40573Comment by ninho for <p>The error is indeed cryptic (see <a href="https://trac.sagemath.org/ticket/24526">trac ticket #24526</a>). The problem comes from the fact that your expression <code>x^2 + 1</code> is not a proper polynomial with coefficients in the base field but a symbolic expression. You should do</p>
<pre><code>sage: K = GF(3)
sage: R.<t> = PolynomialRing(K)
sage: K.extension(t^2 + 1, 'a')
Finite Field in a of size 3^2
</code></pre>
<p>You can compare</p>
<pre><code>sage: parent(x)
Symbolic Ring
sage: parent(t)
Univariate Polynomial Ring in t over Finite Field of size 3
</code></pre>
https://ask.sagemath.org/question/40568/quadratic-extension-field-of-a-finite-field/?comment=40577#post-id-40577Thank you very much for the clarification.Thu, 11 Jan 2018 23:00:46 +0100https://ask.sagemath.org/question/40568/quadratic-extension-field-of-a-finite-field/?comment=40577#post-id-40577