>
> By the way, the numerical answers you got are very bad, but Maxima is
> not a numerical analysis package. The way to get good numerical roots
> is:
> sage: pari('x^5+x^3+17*[x + (0.0588115223184494 + 0.E-38*I), 1; x +
> (-1.36050567903502 +
> 1.51880872209965*I), 1; x + (1.33109991787580 + 1.52241655183732*I),
> 1;
> x + (-1.36050567903502 - 1.51880872209965*I), 1; x + (1.33109991787580
> -
> 1.52241655183732*I), 1]x+1+0.*I').factor()
>
Or using Sage interval arithmetic:
sage: R.<x>=QQbar[]
sage: a=(x^5+x^3+17*x+1)
sage: a.roots()
[(-0.05881152231844944?, 1),
(-1.331099917875796? - 1.522416551837318?*I, 1),
(-1.331099917875796? + 1.522416551837318?*I, 1),
(1.360505679035020? - 1.518808722099650?*I, 1),
(1.360505679035020? + 1.518808722099650?*I, 1)]
Jason
--
Jason Grout
I don't use the solve() function at all. I'm probably missing the
user's point of view completely, so please take what I say below with a
grain of salt.
Going by the "What Would Maple Do" rule, I would like solve() to remain
exact. Looking through the examples here
http://www.maplesoft.com/support/help/view.aspx?path=examples/solve
I couldn't see any cases where Maple switches to numeric results.
I think it's better to return no results if the exact methods don't
work, and point the user to the numeric solver. This is fsolve [1] in
the case of Maple. Is it find_root() in Sage?
[1] http://www.maplesoft.com/support/help/view.aspx?path=fsolve
On Thu, 17 Sep 2009 06:30:19 -0700 (PDT)
kcrisman <kcri...@gmail.com> wrote:
>
> For a frustrated user because of precisely this issue, see
> http://groups.google.com/group/sage-support/browse_thread/thread/6407896aab6a52cc/bfb4e85815ef94a3?show_docid=bfb4e85815ef94a3
> . I now think we should definitely change to having to_poly_solve as
> an option, but not default, even if we miss some solutions that way,
> because it's unlikely that Maxima will be able to change its behavior
> very soon, even if they wanted to.
In this case, I agree that we should make to_poly_solve a non-default
option.
Thanks.
Burcin
Great idea. We can make an alias:
solve_numerical=find_root
Does find_root take general symbolic expressions (i.e., x==x^2)?
Jason
--
Jason Grout
I like the idea of solve(f) attempting to call f.solve(), which would
handle the finite field and numerical cases much nicer. However, it
should probably not be synonymous with roots, as I'd want a
polynomial over RR to return its complex roots as well. (Not sure
what to do about the case above, the answer is pretty useless... IIRC
some systems return an object "roots of ..." which then can be
numerically approximated.
- Robert
> I don't know if there is a way to get at where coefficients of
> elements in SR come from; they all just become symbolic expressions.
> Even with the .coeffs() method, they still end up coming out as
> symbolic expressions. Burcin or others will clarify, but probably the
> idea was that symbolic means just that - symbolic, with no reference
> to other things.
Symbolic expressions keep python objects for numeric values or
coefficients. You can get at the python object wrapped by an expression
using the .pyobject() method and ask for its parent.
sage: t = Mod(3,5)
sage: t.parent()
Ring of integers modulo 5
sage: u = SR(t)
sage: u
3
sage: u.parent()
Symbolic Ring
sage: u.pyobject().parent()
Ring of integers modulo 5
Cheers,
Burcin
That being said, i still don't understand what Symbolic expressions are.
>> sage: t = Mod(3,5)
>> sage: t.parent()
>> Ring of integers modulo 5
>> sage: u = SR(t)
>> sage: u
>> 3
>> sage: u.parent()
>> Symbolic Ring
>> sage: u.pyobject().parent()
>> Ring of integers modulo 5
In this example t is defined over "Ring of integers modulo 5", which
is great, because i heard about this before. It is wrapped in a SR,
for some reason, and afterwards the ring can be retrieved. No problem.
>> Symbolic expressions keep python objects for numeric values or coefficients.
Why is this object accessible to the user?
>Try sage: x.roots? for documentation about specifying rings to solve
>over; most or even all of what you suggest is possible if you do that.
Thanks i wasn't aware of this function, and the functionality is
indeed there. However i disagree if no ring is specified. Here is an
example (see first example x.roots)
------------------
var('x')
x.parent()
OUTPUT: Symbolic Ring
f=(x^2-1)^2
f.pyobject().parent()
OUTPUT: TypeError: self must be a numeric expression
f.parent()
OUTPUT: Symbolic Ring
f.roots()
OUTPUT: [(-1, 2), (1, 2)]
------------------
In the documentation of x.roots:
- ``ring`` - a ring (default None): if not None, convert
self to a polynomial over ring and find roots over ring
------------------
So from a mathematical point of view, it seems that a symbolic ring is
the polynomial ring with ground field determined by the coefficients
(?). Is this consistent with all the functions taking symbolic
expressions without a ring specified?
>If you really want polynomials, you need to do
>something like
>
>sage: R.<x> = CC[]
>sage: x^2+1
>
>and go from there, I think. That is occasionally annoying to those of
>us who primarily teach undergraduates, but essential for many of the
>applications of Sage.
It seems to me that not specifying the ring explicitly is even more
difficult to teach. At least i hope so, because i don't understand it
yet.
As i understand "solve" differs from "roots" in that is solves systems
of equation instead of a single equation. In solve it is not even
possible to specify a ring, and only can solve in ""Symbolic""
expressions.
Thanks,
niels
On Sun, 20 Sep 2009 15:45:37 +0200
x x <niels....@gmail.com> wrote:
>
> Sage is a great project in my opinion, and i hope to contribute, when
> i am more familiar with sage and python. I am not sure whether this
> belongs to sage-support or sage-devel, since i don't understand the
> architecture, in particular relating to the Symbolic expressions.
>
> That being said, i still don't understand what Symbolic expressions
> are.
Symbolic expressions are where sin(x), x^y, etc. live. In systems like
Maple or MMA, everything is a symbolic expression. This let's you do
formal symbol manipulation without worrying about the mathematical
background. Sage also let's the user work with algebraic structures,
similar to Axiom, Magma, etc.
> >> sage: t = Mod(3,5)
> >> sage: t.parent()
> >> Ring of integers modulo 5
> >> sage: u = SR(t)
> >> sage: u
> >> 3
> >> sage: u.parent()
> >> Symbolic Ring
> >> sage: u.pyobject().parent()
> >> Ring of integers modulo 5
>
> In this example t is defined over "Ring of integers modulo 5", which
> is great, because i heard about this before. It is wrapped in a SR,
> for some reason, and afterwards the ring can be retrieved. No problem.
Say you want to work with t^n for some unspecified number n. You can do
this:
sage: var('n')
n
sage: u^n
3^n
After you're done computing, substituting a value for n will evaluate
the expression:
sage: (u^n).subs(n=5)
3
sage: res = (u^n).subs(n=5)
sage: res.parent()
Symbolic Ring
You can use .pyobject() on res to go back to working in Ring of
integers modulo 5.
<snip>
> So from a mathematical point of view, it seems that a symbolic ring is
> the polynomial ring with ground field determined by the coefficients
> (?).
"Symbolic ring" is an unfortunate name. It doesn't mean much from the
"mathematical point of view." It's just where all the symbolic stuff
live in Sage. Maybe we should call it symbolic parent.
> Is this consistent with all the functions taking symbolic
> expressions without a ring specified?
I don't understand this question.
> >If you really want polynomials, you need to do
> >something like
> >
> >sage: R.<x> = CC[]
> >sage: x^2+1
> >
> >and go from there, I think. That is occasionally annoying to those
> >of us who primarily teach undergraduates, but essential for many of
> >the applications of Sage.
>
> It seems to me that not specifying the ring explicitly is even more
> difficult to teach. At least i hope so, because i don't understand it
> yet.
AFAICT, most non mathematician users prefer to work with symbols
instead of using the algebraic structures directly.
> As i understand "solve" differs from "roots" in that is solves systems
> of equation instead of a single equation. In solve it is not even
> possible to specify a ring, and only can solve in ""Symbolic""
> expressions.
The function solve() is meant to correspond to the solve command in
Maple and MMA, which try to find "solutions" to whatever you throw at
them. Here is the documentation for solve in Maple:
http://www.maplesoft.com/support/help/view.aspx?path=solve
ATM, Sage calls various functions in maxima to do this. As discussed in
this thread, this doesn't work very well.
Cheers,
Burcin
Thanks for the explanation!
> "Symbolic ring" is an unfortunate name. It doesn't mean much from the
> "mathematical point of view." It's just where all the symbolic stuff
> live in Sage. Maybe we should call it symbolic parent.
I agree that the naming is unfortunate. I think it would be a good
idea to add this remark in the documentation.
> AFAICT, most non mathematician users prefer to work with symbols
> instead of using the algebraic structures directly.
I hope this idea is not based on Maple and MMA having such symbolic parents.
In any case i think it should be easy to explain what is happening,
although some users are not aware.
In your example t=3 is in ZZ_5 and u is a function from ZZ_5 to ZZ_5,
mapping n to 3^n. So although some users may be not aware, they are
actually working over the ring ZZ_5.
What i do understand is that for example elements in QQBar should be
represented by symbols (sqrt(2) instead of a numerical value 1,... or
pi instead of 3.14... ).
An computer algebra system should be able to manipulate these symbols,
such that it is mathematically correct in a given algebraic structure.
I think that the output is then both for mathematicians and non
mathematicians better understandable, and such symbolic inputs are
also more human readable.
Sorry if i am stating the obvious here, the reason is that i am trying
to explain why i think it should be (either implicit or explicit)
clear over which algebraic structure is computed.
Cheers,
Niels
Generally it is -- try parent(foo) or foo.parent() to see what
"algebraic structure" is in play.
sage: Zmod(5)(1).parent()
Ring of integers modulo 5
sage: (Zmod(5)(-1) * sin(x))
4*sin(x)
sage: (Zmod(5)(-1) * sin(x))^2
sin(x)^2
sage: (Zmod(5)(-1) * sin(x)).parent()
Symbolic Ring
Now this is irritating, perhaps, but there is no way to avoid this
given the "parents with objects" approach that Sage subscribes to:
sage: t = (Zmod(5)(3) * sin(x))^2
sage: t
4*sin(x)^2
sage: t.operands()
[sin(x)^2, 4]
sage: t.operands()[-1]
4
sage: t.operands()[-1].parent()
Symbolic Ring
sage: t.operands()[-1].pyobject().parent()
Ring of integers modulo 5
So the algebraic structure really is there, it's just that the
"Symbolic Ring" algebraic structure is very permissive: it's not
really "algebraic" in a mathematical sense.
Nick
The problem is that most elements of QQBar can't be represented this
way, and even if they can be it's expensive. (Maybe a printing mode
would be good..., but "Root of x^5 - x - 1 closest to 1.18... +
1.08...i" is pretty verbose).
- Robert
>>
>> What i do understand is that for example elements in QQBar should be
>> represented by symbols (sqrt(2) instead of a numerical value 1,... or
>> pi instead of 3.14... ).
>
> The problem is that most elements of QQBar can't be represented this
> way, and even if they can be it's expensive. (Maybe a printing mode
> would be good..., but "Root of x^5 - x - 1 closest to 1.18... +
> 1.08...i" is pretty verbose).
And pi can't be represented by QQbar at all!
Jason
--
Jason Grout
Thanks for the correction! What I meant was a transcendental extension over QQ.
Yep, we support various root numerical root finders, linear solvers,
grobner bases, and symbolic solvers (via Maxima--you're right, we
should look into exposing and using the various package here). The
non-symbolic ones are typically orders of magnitude faster, if you're
in that special case. This is one area where the idea of a domain
like Sage has is useful.
sage: x = ZZ['x'].gen()
sage: f = x^6 - 2*x^5 - x^2 + x + 2
sage: f.roots(QQ)
[(2, 1)]
sage: f.roots(QQbar) # these are exact
[(1.167303978261419?, 1), (2, 1), (-0.7648844336005847? -
0.3524715460317263?*I, 1), (-0.7648844336005847? + 0.3524715460317263?
*I, 1), (0.1812324444698754? - 1.083954101317711?*I, 1),
(0.1812324444698754? + 1.083954101317711?*I, 1)]
sage: f.roots(RR)
[(1.16730397826142, 1), (2.00000000000000, 1)]
sage: f.roots(RealField(500))
[(1.16730397826141868425604589985484218072056037152548903914008244927565
190342952705318068520504972867289535916899524104793645129596750871791336
957872256, 1),
(2.000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000
00000000, 1)]
sage: f.roots(CDF)
[(1.16730397826, 1), (2.0, 1), (-0.764884433601 - 0.352471546032*I,
1), (-0.764884433601 + 0.352471546032*I, 1), (0.18123244447 -
1.08395410132*I, 1), (0.18123244447 + 1.08395410132*I, 1)]
sage: f.roots(GF(17))
[(8, 1), (6, 1), (2, 1)]
sage: sage: f.roots(Qp(17, 5))
[(8 + 17 + 2*17^2 + 17^3 + 11*17^4 + O(17^5), 1),
(6 + 17 + 8*17^2 + 14*17^3 + 7*17^4 + O(17^5), 1),
(2 + O(17^5), 1)]
Alternatively,
sage: x = RR['x'].gen()
sage: f = x^6 - 2*x^5 - x^2 + x + 2
sage: parent(f)
Univariate Polynomial Ring in x over Real Field with 53 bits of
precision
sage: f.roots()
[(1.16730397826142, 1), (2.00000000000000, 1)]
etc.
- Robert
I think it would be very interesting to try to write such a function,
and there are certainly people with the appropriate knowledge...
William
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
Carl Witty would be one person to write a real Reduce replacement.
Reduce uses CAD, which has been a personal sage project of Carl Witty's
for at least several years. That's where we have QQbar and AA from, for
example (he needed it to do CAD stuff). Carl's made a lot of progress,
and from what I understand, he's probably several months away (of
full-time work) of having a finished CAD implementation in Sage. I
might be wrong on that point, though.
Right now, we do have an interface to qepcad that can do some of the
stuff, but I don't think it's quite as powerful as Reduce. It can do a
lot, though.
Jason
--
Jason Grout
> There's the small problem that as far as I can tell, unfortunately
> Carl stopped working on or contributing to Sage several months ago.
Yes, I haven't seen him around either. My guess is that someone
interested/capable of implementing CAD would get a huge headstart if
they could use the code Carl was working on. It's probably worth an
email to him, if someone was willing to take up the project.
Carl, if you're reading this still, could you comment?
Jason
--
Jason Grout
Can you tell us what wv, wv1, wb, wb1, veloc, mort, lwat, jbiom, rwat,
and av are?
Thanks,
Jason
--
Jason Grout
> I think that some of the suggestions here pretty much miss the mark.
>
> If you want to have Maxima do the same thing as Mathematica's Reduce
> program
> (and, by the way I think this would be good, especially since
> Mathematica's Reduce
> program seems to have been improved substantially so it is a store-
> house of neat things, in current Mma), then you should write a program
> that implements Reduce. Probably most easily done by adding to the
> Maxima code.
>
> Patching together something that answers questions from Maxima, either
> in python, pexpect, or for that matter, lisp, doesn't seem to me to
> be as
> worthwhile.
I agree. However, if I wanted something less powerful but still very
useful next week, putting something together that answers questions
is feasible, and I could do that on whichever side of the pexpect
barrier is most convenient for me. Just answering questions could be
a higher return on investment until something more is needed.
> As for the CAD (cylindrical algebraic decomposition) stuff, Reduce
> has gone far beyond that. Having a program that does only CAD is not
> very useful in the general world of "solve" unless you are only
> interested in polynomials and in particular, CAD.
> So no trig, log, exp, etc.
>
> Implementing CAD and a good geometry data-base for assume, and writing
> a version of Reduce for Maxima and/or Sage -- sure. Someone should go
> ahead and design it in detail. Write a nice paper about it, perhaps.
> Then decide how to implement it, in Python/Sage or "Maxima language"
> or Lisp. One nice thing about the latter two choices is that it would
> improve "standalone" Maxima too.
I hope someone does this, but if no one has the time and expertise to
design it in detail and write a paper, I'd rather see something
instead of nothing. Even better would be to see something simple
(even if it's not super powerful) in the next release of Sage, which
eventually gets thrown out when a fuller version gets developed
(probably in standalone Maxima).
- Robert
dwaterv = (av p - esv - etv - qvb + qbv);
dwaterb = (ab p - esb + qvb - qbv);
ab = 1 - av;
qvb = veloc wv/av;
qbv = veloc wb/ab;
esv = av lwat (wv/av);
etv = av rwat (wv/av) (bv/av)^2;
esb = ab lwat wb/ab;
dbv = jbiom etv - mort bv;
Reduce[0 == dwaterv && p > 0 && veloc > 0 && mort > 0 && lwat > 0 &&
jbiom > 0 && rwat > 0 && av >= 0, wv, Reals]
veloc > 0 &&
rwat > 0 && ((0 < av < 1 && lwat > 0 && p > 0 && mort > 0 &&
jbiom > 0) || (av > 1 && lwat > 0 && p > 0 && mort > 0 &&
jbiom > 0)) &&
wv == (av^3 p - av^4 p + av^2 veloc wb)/(
av^2 lwat - av^3 lwat + bv^2 rwat - av bv^2 rwat + av veloc -
av^2 veloc)
Solve[0 == dwaterv, wv]
wv1 = %[[1, 1, 2]];
{{wv -> (av^2 (-av p + av^2 p - veloc wb))/((-1 + av) (av^2 lwat +
bv^2 rwat + av veloc))}}
...
This was my last MMA project, which I recoded and finished in sage. I had quite a bit of trouble getting sage to solve some of the equations I needed to solve, but it worked in the end. Hope it will be easier in the future. When the paper is accepted, I shall put the sage code online.
Cheers,
Stan