On Tue, Mar 25, 2008 at 10:54 PM, Jay Pottharst <[EMAIL PROTECTED]> wrote:
>
>  Hi all, I'm having trouble adding two modular forms together,
>  sometimes.  Here is a whittled-down demo case:
>
>  sage: b=CuspForms(22).basis()
>  sage: sum(b)
>  Traceback (most recent call last):
>  ...
>  NameError: global name 'other' is not defined
>
>  The following also doesn't work:
>
>  sage: ssum=0
>  sage: for u in b:
>  ...     ssum=(ssum+u)
>  ...
>  Traceback (most recent call last):
>  ...
>  TypeError: unsupported operand parent(s) for '+': 'Integer Ring' and
>  'Cuspidal subspace of dimension 2 of Modular Forms space of dimension
>  5 for Congruence Subgroup Gamma0(22) of weight 2 over Rational Field'
>
>  So there are probably at least two different issues.  For the record:
>
>  sage: b[0]+b[1]
>  q + q^2 - q^3 - 4*q^4 + q^5 + O(q^6)
>
>  Is this my doing?  Is there a work-around at present?

The workaround is to specify the first term in the summation as an optional
argument to sum:

sage: b=CuspForms(22).basis()
sage: sum(b[:1], b[0])
2*q - 2*q^3 - 4*q^4 + 2*q^5 + O(q^6)
sage: b=CuspForms(54).basis()
sage: len(b)
4
sage: sum(b[:1], b[0])
2*q + O(q^6)
sage: b=CuspForms(54,prec=20).basis()
sage: sum(b[:1], b[0])
2*q - 2*q^7 - 4*q^10 - 2*q^13 + 4*q^16 - 2*q^19 + O(q^20)

Note that

  b[0] + 0

and

  0 + b[0]

should *not* work, since in each case that's a canonical coercion,
and there is no natural map from ZZ (the parent of 0) into CuspForms(...)
for any weight except 0.   In Sage coercions should not happen automatically
unless they are in some way natural and well defined on the whole domain
of the coercion (in this case ZZ).

There are some canonical coercions that one *should* have in the context
of modular forms that aren't there, probably partly because this whole
"canonical
coercions" business was after I wrote the modular forms code.  Here's
an example bug (=lack of a coercion that should be there):

sage: b=CuspForms(22).basis()
sage: sum(b, b[0].parent()(0))
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/Users/was/<ipython console> in <module>()

/Users/was/element.pyx in sage.structure.element.ModuleElement.__add__()

/Users/was/coerce.pyx in
sage.structure.coerce.CoercionModel_cache_maps.bin_op_c()

<type 'exceptions.TypeError'>: unsupported operand parent(s) for '+':
'Modular Forms space of dimension 5 for Congruence Subgroup Gamma0(22)
of weight 2 over Rational Field' and 'Cuspidal subspace of dimension 2
of Modular Forms space of dimension 5 for Congruence Subgroup
Gamma0(22) of weight 2 over Rational Field'
 -- William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@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-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to