On Wed, Aug 19, 2009 at 6:30 AM, Harald Schilly<harald.schi...@gmail.com> wrote: > > here is another "report a problem" message from the notebook > interface. It's not a bug (i think) but it gives insight in how Sage > is used and over what users stumble when using it for simple things. > > ------------------ > This doesn't work: > > var('k') > u = 1 + k > k = 1 > u.n() > ------------------ > It is maybe not a bug, but I would expect it to give the same as > > var('k') > k = 1 > (1+k).n() > > I think that .n() should try to evaluate the expression before to > throw an exception. > ------------------ > > Comment: > I think n() could be made more intelligent in a way that it searches > the globals()? Or not .n(), but a new method ".evaluate()" or > something that does this? Any ideas? Just u.subs(globals()) didn't > work for me.
I think it would be bizarre and wrong to change the behavior of n at all from what it currently is. I think this question has nothing to do with n. The user wants the following: sage: var('k') sage: u = 1 + k sage: k = 1 sage: u to output 2. If Sage or Python were to do that, I would consider it crazy and terribly broken. When I write "u = 1+k", I'm making u into the symbolic expression "1+k" with k a symbolic variable. When I wrote "k=1", I'm binding the k in the current namespace to point to the integer 1. This better not change u; changing u would be utterly insane. I've never seriously used any programming language that would be that bad. They do exist though. Since Python isn't such a (bad!) language, we don't really have to discuss this further. However, for fun here are some examples for comparison: PARI -- behaves the same as Python: ? u = 1 + k; u %1 = k + 1 ? k = 1 %2 = 1 ? u %3 = k + 1 MATHEMATICA: In[1]:= u := 1 + k; u Out[1]= 1 + k In[2]:= k := 1; In[3]:= u Out[3]= 2 MAGMA: > R<k> := PolynomialRing(RationalField()); > u := 1 + k; u; k + 1 > k := 1; > u; k + 1 MAPLE: > u := 1+k; u := 1 + k > u; 1 + k > k := 1; k := 1 > u; 2 LISP -- it's popular these days suddenly :-) [1]> (setq u 'k+1) K+1 [2]> u K+1 [3]> (setq k '1) 1 [4]> u K+1 MAXIMA: (%i1) u : k+1; (%o1) k + 1 (%i2) u; (%o2) k + 1 (%i3) k : 1; (%o3) 1 (%i4) u; (%o4) k + 1 Wow, that's pretty interesting. So Maple and Mathematica also have the (bizarre) semantics the user wants, but no other language I tested does, including Maxima. This would thus be a very useful thing to add to the Sage tutorial, as users coming over from Maple and Mathematica *should* expect this weird semantic, since it is what they learned and are used to. We should have exactly this example to illustrate this subtle point. <flamebait> The computer scientist in me just can't believe Maple and Mathematica are designed that way. It's just sad. </flamebait> -- William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---