a more reasonable sorting of complex numbers#2033
a more reasonable sorting of complex numbers#2033edgarcosta wants to merge 1 commit intoflintlib:mainfrom
Conversation
|
@fredrik-johansson, I might have some tests to fix, but before I do that, please let me know if you agree with the change. |
|
I agree the comparison function is buggy. However...
... I don't think this is true. Even if the roots are non-overlapping, real or imaginary parts can be overlapping. No matter how one defines the comparison function, the order of non-exact balls will be essentially random in case of componentwise overlap (though one can make such cases exceedingly rare by using a more artificial comparison function, e.g. mapping a+bi -> a+bc where c is some fixed, unattractive real number). Now, there is also some logic to the current comparison: it intended to put real roots first and then group complex conjugates. A more robust version of the idea can be found in It would be useful to provide both "lexicographic" and "root order" comparisons/sorts for complex numbers. This could also be implemented using generics with the option to error when the comparisons fail. |
|
I agree. |
In the current sorting, we have
z < conjugate(z)andconjugate(z) < z.I propose sorting on the real part; if they overlap, use the imaginary part.
Note that in the library,
_acb_vec_sort_prettyis used to sort polynomials' roots, which are multisets of non-overlapping balls.Therefore, we will obtain a predictable and stable sorting with the new comparison function.
PS: this will break some tests at Sagemath, as the roots will now come in a different order, but this is how I got into this rabbit hole.