ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 16 Feb 2015 14:44:21 +0100simplifying expressions in GF(2)https://ask.sagemath.org/question/25838/simplifying-expressions-in-gf2/ Hi guys,
I know that for a variable $x$ in $GF(2)$, $x^2 = x$, and $2x=0$.
How do I simplify a polynomial expression in $GF(2)$ in the Sage interface?
For example, I should obtain
$$(a+b+1)^2=a^2+b^2+1+2a+2b+2ab=a+b+1$$
Mon, 16 Feb 2015 03:45:32 +0100https://ask.sagemath.org/question/25838/simplifying-expressions-in-gf2/Answer by vdelecroix for <p>Hi guys,</p>
<p>I know that for a variable $x$ in $GF(2)$, $x^2 = x$, and $2x=0$.</p>
<p>How do I simplify a polynomial expression in $GF(2)$ in the Sage interface?</p>
<p>For example, I should obtain</p>
<p>$$(a+b+1)^2=a^2+b^2+1+2a+2b+2ab=a+b+1$$ </p>
https://ask.sagemath.org/question/25838/simplifying-expressions-in-gf2/?answer=25849#post-id-25849The simplest is to work over boolean polynomials
sage: B.<a,b> = BooleanPolynomialRing(2)
sage: (a+b+1)^2
a + b + 1
But you can also use the more general quotient of polynomial rings (notice that in GF(2) **a** equals **-a**)
sage: R.<a,b> = PolynomialRing(GF(2), 'a,b')
sage: Rbar = R.quotient([a^2+a, b^2+b])
sage: abar,bbar = Rbar.gens()
sage: abar
abar
sage: (abar+bbar+1)^2
abar + bbar + 1Mon, 16 Feb 2015 14:35:21 +0100https://ask.sagemath.org/question/25838/simplifying-expressions-in-gf2/?answer=25849#post-id-25849Answer by rws for <p>Hi guys,</p>
<p>I know that for a variable $x$ in $GF(2)$, $x^2 = x$, and $2x=0$.</p>
<p>How do I simplify a polynomial expression in $GF(2)$ in the Sage interface?</p>
<p>For example, I should obtain</p>
<p>$$(a+b+1)^2=a^2+b^2+1+2a+2b+2ab=a+b+1$$ </p>
https://ask.sagemath.org/question/25838/simplifying-expressions-in-gf2/?answer=25842#post-id-25842I'm not sure why you think that `x^2=x` and Sage gives
sage: R.<a,b> = PolynomialRing(GF(2), 'a,b')
sage: (a+b+1)^2
a^2 + b^2 + 1
Mon, 16 Feb 2015 09:56:59 +0100https://ask.sagemath.org/question/25838/simplifying-expressions-in-gf2/?answer=25842#post-id-25842Comment by slelievre for <p>I'm not sure why you think that <code>x^2=x</code> and Sage gives</p>
<pre><code>sage: R.<a,b> = PolynomialRing(GF(2), 'a,b')
sage: (a+b+1)^2
a^2 + b^2 + 1
</code></pre>
https://ask.sagemath.org/question/25838/simplifying-expressions-in-gf2/?comment=25850#post-id-25850The question is how to manipulate expressions involving variables which are assumed to live in GF(2). In this context, x, a, b, etc. are thought of as elements in GF(2), not as indeterminates of polynomial rings over in GF(2). The question mentions polynomial expressions in such variables, but this does not mean formal polynomials.Mon, 16 Feb 2015 14:44:21 +0100https://ask.sagemath.org/question/25838/simplifying-expressions-in-gf2/?comment=25850#post-id-25850