> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>
It is related with this issue:
http://code.google.com/p/sympy/issues/detail?id=2193
20.01.2012 01:25, krastano...@gmail.com пишет:
--
Alexey U.
>>> d = [nsimplify(w) for w in [1., 2, 2, 2, 1., 0, 2, 0, 1.]]
>>> Matrix(3,3,d).diagonalize()
([ 0, sqrt(2), -sqrt(2)]
[-1, 1, 1]
[ 1, 1, 1], [1, 0, 0]
[0, 1 + 2*sqrt(2), 0]
[0, 0, -2*sqrt(2) + 1])
>>> out = _
>>> out[0]
[ 0, sqrt(2), -sqrt(2)]
[-1, 1, 1]
[ 1, 1, 1]
>>> out[1]
[1, 0, 0]
[0, 1 + 2*sqrt(2), 0]
[0, 0, -2*sqrt(2) + 1]
I'm not sure exactly what the difficulty is that you are imagining.
There are several routines in SymPy that don't work well when you use
floats, so you have to work around the "features'. For the above,
>>> Matrix(3,3,[nsimplify(w) for w in [1., 2, 2, 2, 1., 0, 2, 0, 1.1]]).diagonalize()
seems to work ok. Perhaps nsimlify could be made to recognize Matrix
so one could do nsimplify(m)...but just simplifying the data before
creating the Matrix isn't too bad.
I agreed that this problem exists: the problem with the `diagonalize`
method, which is based on the problem of the calculation of the
eigenvectors for some eigenvalues when the cases are not trivial. (And
more deeply, in common cases, in particular, it is (or was) related with
complex numbers, and with the so called zero-test problem: the complex
theoretical problem how to determine whether the symbolic expression is
zero or not). Now you added an example for the floats.
It is somehow described only in that issue [1]. Although only an
approximate location of the problem is described there.
I have accepted, and I am marked for this issue as owner, and fill
myself to continue with it.
And I agreed that the `nsimplify` can be considered only as a temporary
roundabout way.
As this issue is almost year old we must decide indeed, either to
describe it in the documentation or to increase the priority of the issue.
For my part, I am going to deal with it in a few weeks only (when I have
free time).
Now I attached your examples to that issue.
Thank you and others for raising the interest in this problem.
I hope it will be resolved soon.
[1] http://code.google.com/p/sympy/issues/detail?id=2193
--
Alexey U.
In our part of the country "imagining" means more along the lines of
"thinking". To you there is a problem. You posted it, I sent a
workaround, and then you sent another problem which was essentially
the same, so I didn't know what is what that you were thinking the
problem was.
To me it's just the common problem of having to use Rational instead
of floats. But this is not a special problem in the sense that python
addresses this in a variety of ways: int, long, float, decimal and I
showed a way to work around it in SymPy. What threw me off is the
"another problem" that you gave which is (to me) just the same problem
-- you have to be careful with how and where you use floats. There's
no easy, unambiguous way around that problem. Of course SymPy could
totally disallow the use of floats, but that's not pythonic. You can
use them at your own risk.
Anyway, we're always watching for ways to make SymPy more usable, and
do appreciate the feedback, so please don't imagine -- and now I do
mean "imagine" -- that what you have posted is unwelcome in anyway or
that I was trying to downplay it.
Best regards,
Chris
I don't think this can even be done. Not in the general case anyway;
simple cases like 1+1.0 will probably work as expected :-)
It's numeric instabilities that force the numeric solution algorithms
into fundamentally different approaches than their symbolic counterparts.
Matrix calculations are a case in point; computing determinants tends to
give rise to instabilities, and there's an entire lore around avoiding
having to compute determinants, and if it's unavoidable, how to
condition your equations so that the determinants are stable (i.e. the
denominators don't get near to zero).
I'm not sure that SymPy can do anything better than convert Python
floats to Rationals as soon as it tries to do arithmetic with them.
Regards,
Jo