On Dec 17, 2008, at 11:49 AM, David Joyner wrote: > > On Wed, Dec 17, 2008 at 2:41 PM, Simon King <k...@mathematik.uni- > jena.de> wrote: >> >> Dear Sage supporters, >> >> inspired by http://groups.google.com/group/sage-support/ >> browse_thread/thread/729f4a557d970195?hl=en, >> I was playing around with the solve command. >> >> I found two questions: >> 1. How can one add assumptions (such as x>0 or x is an integer)? >> The following does not work: >> sage: assume(x>0) >> sage: solve(x^2-1,x) >> [x == -1, x == 1] >> The Sage Tutorial doesn't mention assumptions in the section about >> solving equations. > > > I don't know the answer
The problem is that maxima ignores the assume command in solving. I don't know if this is intentional behavior or a bug. (%i1) assume(x>0); (%o1) [x > 0] (%i2) solve(x^2-1=0, x); (%o2) [x = - 1, x = 1] Assumptions that something is an integer while solving would be highly nontrivial. Imagine sage: var('a,b,c,n') sage: assume(a, 'integer') sage: assume(b, 'integer') sage: assume(c, 'integer') sage: assume(d, 'integer') sage: assume(n > 2) sage: solve(a^n + b^n == c^n, n) > but if assume doesn't work then I would vote to > deprecate it and replace it by an option such as > > solve(x^2-1,x,assume="x>0") > or > solve(x^2-1,x,options="assume(x>0)") > or something. Then just pass the assume statement to > maxima before the solve statement. Usually I like to avoid using strings to carry more structured mathematical information. I do think solve(x^2-1, x, assume=x>0) wouldn't be a bad thing to support. This all depends on how assumptions are going to be done in the new symbolics. >> 2. Why does it take so long to return the solution dictionary? >> From the solve-docstring: >> sage: ct=cputime() >> sage: time solve([x^2+y^2 == 1, y^2 == x^3 + x + 1], x, y, >> solution_dict=True) >> CPU times: user 0.07 s, sys: 0.00 s, total: 0.07 s >> Wall time: 0.18 s >> [{y: -sqrt(3 - sqrt(3)*I)/sqrt(2), x: (-sqrt(3)*I - 1)/2}, >> {y: sqrt(3 - sqrt(3)*I)/sqrt(2), x: (-sqrt(3)*I - 1)/2}, >> {y: -sqrt(sqrt(3)*I + 3)/sqrt(2), x: (sqrt(3)*I - 1)/2}, >> {y: sqrt(sqrt(3)*I + 3)/sqrt(2), x: (sqrt(3)*I - 1)/2}, >> {y: -1, x: 0}, >> {y: 1, x: 0}] >> sage: cputime(ct) >> 2.6121629999999989 >> >> So, for computing the solutions 0.07 CPU-seconds suffice, but for >> printing them 2.6 CPU-seconds are needed?? cputime only measures the time of the Sage process (formatting the equations, feeding them to maxima, and parsing and printing the result). The forked maxima process, which is actually doing all the work in this example, takes the rest. As for printing, I'm not sure what's taking so long (simplifying each result individually?), but it shouldn't. sage: time soln = solve([x^2+y^2 == 1, y^2 == x^3 + x + 1], x, y, solution_dict=True) CPU times: user 0.02 s, sys: 0.01 s, total: 0.03 s Wall time: 0.14 s sage: print soln # fast sage: str(soln) # fast sage: repr(soln) # fast sage: soln # slow !? - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---