# 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.

edit retag close merge delete

Sort by » oldest newest most voted

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]

more

1

(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]