Division in the ring ZZ/6 in Julia
Following the 2018-05-01 thread on sage-devel about the case of SageMath, we explore the case of Julia and Nemo, a computer algebra package running in Julia.
The exploration is done in a project on CoCalc. It turns out Julia and Nemo are installed system-wide on CoCalc.
As Bill Hart recalls us in the sage-devel thread mentioned above
In Julia and Nemo, the slash operator is floating point division. For example, 1/2 is 0.5 not a half. For division in a ring, you want divexact (there is also a separate operator, div, for Euclidean division).
At the moment, the code in Nemo for this is actually incorrect, so it only gives you an answer in one of the two examples in this thread and an exception in the other case. It's not a difficult fix. It should be in the next version of Nemo.
In AbstractAlgebra (pure Julia, no Flint), we get:
ArgumentError: Module AbstractAlgebra not found in current path.
Run `Pkg.add("AbstractAlgebra")` to install the AbstractAlgebra package.
Stacktrace:
[1] _require(::Symbol) at ./loading.jl:435
[2] require(::Symbol) at ./loading.jl:405
[3] include_string(::String, ::String) at ./loading.jl:522
INFO: Initializing package repository /home/user/.julia/v0.6
INFO: Cloning METADATA from https://github.com/JuliaLang/METADATA.jl
INFO: Cloning cache of AbstractAlgebra from https://github.com/Nemocas/AbstractAlgebra.jl.git
INFO: Installing AbstractAlgebra v0.0.6
INFO: Package database updated
INFO: Precompiling module AbstractAlgebra.
MethodError: no method matching /(::AbstractAlgebra.Generic.Res{BigInt}, ::AbstractAlgebra.Generic.Res{BigInt})
Stacktrace:
[1] include_string(::String, ::String) at ./loading.jl:522
MethodError: no method matching /(::AbstractAlgebra.Generic.Res{BigInt}, ::AbstractAlgebra.Generic.Res{BigInt})
Stacktrace:
[1] include_string(::String, ::String) at ./loading.jl:522
Load Nemo, define two elements of ZZ/6 and their product
MethodError: Cannot `convert` an object of type Nemo.Integers{BigInt} to an object of type AbstractAlgebra.Ring
This may have arisen from a call to the constructor AbstractAlgebra.Ring(...),
since type constructors fall back to convert methods.
Stacktrace:
[1] AbstractAlgebra.Generic.ResRing{BigInt}(::BigInt, ::Bool) at /home/user/.julia/v0.6/AbstractAlgebra/src/generic/GenericTypes.jl:292
[2] #ResidueRing#36(::Bool, ::Function, ::AbstractAlgebra.Integers{BigInt}, ::Int64) at /home/user/.julia/v0.6/AbstractAlgebra/src/generic/Residue.jl:557
[3] (::AbstractAlgebra.Generic.#kw##ResidueRing)(::Array{Any,1}, ::AbstractAlgebra.Generic.#ResidueRing, ::AbstractAlgebra.Integers{BigInt}, ::Int64) at ./<missing>:0
[4] ResidueRing(::AbstractAlgebra.Integers{BigInt}, ::Int64) at /home/user/.julia/v0.6/AbstractAlgebra/src/AbstractAlgebra.jl:306
[5] include_string(::String, ::String) at ./loading.jl:522
Try dividing naively with /
MethodError: no method matching /(::AbstractAlgebra.Generic.Res{BigInt}, ::AbstractAlgebra.Generic.Res{BigInt})
Stacktrace:
[1] include_string(::String, ::String) at ./loading.jl:522
MethodError: no method matching /(::AbstractAlgebra.Generic.Res{BigInt}, ::AbstractAlgebra.Generic.Res{BigInt})
Stacktrace:
[1] include_string(::String, ::String) at ./loading.jl:522
What went wrong
As Bill Hart recalls us in the sage-devel thread mentioned above
In Julia and Nemo, the slash operator is floating point division. For example, 1/2 is 0.5 not a half. For division in a ring, you want divexact (there is also a separate operator, div, for Euclidean division).
At the moment, the code in Nemo for this is actually incorrect, so it only gives you an answer in one of the two examples in this thread and an exception in the other case. It's not a difficult fix. It should be in the next version of Nemo.
In AbstractAlgebra (pure Julia, no Flint), we get:
So let's try again.