-
-
Notifications
You must be signed in to change notification settings - Fork 697
Description
So currently, we compare elements of inexact rings like CDF by just comparing their components as doubles. We use this for sorting, and expect the results to be consistent between runs, architectures, etc. However, this is wildly untrue. Here's a good example:
sage: z1, z2 = [ x[0] for x in f.roots()[-2:] ]
sage: R = CDF['x']
sage: f = R([17,1,0,0,0,1]) ; f
1.0*x^5 + 1.0*x + 17.0
sage: f.roots()
[(-1.72502775061, 1),
(1.4372759883 + 1.06991737978*I, 1),
(1.4372759883 - 1.06991737978*I, 1),
(-0.574762112991 + 1.65506825348*I, 1),
(-0.574762112991 - 1.65506825348*I, 1)]
sage: z1, z2 = [ x[0] for x in f.roots()[-2:] ]
sage: z1
-0.574762112991 + 1.65506825348*I
sage: z2
-0.574762112991 - 1.65506825348*I
sage: z1.real() == z2.real()
False
Notice that the +/- ordering is different for the two pairs of complex conjugate roots. What we should do is pass a parameter to __cmp__ that describes a threshold such that if the difference is smaller than this threshold in absolute value, things compare equal. This could even be a parameter to the ring.
There are a ton of questions this brings up, such as, "how is this done in other systems?" Notice this also underlies the following confusing result:
sage: [ f(x[0]).is_zero() for x in f.roots() ]
[False, False, False, False, False]
Someone should do some research and start a sage-devel conversation, probably.
Component: numerical
Issue created by migration from https://trac.sagemath.org/ticket/4544