tkluck / GaloisFields.jl

Finite fields for Julia
Other
47 stars 6 forks source link

Display confusion between PrimeField and BinaryField #5

Closed Keno closed 4 years ago

Keno commented 4 years ago

I'm not sure if this is intended or a bug, but either way it's confusing.

julia> @GaloisField â„Ī/256â„Ī
ð”―â‚‚â‚…â‚†

julia> @GaloisField ð”―â‚‚â‚…â‚†
(ð”―â‚‚â‚…â‚†, ##423)

The former ð”―â‚‚â‚…â‚† is a PrimeField (even though 256 isn't prime?) while the latter is a BinaryField. They print the same, but behave completely differently.

tkluck commented 4 years ago

Thanks for flagging. I've been hesitant to add isprime assertions in the constructors, but after timing this I don't see a reason:

julia> @btime isprime($(prevprime(typemax(Int128))))
  68.619 Ξs (4 allocations: 2.49 KiB)
true

That would then throw an error in your first example. Would that solve your confusion?

Keno commented 4 years ago

It would solve my confusion, though of course â„Ī/256â„Ī is sometimes quite useful, so perhaps we should just add a ModP datatype to support things of that form that aren't finite fields and just make it work. Perhaps this isn't the correct package for that, but I figure PrimeField has all the code to support ModP anyway.

tkluck commented 4 years ago

of course â„Ī/256â„Ī is sometimes quite useful, so perhaps we should just add a ModP datatype to support things of that form that aren't finite fields and just make it work.

I agree that it might be useful, but it immediately asks for new methods and functionality (chinese remainder theorem, is_zero_divisor, ideals, etc). So yep, probably not the right package.

I'll leave the issue open until I added isprime to the constructor.