# 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
The text passage contains a question about performing a modulo operation on a symbolic expression in the Sage mathematics software. It also includes an answer that provides a method to convert the symbolic expression into a polynomial over the field with two elements, effectively performing the modulo 2 operation.
single_question_with_answer
Given a text passage, determine:
    1. If it contains a mathematical question (including word problems or calculations)
    2. If an answer to that mathematical question is provided in the text

First, describe the content structure you found in 1-2 sentences.

Then provide your analysis in the following format:
TYPE: <one of the following values>
- NO_QUESTION
- SINGLE_QUESTION
- SINGLE_QUESTION_WITH_ANSWER
- MULTIPLE_QUESTIONS
- MULTIPLE_QUESTIONS_WITH_ANSWERS
system
# 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
user
The text passage contains a question about performing a modulo operation on a symbolic expression in the Sage mathematics software. It also includes an answer that provides a method to convert the symbolic expression into a polynomial over the field with two elements, effectively performing the modulo 2 operation.

TYPE: SINGLE_QUESTION_WITH_ANSWER