polynomials over GF(2)

96 views
Skip to first unread message

Phillip M. Feldman

unread,
May 23, 2016, 8:37:42 PM5/23/16
to sympy
I would like to perform operations on polynomials over GF(2), i.e., polynomials with binary coefficients.  Is there a way to do this with SymPy?

There is a sympy.polys.galoistools module, but I haven't found any user documentation for it

Kalevi Suominen

unread,
May 24, 2016, 1:05:26 AM5/24/16
to sympy


On Tuesday, May 24, 2016 at 3:37:42 AM UTC+3, Phillip M. Feldman wrote:
I would like to perform operations on polynomials over GF(2), i.e., polynomials with binary coefficients.  Is there a way to do this with SymPy?

There is a sympy.polys.galoistools module, but I haven't found any user documentation for it

galoistools is the low lever implementation module that is not intended for direct use. The user interface is the
same as with other polynomials. To define a polynomial ring  R  with generator (or 'unknown')  x  over  GF(2)  you write

R, x = ring('x', GF(2))

Polynomials are then constructed in the usual way: p = x**2 + x , etc. and all the standard operations are valid. (Note:  x  is also a polynomial, not a Symbol.)

Phillip Feldman

unread,
May 24, 2016, 8:31:23 PM5/24/16
to sy...@googlegroups.com
I tried the following:

In [1]: from sympy import *
In [2]: R, x= ring('x', GF(2))
In [3]: p= x**5 + 1
In [4]: q= x+1
In [5]: div(p, q)

The result is an exception: SympifyError: x**5 + 1 mod 2

Any advice will be appreciated.

--
You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/nVDoS5B7DXw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/7895ce42-a158-4682-8590-4208c16580a4%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Kalevi Suominen

unread,
May 25, 2016, 12:55:46 AM5/25/16
to sympy


On Wednesday, May 25, 2016 at 3:31:23 AM UTC+3, Phillip M. Feldman wrote:
I tried the following:

In [1]: from sympy import *
In [2]: R, x= ring('x', GF(2))
In [3]: p= x**5 + 1
In [4]: q= x+1
In [5]: div(p, q)

The result is an exception: SympifyError: x**5 + 1 mod 2

Any advice will be appreciated.

div(p, q)  is intended for expressions. p and q  are polynomials, not expressions. Division of polynomials is defined as a method:
In [4]: p.div(q)
Out[4]: (x**4 + x**3 + x**2 + x + 1 mod 2, 0 mod 2)

Kalevi Suominen

unread,
May 25, 2016, 1:03:10 AM5/25/16
to sympy


On Wednesday, May 25, 2016 at 7:55:46 AM UTC+3, Kalevi Suominen wrote:


On Wednesday, May 25, 2016 at 3:31:23 AM UTC+3, Phillip M. Feldman wrote:
I tried the following:

In [1]: from sympy import *
In [2]: R, x= ring('x', GF(2))
In [3]: p= x**5 + 1
In [4]: q= x+1
In [5]: div(p, q)

The result is an exception: SympifyError: x**5 + 1 mod 2

Any advice will be appreciated.

div(p, q)  is intended for expressions. p and q  are polynomials, not expressions. Division of polynomials is defined as a method:
In [4]: p.div(q)
Out[4]: (x**4 + x**3 + x**2 + x + 1 mod 2, 0 mod 2)

PS: You can also write p/q, if the remainder 0 is not needed. 
Reply all
Reply to author
Forward
0 new messages