-
-
Notifications
You must be signed in to change notification settings - Fork 434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up comparisons in QQbar #16964
Comments
comment:1
Please mention the version of Sage, in particular whether or not #15767 was applied. |
comment:2
Replying to @jdemeyer:
This was sage 6.3 on Gentoo. With current develop (6.4.beta2) at least it doesn't fail as “quickly”: where the previous computation was 8 hours all in all up to the exception, my patched version without sorting took 7½ hours to compute the list, and after that sage has now been busy sorting that list for 1½ hours and still isn't done. I'll report back when it is, or when it gave up, but I'd say some need for action remains, even if the exception no longer occurs in this form. |
comment:3
Here is a reproducing example which at least demonstrates that comparisons take way longer than they should:
This is because the comparison of the real parts takes like forever. Which in turn is because the computation of its minimal polynomial takes forever. Looking at the set of all zeros, I can see that there are 4 clearly distinct real parts, and each comes with a pair of conjugate solutions since the polynomial has real coefficients. This is enough to conclude that if the intervals for two real parts overlap, then they must be equal and I don't have to do an exact computation for this. Should we try to implement some of this reasoning as a special case for |
comment:5
Looking for ways to address this, I noticed that the a lot of time apparently is spent inside
I wonder whether we can avoid that union for the case where both fields have the same defining polynomial. I wonder whether we can assume that the root of the field will form a power basis, and if so, whether there is any reasonably cheap way to find the conversion between different power bases, so we could express one root in terms of another. Since I don't have any good ideas how to achieve this, my best idea still is tacking this at the Here is what I've tried and discarded, so you can avoid that same cul de sac. I started by writing down a generic linear combination w = a₀ + a₁z + a₂z² + … and then computed p(w) reduced by p(z), where p is the polynomial of the field. This gives a polynomial in z, and if enough powers of z are irrational then all the coefficients have to be zero if w is a root and the a_i are to be rational. So this gave me d conditions on these a₀ through a_{d-1}, which I could combine into an ideal and try to compute a variety. But that variety computation takes like forever in the above example, so this generic approach of finding other roots is not feasible in this fashion. Been there, tried that and discarded it. |
This comment has been minimized.
This comment has been minimized.
Branch: u/gagern/ticket/16964 |
comment:9
Here is my first stab at the approach outlined in comment:3. If you have a nicer way to handle things, feel free to suggest an alternative. If you think that my special case should not call As it is, I consider my code not particularly beautiful, and perhaps not the best solution either, but it is way better than the current state of affairs, and since we have other things depending on this, e.g. #14239, I'd like to see this merged pretty soon and possible improvements dealt with in a later ticket. New commits:
|
Commit: |
Author: Martin von Gagern |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:11
Just a quick comment: I like your general approach, but I have to check the details... |
Branch pushed to git repo; I updated commit sha1. New commits:
|
This comment has been minimized.
This comment has been minimized.
comment:13
Changing description to turn focus from pari exception to performance. Replying to @jdemeyer:
Have you found time for a closer look? Since this is currently the only ticket in the review queue with priority critical, perhaps we should try to get this into Sage 6.5? |
comment:14
Hello, This improvement is really cool! EDIT: the thing below is basically one part of comment:9... Couldn't we do a little bit better? In some cases we might identify numerically pairs of conjugated roots (and possibly one real root) and still be able to decide which one is which. There exists polynomials whose roots have the same real part:
With the implementation proposed in this ticket, the comparison of the roots of the above polynomial falls back to the generic implementation. We could at least compare the conjugated ones without exactification of the real part. But we can leave that for a further ticket. Vincent |
comment:20
Sorry I messed up the commits! Now everything looks good and doctest are fine... |
Changed branch from u/vdelecroix/16964 to u/gagern/16964 |
comment:23
I like how you avoid unneccessary minpoly computation. But I think we can do better than you did, by not having the intervals span negative and positive imaginary parts, but instead considering the absolute value of the imaginary part. I did something along these lines, but I now see that I'll have to rebase that on your latest forced push… New commits:
|
comment:24
Replying to @gagern:
sorry for that... Your version is much simpler by the way! But I am not completely convinced that this is optimal. Do you know if there is a cheap way to assert if two roots of a given (irreducible) polynomial have the same real value? In the example I added in the commit 297c68a Vincent |
comment:25
I can also rebase my changes on yours BTW. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:28
I choose a more meaningful test. Could you have a look? As a consequence of your changes, we get great improvements on comparing rationals!! new timings
old timings
This is completely crazy. If you are happy with my changes you can set to positive review. Vincent New commits:
|
Changed branch from u/gagern/16964 to u/vdelecroix/16964 |
Reviewer: Vincent Delecroix |
comment:29
I like it. Thanks for the review! The speed gain for the rational numbers appear to be due to the fact that we no longer have to construct an algebraic number representation for the real part.
(I still hope that someone, some day, will make all this work here obsolete by coming up with a better way to compare QQbar elements even if they don't share a minpoly. No idea how, though.) |
comment:30
Replying to @videlec:
Using resultants, you can find a polynomial which has (a - b) as a root. And then you use interval arithmetic to find which root. Determining whether the imaginary parts are equal then is equivalent to checking whether a real polynomial has a pure imaginary root. The latter can probably be done using some Sturm-like algorithm. |
comment:31
Replying to @jdemeyer:
Up to now I had assumed that most arithmetic in QQbar would eventually be performed using resultants. But it seems I was mistaken.
One possible root of I lost patience waiting for that final result of I can think of two possible problems. One is that we might be dealing with a special case here, and that perhaps number field unions are in general cheaper than resultants. If that were the case, what does that mean for speeding up comparisons? Another possible problem I can imagine is that the resultant could factor into several distinct polynomials, some of which might share a root. If that were the case, numeric refinement wouldn't be able to help choosing the right factor. Should we perhaps not factor the resultant polynomial, but instead compute roots for the fully expanded form? I get the impression that this might trigger some major work. I hope that the reviewed changes can land as they are, while we investigate (in some other branch) how to tackle this more generic approach. |
comment:32
Replying to @gagern:
Just created #17886 about using resultants to speed up most qqbar operations. |
Changed branch from u/vdelecroix/16964 to |
When computing the variety of some ideal, then excessive amounts of time are apparently spent sorting the solutions. (In one example, the variety was essentially computed in 7½ hours but the sorting wasn't finished even 1½ hours after that.) This is due to the fact that comparison between complex algebraic numbers is done lexicographically, which means that quite often the real parts of complex conjugate numbers will have to be compared for equality, which can be a very costly operation.
Originally the computation even resulted in a Pari exception (“not enough precomputed primes”). This no longer occurs (since the pari upgrade from #15767). So the focus of this ticket is now the excessive amount of time required for comparisons, even without an exception.
Component: number fields
Keywords: variety qqbar cmp singular
Author: Martin von Gagern
Branch/Commit:
3f4afef
Reviewer: Vincent Delecroix
Issue created by migration from https://trac.sagemath.org/ticket/16964
The text was updated successfully, but these errors were encountered: