Hi, I'm going to separate the issues here--multiplication and addition. The former is easily handled by implementing the coercion ZZ -> BooleanMonomials via Z/2Z. David Roe and I still need to finish pushing the new coercion model through, but I've been sidetracked doing 3d and other stuff.
As for addition, this violates the underlying assumption that arithmetic on M is closed in M (with the exception of division which passes to the fraction field). Here is the solution I propose: Monoid parents (such as BooleanMonomials) would implement an ambient_algebra() function. It could optionally take a basering (for groups returning a group ring, for monomials returning a polynomial ring). This would be kind of like Mark Hansen's Combinatorial Algebras. In element.pyx one would have cdef class MonoidElement(Element): def __add__(left, right): if not have_same_parent(left, right): return coercion_model.bin_op_c(left, right, add) A = left. ambient_algebra() return A(left) + A(right) Thoughts? - Robert On Dec 29, 2007, at 5:53 AM, Burcin Erocal wrote: > Hello, > > I'm having trouble implementing arithmetic for BooleanMonomials, which > are elements of a monoid. > > Multiplication of BooleanMonomials work fine using the coercion model, > but the following doesn't work, since there is no coercion from ZZ to > BooleanMonomialMonoid. > > sage: P.<x,y> = BooleanPolynomialRing(2) > sage: M = P._monom_monoid > sage: x_monom = M(x); y_monom = M(y) > > sage: x_monom*1 > boom! > sage: 1*x_monom > boom! > > This works, because of the code after sage/structure/element.pyx:1083 > > sage:x_monom*int(1) > x > sage:int(1)*x_monom > > > How should I fix this? By implementing right and left actions, and > returning 0 (in ZZ) when multiplying by an even integer? > > > I also need to have the functionality to add two BooleanMonomials, and > get a BooleanPolynomial. This is a real grey area for the coercion > model. For example: > > sage: x_monom + 1 > ??? > > The common parent of these objects is a BooleanPolynomialRing, > which is > not the parent of either one, so the coercion model doesn't work here. > At Sage Days 6, Robert B suggested bypassing the coercion model and > implementing an __add__ method for BooleanMonomials. This solves the > above problem, but fails for this case: > > sage: 1 + x_monom > boom! > > I would also like the following to work: > > sage: 0 + x_monom > x > sage: x_monom + 0 #this works with the current solution > x > > Again, since there is no coercion from ZZ to BooleanMonomialMonoids, > especially no image of 0 as a BooleanMonomial, this seems to be a case > to be handled outside of the coercion model. > > > Any thoughts or suggestions? > > Burcin > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---