On Wed, 26 Mar 2008 17:04:10 -0700, Hector Villafuerte <[EMAIL PROTECTED]> wrote:
> > Hi, > While trying to compute the Golden ratio using SAGE I noticed the > following strange (to me) behavior in solve(). > > * This fails: > > sage: var('a b phi') > (a, b, phi) > sage: solve([phi==a/b, phi==(a+b)/a], phi) > --------------------------------------------------------------------------- > <type 'exceptions.ValueError'> Traceback (most recent call last) > > /Users/hector/sage/<ipython console> in <module>() > > /Users/hector/sage/local/lib/python2.5/site-packages/sage/calculus/equations.py > in solve(f, *args, **kwds) > 1215 s = m.solve(args) > 1216 except: > -> 1217 raise ValueError, "Unable to solve %s for %s"%(f, args) > 1218 a = repr(s) > 1219 sol_list = string_to_list_of_solutions(a) > > <type 'exceptions.ValueError'>: Unable to solve [phi == a/b, phi == (b > + a)/a] for (phi,) > > > * This succeeds (note the (unnecessary?) need to also solve for 'a') > > sage: solve([phi==a/b, phi==(a+b)/a], phi,a) > [[phi == (1 - sqrt(5))/2, a == -2*b/(sqrt(5) + 1)], [phi == (sqrt(5) + > 1)/2, a == 2*b/(sqrt(5) - 1)]] > > > Where the Golden ratio is phi == (sqrt(5) + 1)/2. So, am I missing > something fundamental in the way solve() works or is this a bug? > Thanks! Some comments: (1) A simpler way to use solve to find the golden ratio is: sage: var('phi') phi sage: solve(phi==1+1/phi, phi) [phi == (1 - sqrt(5))/2, phi == (sqrt(5) + 1)/2] (2) If it's a bug, then it's a bug in Maxima. You may want to look at the Maxima docs for solve. Here's what happens doing things like the above directly in Maxima: (%i4) solve([phi=a+b,phi=a+b], phi); Dependent equations eliminated: (2) (%o4) [[phi = b + a]] (%i1) solve([phi=a/b,phi=a+b], phi) ; Maxima encountered a Lisp error: CAR: 2 is not a list Automatically continuing. To reenable the Lisp debugger set *debugger-hook* to nil. (%i2) solve([phi=a*b,phi=a+b], phi); Maxima encountered a Lisp error: CAR: 2 is not a list Automatically continuing. To reenable the Lisp debugger set *debugger-hook* to nil. (%i3) solve([phi=a-b,phi=a+b], phi); Maxima encountered a Lisp error: CAR: 2 is not a list Automatically continuing. To reenable the Lisp debugger set *debugger-hook* to nil. -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org --~--~---------~--~----~------------~-------~--~----~ 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://www.sagemath.org -~----------~----~----~----~------~----~------~--~---