M2 icon indicating copy to clipboard operation
M2 copied to clipboard

random(GaloisField) not functioning property with user-defined GaloisField

Open moorewf opened this issue 2 years ago • 1 comments

If one creates a GaloisField with a user-defined polynomial, then random(GaloisField) seems to choose a random power of the variable used to define the extension at random, rather than an actual random element of the GaloisField. This is not an issue if one creates a GaloisField without providing the polynomial.

i1 : kk = ZZ/32003

o1 = kk

o1 : QuotientRing

i2 : R = kk[q]

o2 = R

o2 : PolynomialRing

i3 : f = q^2 + q + 1

      2
o3 = q  + q + 1

o3 : R

i4 : ll = R/(f)

o4 = ll

o4 : QuotientRing

i5 : LL = GF(ll)

o5 = LL

o5 : GaloisField

i6 : tally apply(100, i -> random LL)

o6 = Tally{- q - 1 => 33}
           1 => 34
           q => 33

o6 : Tally

i7 : MM = GF(32003^2)

o7 = MM

o7 : GaloisField

i8 : random MM

o8 = 546a + 11354

o8 : MM

moorewf avatar Mar 03 '24 21:03 moorewf

Upon looking at the code for random, it does precisely that:

random GaloisField := opts -> F -> (
           i := random F.order;
           if i === 0 then 0_F else F_0^i
           )

Would anything be wrong/slower with just taking F_0 and the degree of the extension over the prime field K, and adding (random K)*F_0^i the appropriate number of times here?

moorewf avatar Mar 03 '24 21:03 moorewf