Ask Your Question
0

Sage symbolic expression modulo

asked 2015-04-28 13:51:49 +0100

this post is marked as community wiki

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 flag offensive close merge delete

Comments

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

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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-04-28 15:35:54 +0100

slelievre gravatar image

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
edit flag offensive delete link more

Comments

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

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

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2015-04-28 13:51:49 +0100

Seen: 1,465 times

Last updated: Apr 28 '15