It’s time for a conclusion now.
First I would like to thank all contributors, who gave to me good advises and spent time for experiments. Among them a special mention to DNF and genkuroki.
The recommendation to have a look at GaloisFields.jl was again of great value.
From the various notes I learned a lot of things about sub-typing and promotion rules and understood why my model with macro, although possible to use was not adequate.
I remind my purpose here for the moment : to teach linear algebra to students giving examples with finite fields where ‘exact’ computations are possible to illustrate the main technique of this discipline, for example computation of determinants, simplification of matrices, resolution of linear systems.
At the moment of choice I decided to adopt the Tmo Kluck’s model at least for the primary p-fields Z/pZ, it’s enough to introduce this model with the two lines :
using GaloisFields
const F = @GaloisField 5 #F will be the primary 𝔽₅=ℤ/5ℤ field
The problem now is what to do with vector spaces of finite dimension over these 𝔽p 's ? Is it advisable to continue with Dr Kluck’s model ?
First I was really impressed by the construction via a given minimal polynomial. I used this possibility in a demonstration example earlier.
I was even more impressed by such constructions :
const G, β = GaloisField(81, :β) # degree-4 extension of ℤ/3ℤ
const G, β = GaloisField(3, 4, :β) # same; avoid having to factorize 81
I mean without passing an irreducible polynomial as an argument. It is well known that for any n it exists an irreducible polynomial of degree n over 𝔽ₚ but I couldn’t find anywhere a fast algorithm to find one. Examples here and there use brute force together with tricks (should be unitary, divisor of X^q -X where q=p^n , shouldn’t have any root in 𝔽ₚ and all this stuff).
It seems to me that multiplication rules between elements given as linear combinations of powers of β need to know this polynomial. So the author has a trick either to find it or to bypass it. I didn’t go further in this direction but it’s very interesting.
Now Dr Kluck concentrate on the fact that such extension have a field structure, namely an algebra over 𝔽ₚ, this is too much for us; we just need to use finite powers of 𝔽ₚ with the canonical basis.
So I decided to abandon Timo’s model for vector spaces. and used instead
using Base.Iterators
using GaloisFields
const F = @GaloisField 5 #corps ℤ/5ℤ
PowerX_n(X, n) = Iterators.product(ntuple(i->X, n)...)
n=3 #puissance
P=PowerX_n(F,n) #ensembles de 3-uples
convert(t)=F[t[i] for i in 1:n]
const E=[convert(t) for t in P] #ℤ/5ℤ^3
This allows to build the space as a full list of elements or as a simple iterator by own choice.
Furthermore I decided to study vector spaces on the basic 𝔽ₚ fields only. I’m just looking for examples after all not a complete theory.
We noted that The author used indirect derivation from the basic abstract type ‘Number’ . one could hope that call for help to such beautiful tools as LinearAlgebra or AbstractAlgebra would help to compute let’s say determinants, inverses and solve systems. Alas ! it doesn’t work like genkuroki noted.
The reason is that such function use for efficiency LU decomposition and the algorithm uses such fonctions as abs, conv, adjoint, together with binary relations ‘isless’ and so on. which have meaning for real and complex fields but cannot have any equivalent with finite fields.
So since I want to use this only for educational purpose where efficiency is not a criteria I decided to write own ‘hand-made’ such functions using text-books formulas.
using GaloisFields
const F = @GaloisField 5
A=F[1 1 2;0 2 4;0 0 4]
delrowcol(M,i,j)=M[1:end .!=i,1:end .!=j] #suppression de la ième ligne et de la jème colonne
#développement suivant la première ligne
function DET(M)
if size(M,1)==1
return M[1,1]
end
s=size(M,1)
L=[(-1)^(1+j)*M[1,j]*DET(delrowcol(M,1,j)) for j in 1:s]
return reduce(+,L)
end
println(DET(A))
and as well
using GaloisFields
const F = @GaloisField 5
A=F[1 1 2;0 2 4;0 0 4]
delrowcol(M,i,j)=M[1:end .!=i,1:end .!=j] #suppression de la ième ligne et de la jème colonne
cofacteur(M,i,j)=(-1)^(i+j)*DET(delrowcol(M,i,j))
#développement suivant la première ligne
function DET(M)
if size(M,1)==1
return M[1,1]
end
s=size(M,1)
L=[(-1)^(1+j)*M[1,j]*DET(delrowcol(M,1,j)) for j in 1:s]
return reduce(+,L)
end
function cofacteurs(M)
s=size(M,1)
B=zeros(F,s,s)
s=size(M,1)
for i in 1:s ,j in 1:s
B[i,j]=cofacteur(M,i,j)
end
return B
end
INV(M)=DET(M)^(-1)*transpose(cofacteurs(M))
println(DET(A))
println(INV(A))
println(A*INV(A))
I feel a little shy to send this last post because of possible reaction of DNF who estimates (Latin atavism) that I’m too much verbose.
Thank you again to you all and see you soon about affine geometry.