>> [EMAIL PROTECTED] (elegant, clear, no matching of brackets)
>
> What does that do?

Sorry!  I didn't want to go into detail unless people didn't already  
know it.

Same as f[data].  Benefit is that you can chain it up really clearly.

[EMAIL PROTECTED]@[EMAIL PROTECTED] is better than f[g[h[x]]]
[EMAIL PROTECTED]@x, x] is better than f[g[h[x], x]


While we're here, there is also @@ (Apply).

g@@f[x] becomes g[x].

The use of that might not be immediately apparent.  Suppose that data  
= {1, 2, 3, 4}.  Then Plus@@data becomes 10.

That is because data = List[1, 2, 3, 4].  Plus@@data becomes Plus[1,  
2, 3, 4] which is 10.


>> f /@ data (good extension of good syntax)
>
> What does that do?

Map[f, data]

f /@ {1, 2, 3} becomes [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]

f /@ g[x, y, z] becomes g[ [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL 
PROTECTED]


>> {#, f[#]}& /@ data (so dirty, so quick, a bit hard on pinky)
>
> What does that do?

Inline declaration of a function, then I mapped it across "data" as  
per above.  Equivalent to
g[x_] := {x, f[x]}
g /@ data

So if f[x_] := x^2,
{#, f[#]}& /@ {1, 2, 3} becomes {{1,1}, {2, 4}, {3, 9}}

Not a killer example.  There might not be a killer example.  I just  
miss it.


>> data /. x_?(# < 0 &) -> 0 (this is perhaps not the killer example)
>
> What does that do?

xpos = data /. x_?(# < 0 &) -> 0

xpos = data, except where an entry is manifestly less than zero,  
replace it with zero



A more useful example to illustrate what I miss would have been

posys = Cases[data, {x_?(# > 0&), y_} -> y]

On entry, data was a list of pairs, like
data = {{-1, 2}, {3, 2}, {5, 2}, {-3, -9}}

on exit, posys is a list of y's that were paired with an x that was  
manifestly positive.

This is useful in algebra too:

Let y = a x^2 + b x + c
Cases[y, _?(FreeQ[#, x]&) ]

returns a list of the terms in y that were free of the symbol x.

>> y == a x^2 + b x + c (so easy to type, so easy to parse by eye)
>
> Here is how to do it in Sage:
>
> sage: implicit_multiplication(True)
> sage: var('x,y,a,b,c')
> (x, y, a, b, c)
> sage: y == a x^2 + b x + c
> y == a*x^2 + b*x + c

Thanks.


>> Probably the thing that makes all that learnable and useable in
>> Mathematica is how a multiple click shows you the structure of your
>> expression.
>
> What do you mean?  Multiple click on what?  What sort of structure?

Suppose that you're looking at an expression and you don't know the  
precedence rules perfectly, and you think you might have made a  
mistake.  In a Mathematica notebook, you can multiple-click to  
discover how an expression is parsed.

y == a x^2 + b x + c

If you click on the first x, it's just like a text editor.

Double click, you select the symbol (x).  Just like a text editor.

Triple-click, you select the expression containing the x.  Because  
raising to a power has higher precedence than multiplication, you get  
x^2 selected.

Four clicks gets the a x^2.

Five clicks gets the  x^2 + b x + c

Six gets you the whole line.

The internal representation of that equation is
Equal[y, Plus[ Times[a, Power[x, 2]], Times[b, x], c]]

so you can see that the "clicking" is working its way out through that  
nest.

It's obvious for expressions like the above that follow rules  
established in high school.  But it works just as well for expressions  
like
data /. x_?(# < 0 &) -> 0

So I can check that my expression does what I think it does without  
running and debugging.

>> The virtuous solution might be to write a "Sage for Mathematica
>> junkies" document.
>
> Definitely that should happen.  Want to do it?  Make it 1 page long
> for starters and put in the wiki.

Yes but I don't know python very well.  I could only write a "Sage for  
Mathematica junkies who don't know Python".  Which is probably more  
useful.  It would be hard to avoid the trap of explaining python too  
much as I go along.

It might start out as my "breakup with mathematica blog" minus some of  
the more personal issues that I've already aired on this list.  I'll  
try to get started.

> But still, Sage should also be made easier to use.

It would drive beginners nuts.  It would be the oil slick in your  
learning curve.

It probably doesn't include the quality of experts' code, it can  
quickly become unreusable and unmaintainable.  But it is just so  
quick.  I genuinely find that sort of syntax useful.

It is probably not a high priority if you're more or less trying to  
follow python philosophy.  That said, I tend to think that geeks take  
pride and pleasure in difficult languages (how else do you explain C+ 
+?!), and having some unnecessarily opaque and powerful syntax  
available might be good for attracting users who can become  
developers, developers, developers.

D





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

Reply via email to