Nemocas / Nemo.jl

Julia bindings for various mathematical libraries (including flint2)
http://nemocas.github.io/Nemo.jl/
Other
184 stars 57 forks source link

Scalar multiplication between `nmod` and `fq_nmod` #668

Open Keno opened 4 years ago

Keno commented 4 years ago

I expected the following to work, treating 𝔽₈ as an 𝔽₂ vector space:


julia> R, x= ResidueRing(ZZ,2)["X"]
(Univariate Polynomial Ring in X over Integers modulo 2, X)

julia> F = FiniteField(R(x^3+x^2+1), "z")
(Finite field of degree 3 over F_2, z)

julia> base_ring(R)(0)*F(1)
ERROR: MethodError: no method matching (::FqNmodFiniteField)(::Nemo.nmod)
Closest candidates are:
  Any() at /Users/kfischer/.julia/dev/Nemo/src/flint/fq_nmod.jl:430
  Any(::Int64) at /Users/kfischer/.julia/dev/Nemo/src/flint/fq_nmod.jl:438
  Any(::fmpz) at /Users/kfischer/.julia/dev/Nemo/src/flint/fq_nmod.jl:444
  ...
Stacktrace:
 [1] *(::Nemo.nmod, ::fq_nmod) at /Users/kfischer/.julia/packages/AbstractAlgebra/QTyIN/src/Rings.jl:76
 [2] top-level scope at REPL[9]:1
wbhart commented 4 years ago

Again, in my humble opinion, this construction shouldn't be allowed in the first place.

I would only expect there to be a coercion from F_2 to your finite field, and ResidueRing(ZZ, 2) is not intended to be a finite field, but a residue ring, i.e. the set of residue classes of ZZ modulo 2, as a ring (not a field).

In any event, embeddings of finite fields are still being implemented, so the coercion certainly won't be there for a while, though I can perfectly understand why you would expect it to be there. We just need to think carefully about how we want that to work.

It's not at all clear this is ever going to work unless you explicitly embed one of the fields in the other, and I don't know if we have or haven't decided that constructing a finite field in this way will automatically also construct an embedding.

Sorry if that sounds like a very complicated answer to a very simple problem.

wbhart commented 4 years ago

Just to elaborate a little, although Z/pZ is isomorphic to F_p as a field, constructing a finite field of degree 1 with a Conway polynomial isn't the same as Z/pZ. That means there couldn't be a coercion of the kind you are asking for if the field was constructed using a Conway polynomial. For that reason alone, it might not be a good idea to ever allow such a coercion.

In your case, you are not constructing a finite field with a Conway polynomial, and presumably don't care about them at all. So there is an argument that the coercion you want should be allowed. But this would mean we would need to keep track of how the field was constructed.

It also has consequences for some of the functions as implemented, since they rely on multiplicative generators. When we recently thought about this, we realised that there was a choice of multiplicative generator for F_p, even if we know how the field embeds in an extension. But there's only one multiplicative generator that will be consistent with the norm function given your chosen generator (x) in the extension field.

As you probably realise, this isn't compatible with constructing finite fields in the way that you are doing it here.

Sorry if that's an even more complicated answer to a very simple problem and even more sorry if it is incorrect. It seems correct to me at the moment though, after recently working on embeddings and discovering that there were all these subtle hidden choices that affected correctness of various functions we offer.