At the moment i have a polynomial (of a galois field) in function of x. But i want to “evaluate” it in x^3.
Any ideas on how to do it?
JavaScript
x
6
1
import galois
2
3
GF = galois.GF(31)
4
f = galois.Poly([1, 0, 0, 15], field=GF);
5
>> x^3 + 15
6
So now f is in function of x: f(x) But i want to have f(x^3)
Advertisement
Answer
I am the author of the galois
library. Converting f(x)
to g(x) = f(x^3)
is equivalent to multiplying the degrees of f(x)
with non-zero coefficients by 3. In galois
, this is done like this.
JavaScript
1
19
19
1
In [1]: import galois
2
3
In [2]: galois.__version__
4
Out[2]: '0.0.26'
5
6
In [3]: GF = galois.GF(31)
7
8
In [4]: f = galois.Poly([1, 0, 0, 15], field=GF); f
9
Out[4]: Poly(x^3 + 15, GF(31))
10
11
In [5]: f.nonzero_degrees
12
Out[5]: array([3, 0])
13
14
In [6]: f.nonzero_coeffs
15
Out[6]: GF([ 1, 15], order=31)
16
17
In [7]: g = galois.Poly.Degrees(3*f.nonzero_degrees, f.nonzero_coeffs); g
18
Out[7]: Poly(x^9 + 15, GF(31))
19
EDIT: As of v0.0.31, polynomial composition is supported. You can now evaluate a polynomial f(x)
at a second polynomial g(x)
.
JavaScript
1
16
16
1
In [1]: import galois
2
3
In [2]: galois.__version__
4
Out[2]: '0.0.31'
5
6
In [3]: GF = galois.GF(31)
7
8
In [4]: f = galois.Poly([1, 0, 0, 15], field=GF); f
9
Out[4]: Poly(x^3 + 15, GF(31))
10
11
In [5]: g = galois.Poly.Degrees([3], field=GF); g
12
Out[5]: Poly(x^3, GF(31))
13
14
In [6]: f(g)
15
Out[6]: Poly(x^9 + 15, GF(31))
16