Mike,
Thanks for the help - much appreciated! On Dec 3, 9:30 pm, "Mike Hansen" <[EMAIL PROTECTED]> wrote: > If you just need to substitute, you can do: > > sage: m.subs(x=1) > [-1 -1] > [-1 0] > > If you want to apply a more general map to the coefficients, then you can do: > > sage: m.apply_map(lambda e: e.subs(x=1)) > [-1 -1] > [-1 0] > Is there some easy way I could have figured out that m would respond to the message `apply_map'? (Or whatever messages are called in the post-Smalltalk era.) > > 3) How do I get access to maxima's ratsimp? > > sage: n = m.apply_map(lambda e: e.rational_simplify()); n > [ -1/(x^2 + x - 1) -x/(x^2 + x - 1)] > [ -x/(x^2 + x - 1) (x - 1)/(x^2 + x - 1)] > sage: n.subs(x=1) > [-1 -1] > [-1 0] Here's an issue: ((x^2-1)/(x-1)-x).rational_simplify() yields 1. ((x^2-1)/(x-1)-x).rational_simplify().rational_simplify() also yields 1, which is gratifying. However, 1.rational_simplify() causes an error. The explanation is that type(((x^2-1)/(x-1)-x).rational_simplify()) is <class 'sage.calculus.calculus.SymbolicConstant'> whereas type(1) is <type 'sage.rings.integer.Integer'> To me, this points out a problematic feature of implementing something like ratsimp through messages, rather than defining a function called ratsimp Presumably I don't want to encumber the definition of integers with code telling how to respond to the message rational_simplify(). But I would still like an integer to simplify to an integer. I could (and will) define my own function ratsimp that will send its argument the message rational_simplify(), and then do something appropriate if this doesn't work, i.e. if it's a matrix, apply ratsimp recursively to the entries, otherwise just return the argument. But it seems like this could be a more natural and useful way to handle an operation like ratsimp. Maybe the problem is that I just don't have a model yet that would allow me to predict, for example, that to find the length of something I should feed it to the function len, rather than sending it the message len(), whereas if I want to do something to each entry of a matrix, I should send a message apply_map to the matrix, rather than feeding the matrix to a function called apply_map. By the way, Mathematica handles this issue by attaching simplification rules either to a `function' like ratsimp, or alternatively to the object to which the `function' is being applied. Actually,it's not fair to talk about functions, because Mathematica works uniformly according to simplification rules. Which can have all kinds of consequences, many of them useful, and not a few of them potentially very confusing. In this case, ratsimp[1] could cause Mathemica eitther to feed the `argument' 1 to the `function' ratsimp, or else send the object 1 the `message' ratsimp. Users don't need to know or care, as apparently they do in sage. In which case I think it might work better to try to stick with functions rather than messages, where possible. One thing I know I'm going to miss from Mathematica is the loosely binding operator \\, as in f \\ g, which is another way of writing g[f]. This allows you to build up a computation by writing first things first. And because of the loose binding, you can write longcomplicatedexpression \\ ratsimp without fear that ratsimp will stingily only simplify the denominator of the expression. Cheers, Peter --~--~---------~--~----~------------~-------~--~----~ 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/ -~----------~----~----~----~------~----~------~--~---