Closed redshirtrob closed 1 year ago
Thanks for catching this! Malachite should absolutely be able to handle Natural
s of this size. I would only expect problems when the number of bits reaches the billions, and memory allocation starts to fail.
The FFT code is indeed very convoluted, no pun intended. I did some print-debugging comparisons with the FLINT code that it's based on, and it turns out FLINT and Malachite were using different FFT tuning tables. These influence the recursion strategy that the FFT code uses, and the bad table led to the assumption violation that you saw. I've made the fix and will release a new version of Malachite in a few days.
I'll have to see if this impacts performance negatively, but of course correctness is more important.
Awesome! Glad you were able to fix it so quickly.
FWIW, I just tested against Integer
and I see the same issue. I'm guessing your fix will cover that as well, but though I'd mention it just in case.
Yes, Integer
mostly just delegates to Natural
. I've added a test case for Integer
too just for the sake of completeness.
Fixed in 0.4.3.
The tuning tables were a red herring: the real issue was that I thought I had proved that a certain carry was no greater than 1, but I was mistaken, and sometimes it's greater than 1. That's handled correctly now. I have tested 2^n * 2^n for n up to 1,000,000, and it works correctly.
Sorry, v0.4.3 had some wrong dependencies. Please use v0.4.4 instead.
This is awesome to hear! Thank you so much!
I ran into this while porting an LLL library to Malachite. I'm not sure if it's expected or not. Here's the snippet of code that panics:
Here's the stacktrace:
I took a quick look, but the fft code is beyond my ability to comprehend right now. This isn't a big deal for me. I mostly raise it because Malachite is a fantastic library.
I'd completely understand if this is expected behavior or a "won't fix" as multiplying two 100k bit numbers feels a bit ridiculous.