On Sep 10, 2009, at 9:10 AM, Jason Grout wrote: > I was working on a calculus tutorial/primer on Sage yesterday > (http://sagenb.org/home/pub/791/). I realized how annoyed I get with > always having to specify the solution_dict parameter to solve in order > to substitute values back into another expression. Almost every > time I > use solve, I immediately substitute the values back into some other > expression. Having to write solution_dict=True all the time is (a) > hard > to remember and (b) inconvenient. Part of the reason for (a) is > that I > think "solution_dict" is a long and not very obvious name (I think I > wrote the solution_dict patch, so it's my fault! Sorry for the bad > name!). > > Somewhere, a while ago, I remember there being a consensus (with small > voter turnout) that solution_dict should default to True (I can't find > the thread on this, though). That is effectively what Mathematica > does, > for example. Mathematica returns a list of rules, which print as > {x->3, > y->4}, and which are very easy and natural to substitute back into > other > expressions. > > I wonder if we could either: > > (a) make solution_dict default to True (and maybe transition to some > sort of better-named keyword argument?)
It would need to be more robust when it can't actually solve things: sage: solve([x==sin(x)], x, solution_dict=True) ------------------------------------------------------------ Traceback (most recent call last): File "<ipython console>", line 1, in <module> File "/Users/robert/sage/sage-4.0/local/lib/python2.6/site- packages/sage/symbolic/relation.py", line 509, in solve sol_dict=[dict([[eq.left(),eq.right()] for eq in solution]) for solution in sol_list] TypeError: 'sage.symbolic.expression.Expression' object is not iterable > * this may break lots of code, so maybe ought to be put off > until 5.0. > > (b) make .subs() and maybe the __call__ method of a symbolic > expression > take the output of solve as-is and try to do something intelligent > (i.e., see if the lhs of each equation is a single variable, and > substitute in the right side) > > What do you think? I say go we should do (b) whether or not we do (a), but perhaps only if the rhs does not contain the variables of the lhs. - Robert --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---