Mike Hansen wrote:
>> It means 5.+N applied to 5.85987.  (In Mathematica f[x] is how you
>> would express applying f to x).
> 
> I think what confusing is the following:
> 
> In[1]:= Pi // N
> Out[1]= 3.14159
> In[2]:= Pi // N + 2
> Out[2]= (2 + N)[Pi]
> 
> What does it mean in Mathematica to add 2 to N?  Does it just treat N
> as a formal symbol when you add 2 to it N?

I believe that is right, it is treating N as a formal symbol.  We 
discussed things like this when you wrote the patch to handle stuff like 
(sin+1)(x), I believe.  Literally, Mathematica views the above as 
Plus[2,N][Pi] (i.e., the plus function applied to 2 and the symbol N, 
applied then to Pi):

In[2]:= Pi // N+2 // FullForm

Out[2]//FullForm= Plus[2, N][Pi]


In practice, I have never used something like Pi//N+2.  I've always used 
the // operator with a function (or a lambda function) following it:

Pi // N[#,20]&

creates a lambda function, where # represents the argument and the & 
marks the end of the function definition.  This would print Pi out to 
20-digit precision.

Using // also works very nicely as chains of function applications 
(i.e., composition with postfix notation).  It's very natural to me to 
think of taking an object, then doing this to it, then doing that to the 
result, etc.  As a contrived example:

(x^2 - 2)^2 // D[#, x] & // Solve[# == 0, x] &

takes (x^2-2)^2, takes the first derivative with respect to x, and then 
solves for where that derivative is equal to zero.  To have the same 
flow in Sage, we could write:

((x^2-2)^2).diff().solve('x')

This works fine if you have member functions diff and solve, but if you 
don't or want to apply your own function, you can't use this postfix-ish 
style.


This postfix notation is something I've found extremely convenient in 
Mathematica and is something that I miss a lot as well.  I find that it 
is easier to experiment and try new things when I can build up an 
expression bit by bit by appending new operations.

I've resolved in my mind that we can do the same sort of thing in Sage 
by just creating an object and acting on it on successive lines.  It 
doesn't feel as fast or as natural, but it's probably more readable and 
maintainable in the end.


This issue has also come up before on the mailing list, where someone 
mentioned that they missed being able to do a long calculation and then 
double-checking the algebraic result by just putting a "// N" at the 
very end.  They concluded that in Sage, enclosing the entire thing in 
parentheses and putting ".n()" (to call the numeric approximation 
function) was almost as easy.

It would be nice if we had a way to invoke a function with prefix or 
postfix notation in Sage.  Whether or not this breaks too far from 
python syntax should probably be discussed, though.

-Jason


--~--~---------~--~----~------------~-------~--~----~
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