Skip to content

Instantly share code, notes, and snippets.

@chethega
Created August 8, 2019 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chethega/95c704962976244145af08ffe9d73dec to your computer and use it in GitHub Desktop.
Save chethega/95c704962976244145af08ffe9d73dec to your computer and use it in GitHub Desktop.
repro 32809
module AbstractAlgebra
export ZZ, FreeModule, Submodule, Generic, test_submodule
abstract type RingElem end
abstract type Ring end
abstract type FPModule{T} end
abstract type FPModuleElem{T} end
mutable struct Integers{T <: Integer} <: Ring
end
const RingElement = Union{RingElem, Integer, Rational, AbstractFloat}
#### Generic submodule ####
module Generic
import ..AbstractAlgebra: Ring, RingElem, RingElement
using ..AbstractAlgebra
export Submodule, FreeModule, free_module_elem
mutable struct FreeModule{T <: RingElement} <: AbstractAlgebra.FPModule{T}
base_ring::Ring
rank::Int
end
mutable struct free_module_elem{T <: RingElement} <: AbstractAlgebra.FPModuleElem{T}
parent::FreeModule{T}
v::Vector{T}
end
mutable struct Submodule{T <: RingElement} <: AbstractAlgebra.FPModule{T}
m::AbstractAlgebra.FPModule{T}
gens::Vector{<:AbstractAlgebra.FPModuleElem{T}}
end
elem_type(::FreeModule{T}) where T <: RingElement = free_module_elem{T}
function (M::FreeModule{T})(a::Vector{T}) where T <: RingElement
return free_module_elem{T}(M, a)
end
function FreeModule(R::Ring, rank::Int)
T = elem_type(R)
return FreeModule{T}(R, rank)
end
generators(N::Submodule{T}) where T <: RingElement = N.gens::Vector{elem_type(N.m)}
function Submodule(m::AbstractAlgebra.FPModule{T}, gens::Vector{Any}) where T <: RingElement
return Submodule(m, elem_type(m)[])
end
function Submodule(m::AbstractAlgebra.FPModule{T}, subs::Vector{Submodule{T}}) where T <: RingElement
gens = vcat((generators(s) for s in subs)...)
return Submodule(m, gens)
end
end #### Generic submodule ####
import .Generic: elem_type
function FreeModule(R::Ring, rank::Int)
Generic.FreeModule(R, rank)
end
function Submodule(m::FPModule{T}, gens::Vector{<:FPModuleElem{T}}) where T <: RingElement
Generic.Submodule(m, gens)
end
function Submodule(m::FPModule{T}, subs::Vector{<:Generic.Submodule{T}}) where T <: RingElement
Generic.Submodule(m, subs)
end
elem_type(::Integers{T}) where T <: Integer = T
ZZ = Integers{BigInt}()
function test_submodule()
M = FreeModule(ZZ, 2) # <-----------------
M = FreeModule(ZZ, 3)
nsubs = 0
subs = [Submodule(M, [M(BigInt[1, 2, 3])]) for i in 1:nsubs]
N = Submodule(M, subs)
end
end # module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment