On Jul 12, 2009, at 2:49 PM, Kevin Horton wrote:

>
> Carlos Córdoba wrote:
>> Thanks for your quick answers. Coming from Mathematica, I was  
>> expecting to
>> add lists as vectors, multiply real numbers by lists, etc, without
>> sub-classing or using another types (such as vectors in sage)

Sage lists are Python lists, which are very different than  
Mathematica lists. What you really should use here is a vector.

>> Do you advise me to add things to the preparser to have this  
>> behaviour or
>> not? If so, how can I do it?

In general, we try to avoid modifying the preparser as much as  
possible. Sometimes, we really have to

sage: eval("1/2 + 3^2")
1

is really not acceptable (IMHO) for a serious alternative to other  
systems out there, but lists are very useful data structures in their  
own right an to change all lists would be a massive (backwards- 
incompatible) change, as well as another step away from Python.

> You might get some of the functionality you want by using numpy  
> arrays.

Of course, we support all of this without numpy as well.

sage: a0 = vector([1,2,3,4])
sage: a0 * 5
(5, 10, 15, 20)
sage: a0 * / 2
sage: a0  / 2
(1/2, 1, 3/2, 2)
sage: a0.norm()
sqrt(30)

>
> sage: import numpy
> sage: a0 = numpy.array([1,2,3,4])
> sage: a0
> array([1, 2, 3, 4], dtype=object)
>
> sage: a1 = numpy.array([5,6,7,8])
> sage: a0+a1
> array([6, 8, 10, 12], dtype=object)
>
> sage: a0*2.5
> array([2.50000000000000, 5.00000000000000, 7.50000000000000,
>        10.0000000000000], dtype=object)
>
> sage:
> a0*a1
> array([5, 12, 21, 32], dtype=object)
>
> numpy and sage don't cooperate perfectly at the moment, as numpy does
> not accept sage's native types.  But, there are workarounds:
>
> http://wiki.sagemath.org/faq#Typeissuesusingscipy. 
> 2CcvxoptornumpyfromSage
>
> This situation may be resolved in sage-4.1.1, assuming a recently
> developed patch survives the referee process.
> --
> Kevin Horton
>
> >


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to