On Thu, Aug 28, 2008 at 9:20 AM, John Cremona <[EMAIL PROTECTED]> wrote:
>
> Thanks for your comments, David.  I am having some success:
>
> sage: A = AbelianGroup([2,3])
> sage: A.list()
> [1, f1, f1^2, f0, f0*f1, f0*f1^2]
> sage: A = AbelianGroup([2,3],operation='+')
> sage: A.list()
> [0, f1, 2*f1, f0, f0+f1, f0+2*f1]
>
> sage: A = AbelianGroup([2,3], names='ab')
> sage: A.list()
> [1, b, b^2, a, a*b, a*b^2]
> sage: A = AbelianGroup([2,3],names='ab',operation='+')
> sage: A.list()
> [0, b, 2*b, a, a+b, a+2*b]
>
> The one thing I cannot get to work in the additive case is  (for
> example) 2*g where g is a group element.  I have tried all possible
> combinations of __lmul__, _lmul_, __rmul__, _rmul_, but although I
> have this ok:
>
> sage: a,b=A.gens()
> sage: b._lmul_(20)
> 2*b
> sage: 2*b
>
> inputting 20*b gives an error:
> TypeError                                 Traceback (most recent call last)
>
> /home/john/sage-3.1.final/<ipython console> in <module>()
>
> /home/john/sage-3.1.final/element.pyx in
> sage.structure.element.RingElement.__mul__
> (sage/structure/element.c:9190)()
>
> /home/john/sage-3.1.final/coerce.pyx in
> sage.structure.coerce.CoercionModel_cache_maps.bin_op
> (sage/structure/coerce.c:6288)()
>
> TypeError: unsupported operand parent(s) for '*': 'Integer Ring' and
> 'Additive Abelian Group isomorphic to C2 x C3'
>
> Maybe someone who understands coercion can tell me how to get around this?


Again, I'm not one who actually understand this, but I have some
comments anyway:-)

I had the same problem in the Piecewise class. For a long time,
if

sage: f1(x) = 1
sage: f2(x) = 1 - x
sage: f = Piecewise([[(0,1),f1],[(1,2),f2]])

then f*2 would work but 2*f would break. Then C Boncelet suggested how
to fix this,
and now (SAGE Version 3.1.2.alpha1) it works like a charm:

sage: 2*f
Piecewise defined function with 2 parts, [[(0, 1), x |--> 2], [(1, 2),
x |--> 2*(1 - x)]]

If you think this will help with your problem, see
http://trac.sagemath.org/sage_trac/ticket/3655



>
> John
> 2008/8/28 David Joyner <[EMAIL PROTECTED]>:
>>
>> Since no one has emailed intelligent comments yet, I'll add my own
>> not-so-intelligent but hopefully encouraging ones below:-)
>>
>> On Wed, Aug 27, 2008 at 3:18 PM, John Cremona <[EMAIL PROTECTED]> wrote:
>>>
>>> Currently in Sage, AbelianGroups are all multiplicative.  There's a
>>> TODO in abelian_groups.py which asks to implement additive groups.
>>>
>>> As I got fed up with this sort of thing:
>>>
>>> sage: E=EllipticCurve('11a1')
>>> sage: T=E.torsion_subgroup()
>>> sage: list(T)
>>> [1, P, P^2, P^3, P^4]
>>>
>>> (where it should be something like [0,P,2*P,3*P,4*P] ),  I started to
>>> try to adapt abelian_group.py to allow for multiplicative groups.
>>> I had some success (after changing just that file, all the original
>>> doctests still passed, since I had it take the group operation to be
>>> multiplication by default).
>>
>> Agreed, this definitely needs fixing.
>>
>>>
>>> But then I found that AbelianGroupElement was derived from
>>> MultiplicativeGroupElement which in turn is derived from
>>> MonoidElement, while AdditiveGroupElement is derived from
>>> ModuleElement.  These two do  have a common ancestor, plain Element.
>>> I think will make it hard to write common code for additive group
>>> elements and multiplicative group elements.
>>
>>
>> I don't see the problem here. It seems to me that the only
>> problem would arise if you are building a method which maps a
>> group (G,*) to a group (G,+) (in which case maybe you get something
>> circular), but I don't see why this is needed. I may be totally naive about 
>> this
>> though.
>>
>>>
>>> I think it might work to use MultiplicativeGroupElement even when the
>>> operation is addition, but that would seem rather perverse.  But it is
>>> perhaps notable that AdditiveGroupElement is hardly ever used in Sage:
>>> the only places are ine the definition of EllipticCurvePoint_field and
>>>  JacobianMorphism_divisor_class_field.
>>>
>>> I would welcome some comments on what we might do about this.  In the
>>> meantime I'll try to get AbelianGroupElements to behave additively
>>> even though they are derived from MultiplicativeGroupElements.
>>
>>
>> I'm not convinced this is the "right" procedure, but if it works and
>> is well-documented
>> then that is better than nothing!
>>
>>
>>>
>>> Relevant still-open tickets are:
>>>
>>> #1849: [with patch (part 1 of 2); not ready for review] rewrite abelian 
>>> groups
>>>  -- showing that William did a whole lot of work on this back in
>>> January/February (I remember, we were working in the same room at the
>>> time) which was not completed;
>>>
>>> and
>>>
>>> #3127: [duplicate] abelian groups (are lame?) -- bug in comparison of
>>> subgroups ...
>>> -- which is closed, but contains the comment from William:
>>> WARNINGS:
>>>
>>>   1. David Roe is recently rumored to be rewriting abelian groups.
>>>   2. I recently rewrote abelian groups but my patch rotted: #1849
>>>   3. There are other known problems with subgroups of abelian groups: #2272
>>>
>>>
>>> John
>>>
>>> >
>>>
>>
>> >
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
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://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to