How to write a polynomial in x**3 instead of x using Polynomial

Question:

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?

import galois 

GF = galois.GF(31) 
f = galois.Poly([1, 0, 0, 15], field=GF);
>> x^3 + 15

So now f is in function of x: f(x)
But i want to have f(x^3)

Asked By: kabooya

||

Answers:

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.

In [1]: import galois

In [2]: galois.__version__
Out[2]: '0.0.26'

In [3]: GF = galois.GF(31)

In [4]: f = galois.Poly([1, 0, 0, 15], field=GF); f
Out[4]: Poly(x^3 + 15, GF(31))

In [5]: f.nonzero_degrees
Out[5]: array([3, 0])

In [6]: f.nonzero_coeffs
Out[6]: GF([ 1, 15], order=31)

In [7]: g = galois.Poly.Degrees(3*f.nonzero_degrees, f.nonzero_coeffs); g
Out[7]: Poly(x^9 + 15, GF(31))

EDIT: As of v0.0.31, polynomial composition is supported. You can now evaluate a polynomial f(x) at a second polynomial g(x).

In [1]: import galois

In [2]: galois.__version__
Out[2]: '0.0.31'

In [3]: GF = galois.GF(31)

In [4]: f = galois.Poly([1, 0, 0, 15], field=GF); f
Out[4]: Poly(x^3 + 15, GF(31))

In [5]: g = galois.Poly.Degrees([3], field=GF); g
Out[5]: Poly(x^3, GF(31))

In [6]: f(g)
Out[6]: Poly(x^9 + 15, GF(31))
Answered By: Matt Hostetter
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.