Ask Your Question

# Sage symbolic expression modulo

asked 2015-04-28 06:51:49 -0500

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

## Comments

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

( 2015-04-28 07:19:28 -0500 )edit

## 1 answer

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

## Comments

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

( 2015-04-28 08:41:16 -0500 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2015-04-28 06:51:49 -0500

Seen: 541 times

Last updated: Apr 28 '15