On Dec 7, 2007 10:39 PM, pgdoyle <[EMAIL PROTECTED]> wrote:
> > Please quite loudly tell us *everything* you are going to miss from
> > Mathematica.  We want to know!
> >
>
> I can tell some things that I know how to do in Mathematica but don't
> know how to do in sage.
> Here are two such for starters.
>
> 1.  ListPlot
> http://reference.wolfram.com/mathematica/ref/ListPlot.html
>
> The function ListPlot plots a list of numbers, or ordered pairs of
> numbers.  So to illustrate the central limit theorem
> we can simply write:
>
> Table[Sum[Random[],{10}],{1000}]//Sort//ListPlot
>
> This generates 1000 sums X_1+...+X_10, with X_i uniform in the unit
> interval; sorts these sums; and then plots the resulting list,
> giving a very convincing graph (turned on its side) of the cumulative
> distribution for a Gaussian random variable.

In Sage you use the command "list_plot".  The person -- Alex Clemesha -- who
wrote the 2d plotting interface in Sage really likes Mathematica, so he
modeled much of the plotting on the function names in mathematica.
To do the above example in Sage, do this:

sage: show(list_plot(sorted([sum([random() for _ in [1..10]]) for _ in
[1..1000]])))

> 2.   Listable
> http://reference.wolfram.com/mathematica/ref/Listable.html
>
> The attribute Listable enables automatic threading over lists,
> including nested lists and specifically matrices.
>
> In[15]:= N[{{1,2},{3,4}}]
>
> Out[15]= {{1., 2.}, {3., 4.}}
>
> In[16]:= Log[{{1,2},{3,4}}]
>
> Out[16]= {{0, Log[2]}, {Log[3], Log[4]}}
>
> In[24]:= barf[{{1,2},{3,4}}]
>
> Out[24]= barf[{{1, 2}, {3, 4}}]
>
> In[25]:= SetAttributes[barf,Listable]
>
> In[26]:= barf[{{1,2},{3,4}}]
>
> Out[26]= {{barf[1], barf[2]}, {barf[3], barf[4]}}
>

I think Sage doesn't have that exactly, though
you can do something similar with matrices:

sage: v = matrix([[1,2], [3,4]])
sage: v.apply_map(N)
[1.00000000000000 2.00000000000000]
[3.00000000000000 4.00000000000000]

sage: matrix([[1,2],[3,4]]).apply_map(log)
[     0 log(2)]
[log(3) log(4)]

I think it would be pretty easy to write a Python function that
does what you describe above though, and add it to sage.
It could be called map_thread, since Python has a map function
and this would just be an extension of it:

sage: map(log, [1,2,3,e])
[0, log(2), log(3), 1]

sage: map_threaded(log, [[1,2], [3,e]]   # pseudo-code
[[0, log(2)], [log(3), 1]]

OK, actually this was easy to write in one line:

def map_threaded(function, sequence):
    return [map_threaded(function, x) if isinstance(x, (list, tuple))
else function(x) for x in sequence]

(This will go into Sage soon unless there are big objections -- I
agree that it seems
like a very useful thing to have for amthematics!)

Sorry if this is too obfuscated -- i.e., using a conditional
expression and list comprehension --
all this talk of Mathematica is making me prone to write incomprehensible code!

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

Reply via email to