On Oct 8, 4:21 am, "ma...@mendelu.cz" <ma...@mendelu.cz> wrote:
> Hello all
>
> Trying to fixhttp://trac.sagemath.org/sage_trac/ticket/2617
>
> My idea is to write wrapped for maxima solve command which
> * passes equations to maxima within errcatch environment (to prevent
> errors from solve(acot(x)==0,x) )
> * optionally does either nothing more,
>   or (default) plugs the right hand sides of answers in the form
> x=independent_on_x  into equation(s),
>   or optinally checks that the equations are true (this would 
> fixhttp://trac.sagemath.org/sage_trac/ticket/3745)
>
> this would return
> sage:solve(x*ln(x)*(x-1),x, check='domains')
> [x==1]
>
> sage:solve(x*ln(x)*(x-1),x,check='none')
> [x==0, x==1]
>
> and would remove incorrect solutions from trac 3745
>

Incidentally, there is another trac ticket for checking whether
solutions fulfill assumptions, since Maxima's solve does not, and is
not planning to do so.

> I was supprised that
> sage: maxima("solve(x*log(x)-x-sin(x)=0,x)")
> [x=sin(x)/(log(x)-1)]
>
> has very very different output to
>
> sage: solve(x*log(x)-x-sin(x)==0,x)
> [x == r27, x == r25]    ---- ugh!
>

No, this is exactly what we DO want, just not in that form (i.e.,
there is a one-character bug in Sage making that happen).  See below
about topoly_solver versus to_poly_solver, and ticket # 6642.

> so I was looking for definition of solve in /home/sage/sage_install/
> sage-alpha/local/lib/python2.6/site-packages/sage/symbolic/relation.py
> (worked on uw.sagenb.org)
>
> where everything seems to be done in m.solve(variables)   so I looked
> for .solve method.
>
> Doing
> m=maxima(something)
> m.solve??
>

You are correct that everything is in m.solve.  That means we go to
the Maxima console!

sage: maxima_console()
<snip>
Maxima 5.19.1 http://maxima.sourceforge.net
Using Lisp ECL 9.8.4
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) ? solve;

 -- Function: solve (<expr>, <x>)
 -- Function: solve (<expr>)
 -- Function: solve ([<eqn_1>, ..., <eqn_n>], [<x_1>, ..., <x_n>])
     Solves the algebraic equation <expr> for the variable <x> and
     returns a list of solution equations in <x>.  If <expr> is not an
     equation, the equation `<expr> = 0' is assumed in its place.  <x>
     may be a function (e.g. `f(x)'), or other non-atomic expression

etc.

So here is what happens in Sage.  One reason this is hard to see is
because the Traceback does not report much on Expression.solve(),
because that is located in a .pyx file (very, very annoying - I assume
that is not fixable?).

1) User calls solve.

2) Solve determines whether there is one equation or multiple
equations (later on, simple expressions get replaced by ex == 0).

3) Either way, we essentially directly call Maxima solve with nearly
the same syntax; the string is quite similar, I think that symbolic/
expression_conversions.py is part of it, though we really only have to
change == to = and a few other things.  Also, maxima._eval_line
appends ';' and does one or two other things.

4) If there is one equation, it calls Maxima solve.
a) It gets an answer.
b) If the answer is still an equation (such as [x=sin(x)/(log(x)-1)] )
we try to do better.  Currently, this is automatic, using the old
Maxima package topoly_solver; post-6642, which hopefully jhpalmieri
will be able to give positive review to any second (currently doctests
running, I think), it will use the much improved package
to_poly_solver, via a flag to_poly_solve=True.  The change is because
to_poly_solve does not give multiplicities, which Expression.roots()
needs - and because it often gives numerical answers or answers with
parameters, because to_poly_solve calls things like algsys, which have
this behavior.
c) It returns the (possibly improved) answer to the user.

5) If there is more than one equation, it calls Maxima solve.
a) It gets some answers, but these may be numeric, because that is
just what Maxima solve does for more than one equation.  There is no
way around this, because it calls things in Maxima like algsys for
this, which has this behavior.
b) It returns the answers.  Multiplicities are not an option here,
only for one equation.

But as far as what is passed to Maxima, it is quite straightforwardly
nearly the identical syntax to what we put in solve.

In the case you report, topoly_solve reports the weird answer you got,
while to_poly_solve reports an error (because it doesn't know how to
solve it).  Were you expecting something symbolic (I get
sage: find_root(x*ln(x)-x-sin(x),2.5,3)
2.9252520907402371
for numeric).
Anyway, this is because solve already would have gotten the symbolic
"solution" of just the equation back, that is what Sage should report,
post # 6642.  Incidentally, if you had a typo and meant
(%i5) solve(x*log(x)-x*sin(x),x);
(%o5)                      [x = 0, sin(x) = log(x)]
This is what Sage will report, post # 6642.

The developer of to_poly_solver, Barton Willis, has been making quite
a few improvements and bugfixes lately, and so the next time we
upgrade Maxima (hopefully that will be relatively soon) we will have
even better functionality.

Please let me know if this doesn't cover it all!

Best,
- kcrisman

> does not show anything resonable for me. Also I was not able to find
> anything resonable in he file interfaces/maxima.py
>
> Where can i digg out the string which actually is passed to Maxima?
> And do you think that the described method to solve the problem is a
> good idea?
> I did something like this for scalar case in MAW, you can try for
> example function calculator 
> athttp://user.mendelu.cz/marik/maw/index.php?lang=en&form=derivace
>
> Robert Marik
--~--~---------~--~----~------------~-------~--~----~
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
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to