Skip to content
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

Make gcdx agree with Julia. #730

Merged
merged 2 commits into from
Nov 28, 2019
Merged

Make gcdx agree with Julia. #730

merged 2 commits into from
Nov 28, 2019

Conversation

wbhart
Copy link
Contributor

@wbhart wbhart commented Nov 25, 2019

No description provided.

@thofma
Copy link
Member

thofma commented Nov 25, 2019

Given that this is quite a fundamental task, how big is the slow down?

@wbhart
Copy link
Contributor Author

wbhart commented Nov 25, 2019

There's just one or in the worst case two extra exact divisions and an extra divrem, but only when the output isn't already normalised.

Generically the complexity of the gcd is much higher than for the divisions. For small integers, the time for the gcd dominates anyway. There is a small region in between the two cases where the division time could be 20% of the time.

In any event, I spent quite some time reducing the number of additional operations as much as possible. At least in the generic case the gcd is small and the exact divisions are a negligible cost. Obviously if the result is very far from reduced, the divrem is relatively expensive, otherwise it is cheap.

Flint never did this normalisation, whereas GMP and Julia do, so if we want it to be consistent, we have to do this normalisation in Nemo itself. So we don't have a lot of choice here.

Hmm, I just noticed that converting to BigInt, doing the gcdx there and converting back eliminates the cost entirely, and makes it faster for small integers. I think I might do that instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants