On 4/16/07, Gary Bunting <[EMAIL PROTECTED]> wrote:
>
> I have been trying to use some of my python code in sage but
> have been having problems, apparently because sage implements
> generic arithmetic differently to python.

Hi Gary,
The SAGE preparser is your problem. If you run the preparser on the
line you just typed, you'll notice that it is treated as
{{{
sage: preparse( 'MyList([1,2,3])')
 'MyList([Integer(1),Integer(2),Integer(3)])'
}}}

So instead of working with normal int's, you're working with SAGE's.
If you want to work with normal int's you could:
* append an "r" ("r" stands for "raw") to each number (faster):
{{{
sage: x = MyList([1r,2r,3r])
sage: 10r*x
 [10, 20, 30]
}}}

This is preparsed as:
{{{
sage: preparse(' MyList([1r,2r,3r])')
 ' MyList([1,2,3])'
}}}


* explicitly call the int() constructor on each number (slower):
{{{
sage: x = MyList([int(1),int(2),int(3)])

sage: int(10)*x
 [10, 20, 30]
}}}

which is preparsed as:
{{{
sage: preparse(' MyList([int(1),int(2),int(3)])')
 ' MyList([int(Integer(1)),int(Integer(2)),int(Integer(3))])'
}}}


Hope that clarifies things for you,
didier

--~--~---------~--~----~------------~-------~--~----~
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-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to