Indeed! That’s the beauty of Julia’s zero-cost abstractions. The implementation uses invmod (see snippet below).
Construction only seems expensive because F is not a constant. That’s fixable:
julia> using GaloisFields; using BenchmarkTools
julia> const F = GaloisField(7)
𝔽₇
julia> @btime inv(F(5))
30.270 ns (0 allocations: 0 bytes)
3
I didn’t know that before your post triggered me to investigate. I’ll update the documentation accordingly.
FWIW, the benefit you get from using this package is that every operation happens mod p automatically. Moreover, you can use extension fields, like the field of 4 elements \{0,1,\alpha, \alpha + 1\} defined by \alpha(\alpha+1) = 1.
julia> using GaloisFields
julia> F = @GaloisField! 4 α
𝔽₄
julia> α*(α+1)
1
If this topic interests, you, let me know of any features you are missing.