Ask Your Question
1

Is there a way to make sage print out all monomials of a Boolean Ring?

asked 2019-01-07 09:55:20 +0100

Stockfish3709 gravatar image

updated 2019-01-07 09:59:22 +0100

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-01-07 11:08:51 +0100

slelievre gravatar image

updated 2019-01-23 15:17:06 +0100

Hint: 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]
edit flag offensive delete link more

Comments

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]
vdelecroix gravatar imagevdelecroix ( 2019-01-23 18:48:53 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-01-07 09:55:20 +0100

Seen: 595 times

Last updated: Jan 23 '19