Galois Fields

42 views
Skip to first unread message

clemens novak

unread,
Aug 18, 2016, 2:30:23 PM8/18/16
to sympy
Hello,

I try to perform calculations in GF(2^3); e.g. calculate (x^2+x)(x+1) = x^3 + 2x^2 + x = x^3 + x as polynomial coefficients are modulo-2. Using the irreducible polynomial x^3 + x + 1 I arrive at (x^2+x)(x+1) = 1.

I try to do the same in sympy


import sympy as sym
import sympy.polys as polys
import sympy.polys.galoistools as gft

F = polys.domains.FF(2)
# x^2 + x
a = [1, 1, 0]
# x + 1
b = [1, 1]

res = gft.gf_mul(a, b, 8, F)

sym.pprint(res)

but arrive at [1 mod 2, 0 mod 2, 1 mod 2, 0 mod 2] which I interpret as x^3 + x. So it seems that the reduction using the irreducible polynomial is not done - is there a way to do this last step in sympy?

Thanks & regards - Clemens

Kalevi Suominen

unread,
Aug 19, 2016, 1:14:48 AM8/19/16
to sympy

The galoistool functions gf_*  are low level functions that are not intended for general use. Instead, one can use the standard polynomial methods as follows, for example:

>>> from sympy.abc import x
>>> a = (x**2 + x).as_poly(modulus=2)
>>> b = (x + 1).as_poly(modulus=2)
>>> p = (x**3 + x + 1).as_poly(modulus=2)
>>> (a*b).rem(p).as_expr()
1
Reply all
Reply to author
Forward
0 new messages