ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 29 Jan 2019 00:39:23 -0600Dividing Boolean Polynomials in Sage.http://ask.sagemath.org/question/45224/dividing-boolean-polynomials-in-sage/ Hi all,
I'm working in a Boolean Polynomial Ring. I have an equation generator. My objective is to divide the highest possible monomial by the leading monomial of my equations.
NUMBER_OF_VARIABLES = 15
B = BooleanPolynomialRing(NUMBER_OF_VARIABLES,'x', order = 'degrevlex')
Each equation that I generate looks something like this.
f = x6*x2*x1 + x6*x5*x4 + x9*x5*x4 + x9*x6*x0 + x10*x2*x1 + x10*x4*x1 + x11*x9*x7 + x11*x10*x0 + x12*x4*x0 + x12*x7*x3 + x12*x9*x0 + x12*x10*x3 + x12*x10*x5 + x13*x7*x0 + x13*x7*x5 + x13*x8*x6 + x13*x10*x9 + x13*x11*x2 + x14*x5*x4 + x14*x11*x5 + x14*x13*x12 + x6*x3 + x7*x2 + x9*x1 + x10*x9 + x14*x8 + x14*x13 + x3 + x7 + x8 + 1
Getting the leading monomial of f:
print f.lm()
>>> x6*x2*x1
Getting the highest possible monomial of my ring (15 variables)
print f.set().vars()
>>> x14*x13*x12*x11*x10*x9*x8*x7*x6*x5*x4*x3*x2*x1*x0
But somehow I get an error when I try to divide them.
f.set().vars()/f.lm()
>>> bad operand type for unary ~: 'sage.rings.polynomial.pbori.BooleanMonomial'
I checked the documentation and nothing seems to work. I have tried all of the methods below and they do not work.
f.set().vars().divide(f.lm())
# http://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/pbori.html
f.set().vars().reduce(Ideal([f.lm()]))
# https://stackoverflow.com/questions/35233406/multivariate-polynomial-division-in-sage
I'm really at a loss here. I've seen answers whereby the code `q,r = dividend.maxima_methods().divide(divisor)` is used, but this seems like such a simple thing to do. Surely I'm missing something out. Why isn't division working? Multiplication and addition works, so why shouldn't division work?
Mon, 28 Jan 2019 19:43:21 -0600http://ask.sagemath.org/question/45224/dividing-boolean-polynomials-in-sage/Answer by nbruin for <p>Hi all,</p>
<p>I'm working in a Boolean Polynomial Ring. I have an equation generator. My objective is to divide the highest possible monomial by the leading monomial of my equations.</p>
<pre><code>NUMBER_OF_VARIABLES = 15
B = BooleanPolynomialRing(NUMBER_OF_VARIABLES,'x', order = 'degrevlex')
</code></pre>
<p>Each equation that I generate looks something like this.</p>
<pre><code>f = x6*x2*x1 + x6*x5*x4 + x9*x5*x4 + x9*x6*x0 + x10*x2*x1 + x10*x4*x1 + x11*x9*x7 + x11*x10*x0 + x12*x4*x0 + x12*x7*x3 + x12*x9*x0 + x12*x10*x3 + x12*x10*x5 + x13*x7*x0 + x13*x7*x5 + x13*x8*x6 + x13*x10*x9 + x13*x11*x2 + x14*x5*x4 + x14*x11*x5 + x14*x13*x12 + x6*x3 + x7*x2 + x9*x1 + x10*x9 + x14*x8 + x14*x13 + x3 + x7 + x8 + 1
</code></pre>
<p>Getting the leading monomial of f:</p>
<pre><code>print f.lm()
>>> x6*x2*x1
</code></pre>
<p>Getting the highest possible monomial of my ring (15 variables)</p>
<pre><code>print f.set().vars()
>>> x14*x13*x12*x11*x10*x9*x8*x7*x6*x5*x4*x3*x2*x1*x0
</code></pre>
<p>But somehow I get an error when I try to divide them.</p>
<pre><code>f.set().vars()/f.lm()
>>> bad operand type for unary ~: 'sage.rings.polynomial.pbori.BooleanMonomial'
</code></pre>
<p>I checked the documentation and nothing seems to work. I have tried all of the methods below and they do not work.</p>
<pre><code>f.set().vars().divide(f.lm())
# http://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/pbori.html
f.set().vars().reduce(Ideal([f.lm()]))
# https://stackoverflow.com/questions/35233406/multivariate-polynomial-division-in-sage
</code></pre>
<p>I'm really at a loss here. I've seen answers whereby the code <code>q,r = dividend.maxima_methods().divide(divisor)</code> is used, but this seems like such a simple thing to do. Surely I'm missing something out. Why isn't division working? Multiplication and addition works, so why shouldn't division work?</p>
http://ask.sagemath.org/question/45224/dividing-boolean-polynomials-in-sage/?answer=45225#post-id-45225`f.set().vars()//f.lm()` works.
Note that a "boolean" polynomial ring is not a polynomial ring in the usual sense of the word: it has many zero-divisors, so division is generally a tricky operation, and it is indeed not implemented. The division above is on *monomials*.Tue, 29 Jan 2019 00:39:23 -0600http://ask.sagemath.org/question/45224/dividing-boolean-polynomials-in-sage/?answer=45225#post-id-45225