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.Wed, 23 Jan 2019 11:48:53 -0600Is there a way to make sage print out all monomials of a Boolean Ring?http://ask.sagemath.org/question/44921/is-there-a-way-to-make-sage-print-out-all-monomials-of-a-boolean-ring/Hi all,
In a finite ring, is there a way to get Sage to print out all possible monomials of the ring? I have a method, but it's very crude. It's simply doing something like taking a random variable to mutiply with a random ring element from B.random_element(). But this is obviously not what I want.
Below is the ring I'm working with.
B = BooleanPolynomialRing(20,'x', order = 'lex')
Is there a Sage function to put every monomial of the ring into a list? I can't seem to find it in Sage documentation.Mon, 07 Jan 2019 02:55:20 -0600http://ask.sagemath.org/question/44921/is-there-a-way-to-make-sage-print-out-all-monomials-of-a-boolean-ring/Answer by slelievre for <p>Hi all,</p>
<p>In a finite ring, is there a way to get Sage to print out all possible monomials of the ring? I have a method, but it's very crude. It's simply doing something like taking a random variable to mutiply with a random ring element from B.random_element(). But this is obviously not what I want.</p>
<p>Below is the ring I'm working with.</p>
<pre><code>B = BooleanPolynomialRing(20,'x', order = 'lex')
</code></pre>
<p>Is there a Sage function to put every monomial of the ring into a list? I can't seem to find it in Sage documentation.</p>
http://ask.sagemath.org/question/44921/is-there-a-way-to-make-sage-print-out-all-monomials-of-a-boolean-ring/?answer=44922#post-id-44922Hint: start with the boolean polynomial ring generators.
sage: B = BooleanPolynomialRing(9, 'x', order = 'lex')
sage: print(B.gens())
(x0, x1, x2, x3, x4, x5, x6, x7, x8)
Detailed answer: use `powerset` to build on the hint.
sage: B = BooleanPolynomialRing(3, 'x', order='lex')
sage: B
Boolean PolynomialRing in x0, x1, x2
sage: G = B.gens()
sage: len(G)
3
sage: G
(x0, x1, x2)
sage: M = list(prod(x, B.one()) for x in powerset(G))
sage: len(M)
8
sage: M
[1, x0, x1, x0*x1, x2, x0*x2, x1*x2, x0*x1*x2]Mon, 07 Jan 2019 04:08:51 -0600http://ask.sagemath.org/question/44921/is-there-a-way-to-make-sage-print-out-all-monomials-of-a-boolean-ring/?answer=44922#post-id-44922Comment by vdelecroix for <p>Hint: start with the boolean polynomial ring generators.</p>
<pre><code>sage: B = BooleanPolynomialRing(9, 'x', order = 'lex')
sage: print(B.gens())
(x0, x1, x2, x3, x4, x5, x6, x7, x8)
</code></pre>
<p>Detailed answer: use <code>powerset</code> to build on the hint.</p>
<pre><code>sage: B = BooleanPolynomialRing(3, 'x', order='lex')
sage: B
Boolean PolynomialRing in x0, x1, x2
sage: G = B.gens()
sage: len(G)
3
sage: G
(x0, x1, x2)
sage: M = list(prod(x, B.one()) for x in powerset(G))
sage: len(M)
8
sage: M
[1, x0, x1, x0*x1, x2, x0*x2, x1*x2, x0*x1*x2]
</code></pre>
http://ask.sagemath.org/question/44921/is-there-a-way-to-make-sage-print-out-all-monomials-of-a-boolean-ring/?comment=45155#post-id-45155(Simpler) alternative using the method **B.monomial**
sage: B = BooleanPolynomialRing(3, 'x', order='lex')
sage: from itertools import product
sage: [B.monomial(*k) for k in product([0,1],repeat=3)]
[1, x2, x1, x1*x2, x0, x0*x2, x0*x1, x0*x1*x2]Wed, 23 Jan 2019 11:48:53 -0600http://ask.sagemath.org/question/44921/is-there-a-way-to-make-sage-print-out-all-monomials-of-a-boolean-ring/?comment=45155#post-id-45155