# Sage symbolic expression modulo

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi Guys,

I got a symbolic expression in sage that looks like this:

2*s_0_0 + s_0_4 + 3


Can i somehow calculate this modulo 2? So the output would be:

s_0_4 + 1


Any ideas? :) Cheers!

edit retag close merge delete

Instead of symbolic expressions, you may wish to use polynomials over the field with two elements.

( 2015-04-28 14:19:28 +0100 )edit

Sort by ยป oldest newest most voted

Here is a way to follow @kcrisman's advice to move to polynomials over the field with two elements.

First define the expression from your question:

sage: s_0_0, s_0_4 = var('s_0_0 s_0_4')
sage: 2*s_0_0 + s_0_4 + 3
2*s_0_0 + s_0_4 + 3
sage: a = 2*s_0_0 + s_0_4 + 3
sage: a
2*s_0_0 + s_0_4 + 3


This expression lives in Sage's symbolic ring:

sage: a.parent()
Symbolic Ring


Turn it into a polynomial over GF(2) (the finite field with two elements):

sage: a.polynomial(GF(2))
s_0_4 + 1


Note that we could also define a polynomial ring:

sage: R = PolynomialRing(GF(2), names='s_0_0, s_0_4')
sage: R
Multivariate Polynomial Ring in s_0_0, s_0_4 over Finite Field of size 2


and force a into R:

sage: R(a)
s_0_4 + 1

more

Thanks. I used yours and @kcrisman's advice and went for a PolynomialRing! Cheers!

( 2015-04-28 15:41:16 +0100 )edit

## Stats

Seen: 1,299 times

Last updated: Apr 28 '15