Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
334 stars 228 forks source link

memoize GF #1993

Open 8d1h opened 3 years ago

8d1h commented 3 years ago

Hi! I saw this in the documentation which I guess is not the desired behavior.

i3 : tally for i to 100 list random GF 11

o3 = Tally{-1 => 1}
           -1 => 1
           -1 => 1
           -1 => 1
           -1 => 1
           -1 => 1
           -1 => 1
           -1 => 1
           -1 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -2 => 1
           -3 => 1
...

This could be fixed by making GF memoized. I saw this trick in the package "Cyclotomic", where the same number would always give the exact same cyclotomic field.

DanGrayson commented 3 years ago

Probably the reason we didn't memoize it originally was to allow for garbage collection of unused Galois fields. One can imagine experiments that make a lot of them. If that's not a concern, memoization might be good now. And it might be good to make GF 11 and ZZ/11 give the same answer.

8d1h commented 3 years ago

That would indeed be nice. Also I think currently the arithmetic over ZZ/11 is faster than GF 11.

i23 : ZZ/11[x]; time for i to 10000 do factor x^2-1;
     -- used 0.451269 seconds  

i25 : GF 11[x]; time for i to 10000 do factor x^2-1;
     -- used 2.07047 seconds

And isFinitePrimeField GF 11 returns false since it checks with isQuotientRing.