On Dec 29, 2007 6:53 AM, Burcin Erocal <[EMAIL PROTECTED]> 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?
>

By "fix" what do you mean?  Do
you mean make it so 1*x_monom works, or make it so
int(1)*x_monom does _not_ work?

I don't think 1*x_monom should work because there is no coercion from ZZ to
booleanMonomialMonoid that is defined on the whole of ZZ.   Sage is not
supposed to do any automatic coercions and conversions, except ones that
satisfy a certain list of rules.    This is maybe similar to why the following
isn't defined:

sage: Mod(2,7) * (3/5)
... TypeError

> I also need to have the functionality to add two BooleanMonomials, and
> get a BooleanPolynomial.

But the monoid of BooleanMonomials doesn't have an addition operation,
so why should one add them?  It's only when elements of that monoid
are viewed as monomials in a ring that it even makes sense to add them.

Why are you distinguishing between x and x_monom here?

sage: P.<x,y> = BooleanPolynomialRing(2)
sage: M = P._monom_monoid
sage: x_monom = M(x);

That would be like distinguishing between two views of x here:

sage: P.<x,y> = QQ[]
sage: x_monom = some_other_version_of_(x).

which we don't do.

Anyway, I hope Robert Bradshaw will comment on your email too,
since he mainly designed the current coercion model.   Also, maybe
I'm being too restrictive or unimaginative, because of my having
"grown up in the world of Magma".

  --  William

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



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~---------~--~----~------------~-------~--~----~
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/
-~----------~----~----~----~------~----~------~--~---

Reply via email to