Skip to content

Commit

Permalink
Some more tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
HechtiDerLachs committed Nov 24, 2023
1 parent 29ddc51 commit 5c2553e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/Modules/ModuleTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,13 @@ When computed, the corresponding matrix (via `matrix()`) and inverse isomorphism
@assert all(x->parent(x) === G, a)
@assert length(a) == ngens(F)
r = new{typeof(F), typeof(G), Nothing}()
a=Vector{elem_type(G)}(a)
function im_func(x::AbstractFreeModElem)
#if r.generators_map_to_generators === nothing
# r.generators_map_to_generators = images_of_generators(r) == gens(codomain(r))
#end
r.generators_map_to_generators === true && return codomain(r)(coordinates(x))
v = images_of_generators(r)
return sum(a*v[i] for (i, a) in coordinates(x); init=zero(codomain(r)))
return sum(b*a[i] for (i, b) in coordinates(x); init=zero(codomain(r)))
end
function pr_func(x)
@assert parent(x) === G
Expand All @@ -572,14 +572,14 @@ When computed, the corresponding matrix (via `matrix()`) and inverse isomorphism
@assert length(a) == ngens(F)
@assert h(one(base_ring(F))) == one(base_ring(G))
r = new{typeof(F), T2, RingMapType}()
a=Vector{elem_type(G)}(a)
function im_func(x::AbstractFreeModElem)
iszero(x) && return zero(codomain(r))
#if r.generators_map_to_generators === nothing
# r.generators_map_to_generators = images_of_generators(r) == gens(codomain(r))
#end
r.generators_map_to_generators === true && return codomain(r)(map_entries(h, coordinates(x)))
v = images_of_generators(r)
return sum(h(a)*v[i] for (i, a) in coordinates(x); init=zero(codomain(r)))
return sum(h(b)*a[i] for (i, b) in coordinates(x); init=zero(codomain(r)))
end
function pr_func(x)
@assert parent(x) === G
Expand Down
14 changes: 13 additions & 1 deletion src/Modules/UngradedModules/FreeModElem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,26 @@ function (==)(a::AbstractFreeModElem, b::AbstractFreeModElem)
return a.coords == b.coords
end

function hash(a::AbstractFreeModElem, h::UInt)
function hash(a::AbstractFreeModElem{<:MPolyElem}, h::UInt)
b = 0xaa2ba4a32dd0b431 % UInt
h = hash(typeof(a), h)
h = hash(parent(a), h)
h = hash(coordinates(a), h)
return xor(h, b)
end

function hash(a::AbstractFreeModElem{<:MPolyQuoRingElem}, h::UInt)
simplify!(a)
b = 0xaa2ba4a32dd0b431 % UInt
h = hash(typeof(a), h)
h = hash(parent(a), h)
h = hash(coordinates(a), h)
return xor(h, b)
end

simplify(a::AbstractFreeModElem{<:MPolyQuoRingElem}) = return parent(a)(map_entries(simplify, coordinates(a)))
simplify!(a::AbstractFreeModElem{<:MPolyQuoRingElem}) = simplify(a)

function Base.deepcopy_internal(a::AbstractFreeModElem, dict::IdDict)
return parent(a)(deepcopy_internal(coordinates(a), dict))
end
Expand Down
9 changes: 7 additions & 2 deletions src/Modules/UngradedModules/FreeModuleHom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ FreeModuleHom(F::AbstractFreeMod{T}, G::S, mat::MatElem{T}) where {T,S} = FreeMo

img_gens(f::FreeModuleHom) = images_of_generators(f)
images_of_generators(f::FreeModuleHom) = f.imgs_of_gens::Vector{elem_type(codomain(f))}
image_of_generator(phi::FreeModuleHom, i::Int) = phi.imgs_of_gens[i]::elem_type(codomain(phi))
base_ring_map(f::FreeModuleHom) = f.ring_map
@attr Map function base_ring_map(f::FreeModuleHom{<:SubquoModule, <:ModuleFP, Nothing})
return identity_map(base_ring(domain(f)))
Expand Down Expand Up @@ -239,7 +240,9 @@ hom(F::FreeMod, M::ModuleFP{T}, A::MatElem{T}, h::RingMapType; check::Bool=true)
Return the identity map $id_M$.
"""
function identity_map(M::ModuleFP)
return hom(M, M, gens(M), check=false)
phi = hom(M, M, gens(M), check=false)
phi.generators_map_to_generators = true
return phi
end

### type getters in accordance with the `hom`-constructors
Expand Down Expand Up @@ -460,7 +463,9 @@ function kernel(h::FreeModuleHom) #ONLY for free modules...
R = base_ring(G)
if ngens(G) == 0
s = sub(G, gens(G), :module)
return s, hom(s, G, gens(G), check=false)
help = hom(s, G, gens(G), check=false)
help.generators_map_to_generators = true
return s, help
end
g = map(h, basis(G))
if isa(codomain(h), SubquoModule)
Expand Down
33 changes: 19 additions & 14 deletions src/Modules/UngradedModules/SubQuoHom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function Base.show(io::IO, fmh::SubQuoHom{T1, T2, RingMapType}) where {T1 <: Abs
end

images_of_generators(phi::SubQuoHom) = phi.im::Vector{elem_type(codomain(phi))}
image_of_generator(phi::SubQuoHom, i::Int) = phi.im[i]::elem_type(codomain(phi))

###################################################################

Expand Down Expand Up @@ -344,6 +345,15 @@ function Base.hash(f::ModuleFPHom{T}, h::UInt) where {S<:MPolyElem, T<:ModuleFP{
return xor(h, b)
end

function Base.hash(f::ModuleFPHom, h::UInt)
b = 0x535bbdbb2bc54b46 % UInt
h = hash(typeof(f), h)
h = hash(domain(f), h)
h = hash(codomain(f), h)
# We can not assume that the images of generators
# have a hash in general
return xor(h, b)
end
###################################################################

@doc raw"""
Expand Down Expand Up @@ -458,24 +468,17 @@ function image(f::SubQuoHom, a::SubquoModuleElem)
# f.generators_map_to_generators = images_of_generators(f) == gens(codomain(f))
#end
f.generators_map_to_generators === true && return codomain(f)(map_entries(base_ring_map(f), coordinates(a)))
# TODO matrix vector multiplication
i = zero(codomain(f))
b = coordinates(a)
for (p,v) = b
i += base_ring_map(f)(v)*f.im[p]
end
return i
return sum(b*image_of_generator(f, i) for (i, b) in coordinates(a); init=zero(codomain(f)))
end

function image(f::SubQuoHom{<:SubquoModule, <:ModuleFP, Nothing}, a::SubquoModuleElem)
# TODO matrix vector multiplication
@assert a.parent === domain(f)
if f.generators_map_to_generators === nothing
f.generators_map_to_generators = images_of_generators(f) == gens(codomain(f))
end
f.generators_map_to_generators && return codomain(f)(coordinates(a))
v = images_of_generators(f)
return sum(c*v[i] for (i, c) in coordinates(a); init=zero(codomain(f)))
#if f.generators_map_to_generators === nothing
# f.generators_map_to_generators = images_of_generators(f) == gens(codomain(f))
#end
f.generators_map_to_generators === true && return codomain(f)(coordinates(a))
return sum(c*image_of_generator(f, i) for (i, c) in coordinates(a); init=zero(codomain(f)))
end

@doc raw"""
Expand Down Expand Up @@ -533,7 +536,9 @@ Additionally, if `I` denotes this object, return the inclusion map `I` $\to$ `co
"""
function image(h::SubQuoHom)
s = sub(codomain(h), images_of_generators(h), :module)
return s, hom(s, codomain(h), images_of_generators(h), check=false)
inc = hom(s, codomain(h), images_of_generators(h), check=false)
inc.generators_map_to_generators = true
return s, inc
end

@doc raw"""
Expand Down

0 comments on commit 5c2553e

Please sign in to comment.