On Aug 21, 7:50 pm, "William Stein" <[EMAIL PROTECTED]> wrote: > On Thu, Aug 21, 2008 at 4:41 PM, David Philp <[EMAIL PROTECTED]> wrote: > > > I don't know how much of the below is possible or available in Sage. > > But I miss they syntax from Mathematica. I love the fact that it > > doesn't wear down the little fingers on your right hand.
Does that mean that you can write lots of one liners? If so, it's definitely true, but perhaps even to a fault. I see that David Philips has already answered all these questions, but see the list comprehension equivalents in my answers below > > [EMAIL PROTECTED] (elegant, clear, no matching of brackets) > > What does that do? Shortcut for f[data], so that you don't need the brackets. > > f /@ data (good extension of good syntax) > > What does that do? Shortcut for Map[f,data], so if data = {d1,d2,d3}, f /@ data produces {f[d1],f[d2],f[d3]} sage: [f(d) for d in data] > > {#, f[#]}& /@ data (so dirty, so quick, a bit hard on pinky) > > What does that do? {#,f[#]}& is a pure function, and /@ is still map, so taking data as above, this gives {{d1,f[d1]},{d2,f[d2]},{d3,f[d3]}}, which is perfect as input to Table or ListPlot sage: [[d,f(d)] for d in data] > > data /. x_?(# < 0 &) -> 0 (this is perhaps not the killer example) > > What does that do? /. is the pattern replacement operator, _ is a placeholder pattern that matches anything, x_ gives this placeholder a name so you can use it later, ? filters the matches (in this case, everything matches) with the pure function # < 0&, which takes one argument and returns true if the argument is less than 0, and the -> 0 part says anything that made it through the filter gets set to 0. So In[40]:= data = {-1, 2, 3}; In[41]:= data /. x_?(# < 0 &) -> 0 Out[41]= {0, 2, 3} In other words sage: data = [-1,2,3] sage: [(d < 0 and [0] or [d])[0] for d in data] [0,2,3] I haven't been using python long enough to think this one is nice, but Mark Pilgrim says it's cool: http://diveintopython.org/power_of_introspection/and_or.html#d0e9975 Don't forget @@, /@@, @@@, /:, /;, //., :>, and all the rest. The documentation center: http://reference.wolfram.com/mathematica/guide/Mathematica.html explains what all these mean. I love to write one liners like that in Mathematica (and only sometimes do I dislike reading them later). I'm glad they're in Mathematica, but please don't put them in Sage. List comprehensions FTW! > > 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 > > 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? You can write seriously nested stuff in Mathematica, so this is a mechanism to help you sort it out. Each time you click your mouse on a selected part of an expression, your selection expands out one level of nesting. Great for seeing how things are grouped. The live syntax highlighting in Version 6 has made Mathematica much much more useable for me. Live syntax highlighting in the notebook would rock. They payed serious attention to detail with syntax visual aids, and it's worth studying if you can. As for my requests, see http://groups.google.com/group/sage-devel/browse_thread/thread/74a5b645fd866eb8 . I also really like the With statement, which you use to temporarily set variables in a block. A trivial example is With[{k=3}, Plot[Sin[k*x],{x,-2,2}]] This comes in pretty handy for plugging in values of parameters in a way that leaves the general structure of expressions clear. How 'bout a @with(k=3) decorator? Regards, JM > > 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. > > But still, Sage should also be made easier to use. > > I really want to know the answers to all the questions above. > > William --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---