Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

First, I cannot reproduce your result of set(flatten(M0)) in Sage 9.3 - it just gives a set of polynomials from M0.

Second, elements of M0 have type class 'sage.rings.polynomial.pbori.pbori.BooleanPolynomial' and are composed on monomials of type class 'sage.rings.polynomial.pbori.pbori.BooleanMonomial'. Apparently Sage has trouble to comparing them with each other (which may be worth to report as a bug).

Third, to avoid dealing with Boolean polynomials/monomials, we can convert them to polynomials over GF(2) (defined by the ring R in your code).

All in all, the result you want can be achieved as

M0=[R(L_S[i]+L_X[i]) for i in [0..len(A)-1]]
set(flatten(list(map(lambda t: t.monomials(),M0))))

or without explicit conversion of map to list:

import itertools
M0=[R(L_S[i]+L_X[i]) for i in [0..len(A)-1]]
set(itertools.chain.from_iterable(map(lambda t: t.monomials(),M0)))

Each of these gives {x3, x1*x2*x3, x0*x3, 1, x1*x3, x1, x0, x0*x1*x3, x0*x1, x2, x0*x2, x1*x2, x0*x2*x3, x0*x1*x2, x2*x3}.

First, I cannot reproduce your result of set(flatten(M0)) in Sage 9.3 - it just gives a set of polynomials from M0.

Second, elements of M0 have type class 'sage.rings.polynomial.pbori.pbori.BooleanPolynomial' and are composed on monomials of type class 'sage.rings.polynomial.pbori.pbori.BooleanMonomial'. Apparently Sage has trouble to comparing them with each other (which may be worth to report as a bug).

Third, to avoid dealing with Boolean polynomials/monomials, we can convert them to polynomials over GF(2) (defined by the ring R in your code).

All code) when defining M0 as

M0 = [ R(L_S[i]+L_X[i]) for i in all, [0..len(A)-1] ]

Then, the result you want can be achieved as

M0=[R(L_S[i]+L_X[i]) for i in [0..len(A)-1]]
set(flatten(list(map(lambda t: t.monomials(),M0))))

or without explicit conversion of map to list: as

import itertools
M0=[R(L_S[i]+L_X[i]) for i in [0..len(A)-1]]
set(itertools.chain.from_iterable(map(lambda functools
functools.reduce(set.union,map(lambda t: t.monomials(),M0)))
t.monomials(),M0),set())

Each of these gives {x3, the combined set of monomials {1, x0, x0*x1, x2, x1*x2, x0*x1*x2, x3, x1*x2*x3, x0*x3, 1, x1*x3, x1, x0, x0*x1*x3, x0*x1, x2, x0*x2, x1*x2, x0*x2*x3, x0*x1*x2, x2*x3}.