Skip to content

Commit

Permalink
experimental/GModule: collect AA/Nemo/Hecke stuff in Misc.jl (#3584)
Browse files Browse the repository at this point in the history
Move code to `Misc.jl` that belongs to AbstractAlgebra.jl,
Nemo.jl, or Hecke.jl.

Once we agree that this code should be moved to these packages,
the code should be added there,
and as soon as it becomes available in Oscar, it can be removed
from `Misc.jl`.
  • Loading branch information
ThomasBreuer authored Apr 12, 2024
1 parent 0012b96 commit 24e629c
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 313 deletions.
78 changes: 0 additions & 78 deletions experimental/GModule/Brueckner.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
module RepPc
using Oscar

export coimage

Base.pairs(M::MatElem) = Base.pairs(IndexCartesian(), M)
Base.pairs(::IndexCartesian, M::MatElem) = Base.Iterators.Pairs(M, CartesianIndices(axes(M)))

function Hecke.roots(a::FinFieldElem, i::Int)
kx, x = polynomial_ring(parent(a), cached = false)
return roots(x^i-a)
end

Oscar.matrix(phi::Generic.IdentityMap{<:AbstractAlgebra.FPModule}) = identity_matrix(base_ring(domain(phi)), dim(domain(phi)))


#=TODO
- construct characters along the way as well?
- compare characters rather than the hom_base
Expand Down Expand Up @@ -276,69 +263,6 @@ function brueckner(mQ::Map{<:Oscar.GAPGroup, PcGroup}; primes::Vector=[])
return allR
end

Oscar.gen(M::AbstractAlgebra.FPModule, i::Int) = M[i]

Oscar.is_free(M::Generic.FreeModule) = true
Oscar.is_free(M::Generic.DirectSumModule) = all(is_free, M.m)

function Oscar.dual(h::Map{FinGenAbGroup, FinGenAbGroup})
A = domain(h)
B = codomain(h)
@assert is_free(A) && is_free(B)
return hom(B, A, transpose(h.map))
end

function Oscar.dual(h::Map{<:AbstractAlgebra.FPModule{ZZRingElem}, <:AbstractAlgebra.FPModule{ZZRingElem}})
A = domain(h)
B = codomain(h)
@assert is_free(A) && is_free(B)
return hom(B, A, transpose(matrix(h)))
end

function coimage(h::Map)
return quo(domain(h), kernel(h)[1])
end

function Oscar.cokernel(h::Map)
return quo(codomain(h), image(h)[1])
end

function Base.iterate(M::AbstractAlgebra.FPModule{T}) where T <: FinFieldElem
k = base_ring(M)
if dim(M) == 0
return zero(M), iterate([1])
end
p = Base.Iterators.ProductIterator(Tuple([k for i=1:dim(M)]))
f = iterate(p)
return M(elem_type(k)[f[1][i] for i=1:dim(M)]), (f[2], p)
end

function Base.iterate(::AbstractAlgebra.FPModule{<:FinFieldElem}, ::Tuple{Int64, Int64})
return nothing
end

function Base.iterate(M::AbstractAlgebra.FPModule{T}, st::Tuple{<:Tuple, <:Base.Iterators.ProductIterator}) where T <: FinFieldElem
n = iterate(st[2], st[1])
if n === nothing
return n
end
return M(elem_type(base_ring(M))[n[1][i] for i=1:dim(M)]), (n[2], st[2])
end

function Base.length(M::AbstractAlgebra.FPModule{T}) where T <: FinFieldElem
return Int(order(base_ring(M))^dim(M))
end

function Base.eltype(M::AbstractAlgebra.FPModule{T}) where T <: FinFieldElem
return elem_type(M)
end

function Oscar.dim(M::AbstractAlgebra.Generic.DirectSumModule{<:FieldElem})
return sum(dim(x) for x = M.m)
end

Oscar.is_finite(M::AbstractAlgebra.FPModule{<:FinFieldElem}) = true

"""
mp: G ->> Q
C a F_p[Q]-module
Expand Down Expand Up @@ -497,5 +421,3 @@ orbits(G)
end #module RepPc

using .RepPc

export coimage
81 changes: 0 additions & 81 deletions experimental/GModule/Cohomology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,6 @@ function Oscar.quo(C::GModule, mDC::Map{FinGenAbGroup, FinGenAbGroup}, add_to_la
return S, mq
end

function Oscar.direct_sum(M::AbstractAlgebra.Generic.DirectSumModule{T}, N::AbstractAlgebra.Generic.DirectSumModule{T}, mp::Vector{AbstractAlgebra.Generic.ModuleHomomorphism{T}}) where T
@assert length(M.m) == length(mp) == length(N.m)
return hom(M, N, cat(map(matrix, mp)..., dims = (1,2)))
end

function Oscar.direct_product(C::GModule...; task::Symbol = :none)
@assert task in [:sum, :prod, :both, :none]
G = C[1].G
Expand Down Expand Up @@ -1746,73 +1741,10 @@ function fp_group_with_isomorphism(M::AbstractAlgebra.FPModule{<:FinFieldElem})
end

#########################################################
#XXX: should be in AA and supplemented by a proper quo
Oscar.issubset(M::AbstractAlgebra.FPModule{T}, N::AbstractAlgebra.FPModule{T}) where T<:RingElement = is_submodule(M, N)

function is_sub_with_data(M::AbstractAlgebra.FPModule{T}, N::AbstractAlgebra.FPModule{T}) where T<:RingElement
fl = is_submodule(N, M)
if fl
return fl, hom(M, N, elem_type(N)[N(m) for m = gens(M)])
else
return fl, hom(M, N, elem_type(N)[zero(N) for m = gens(M)])
end
end
is_sub_with_data(M::FinGenAbGroup, N::FinGenAbGroup) = is_subgroup(M, N)

function Oscar.hom(V::Module, W::Module, v::Vector{<:ModuleElem}; check::Bool = true)
if ngens(V) == 0
return Generic.ModuleHomomorphism(V, W, zero_matrix(base_ring(V), ngens(V), ngens(W)))
end
return Generic.ModuleHomomorphism(V, W, reduce(vcat, [x.v for x = v]))
end
function Oscar.hom(V::Module, W::Module, v::MatElem; check::Bool = true)
return Generic.ModuleHomomorphism(V, W, v)
end
function Oscar.inv(M::Generic.ModuleHomomorphism)
return hom(codomain(M), domain(M), inv(matrix(M)))
end

function Oscar.direct_product(M::Module...; task::Symbol = :none)
D, inj, pro = direct_sum(M...)
if task == :none
return D
elseif task == :both
return D, pro, inj
elseif task == :sum
return D, inj
elseif task == :prod
return D, pro
end
error("illegal task")
end

Base.:*(a::T, b::Generic.ModuleHomomorphism{T}) where {T} = hom(domain(b), codomain(b), a * matrix(b))
Base.:*(a::T, b::Generic.ModuleIsomorphism{T}) where {T} = hom(domain(b), codomain(b), a * matrix(b))
Base.:+(a::Generic.ModuleHomomorphism, b::Generic.ModuleHomomorphism) = hom(domain(a), codomain(a), matrix(a) + matrix(b))
Base.:-(a::Generic.ModuleHomomorphism, b::Generic.ModuleHomomorphism) = hom(domain(a), codomain(a), matrix(a) - matrix(b))
Base.:-(a::Generic.ModuleHomomorphism) = hom(domain(a), codomain(a), -matrix(a))

function Oscar.matrix(M::FreeModuleHom{FreeMod{QQAbElem}, FreeMod{QQAbElem}})
return M.matrix
end

function ==(a::Union{Generic.ModuleHomomorphism, Generic.ModuleIsomorphism}, b::Union{Generic.ModuleHomomorphism, Generic.ModuleIsomorphism})
domain(a) === domain(b) || return false
codomain(a) === codomain(b) || return false
return matrix(a) == matrix(b)
end

function Base.hash(a::Union{Generic.ModuleHomomorphism, Generic.ModuleIsomorphism}, h::UInt)
h = hash(domain(a), h)
h = hash(codomain(a), h)
h = hash(matrix(a), h)
return h
end

function Oscar.id_hom(A::AbstractAlgebra.FPModule)
return Generic.ModuleHomomorphism(A, A, identity_matrix(base_ring(A), ngens(A)))
end

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

#=
Expand Down Expand Up @@ -1921,19 +1853,6 @@ function pc_group_with_isomorphism(M::FinGenAbGroup; refine::Bool = true)
x->image(mM, gap_to_julia(x.X)))
end

function (k::Nemo.fpField)(a::Vector)
@assert length(a) == 1
return k(a[1])
end

function (k::fqPolyRepField)(a::Vector)
return k(polynomial(Native.GF(Int(characteristic(k))), a))
end

function Oscar.order(F::AbstractAlgebra.FPModule{<:FinFieldElem})
return order(base_ring(F))^dim(F)
end

function pc_group_with_isomorphism(M::AbstractAlgebra.FPModule{<:FinFieldElem}; refine::Bool = true)
k = base_ring(M)
p = characteristic(k)
Expand Down
117 changes: 0 additions & 117 deletions experimental/GModule/GModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,6 @@ import Oscar.GrpCoh: MultGrp, MultGrpElem
import AbstractAlgebra: Group, Module
import Base: parent


#XXX: have a type for an implicit field - in Hecke?
# add all(?) the other functions to it
function relative_field(m::Map{<:AbstractAlgebra.Field, <:AbstractAlgebra.Field})
k = domain(m)
K = codomain(m)
@assert base_field(k) == base_field(K)
kt, t = polynomial_ring(k, cached = false)
f = defining_polynomial(K)
Qt = parent(f)
#the Trager construction, works for extensions of the same field given
#via primitive elements
h = gcd(gen(k) - map_coefficients(k, Qt(m(gen(k))), parent = kt), map_coefficients(k, f, parent = kt))
coordinates = function(x::FieldElem)
@assert parent(x) == K
c = collect(Hecke.coefficients(map_coefficients(k, Qt(x), parent = kt) % h))
c = vcat(c, zeros(k, degree(h)-length(c)))
return c
end
rep_mat = function(x::FieldElem)
@assert parent(x) == K
c = map_coefficients(k, Qt(x), parent = kt) % h
m = collect(Hecke.coefficients(c))
m = vcat(m, zeros(k, degree(h) - length(m)))
r = m
for i in 2:degree(h)
c = shift_left(c, 1) % h
m = collect(Hecke.coefficients(c))
m = vcat(m, zeros(k, degree(h) - length(m)))
r = hcat(r, m)
end
return transpose(matrix(r))
end
return h, coordinates, rep_mat
end

"""
restriction_of_scalars(M::GModule, phi::Map)
Expand Down Expand Up @@ -299,10 +263,6 @@ function invariant_lattice_classes(M::GModule{<:Oscar.GAPGroup, <:AbstractAlgebr
return invariant_lattice_classes(MZ)
end

function Oscar.pseudo_inv(h::Generic.ModuleHomomorphism)
return MapFromFunc(codomain(h), domain(h), x->preimage(h, x))
end

function _hom(f::Map{<:AbstractAlgebra.FPModule{T}, <:AbstractAlgebra.FPModule{T}}) where T
@assert base_ring(domain(f)) == base_ring(codomain(f))
return hom(domain(f), codomain(f), f.(gens(domain(f))))
Expand Down Expand Up @@ -1238,15 +1198,6 @@ inj = hom(C.M, H.M, [preimage(mH, hom(zg.M, C.M, [ac(C)(g)(c) for g = gens(zg.M)
q, mq = quo(H, image(inj)[2])
=#

Oscar.parent(H::AbstractAlgebra.Generic.ModuleHomomorphism{<:FieldElem}) = Hecke.MapParent(domain(H), codomain(H), "homomorphisms")

function Oscar.hom(F::AbstractAlgebra.FPModule{T}, G::AbstractAlgebra.FPModule{T}) where T
k = base_ring(F)
@assert base_ring(G) == k
H = free_module(k, dim(F)*dim(G))
return H, MapFromFunc(H, Hecke.MapParent(F, G, "homomorphisms"), x->hom(F, G, matrix(k, dim(F), dim(G), vec(collect(x.v)))), y->H(vec(collect(transpose(matrix(y))))))
end

function hom_base(C::GModule{S, <:AbstractAlgebra.FPModule{T}}, D::GModule{S, <:AbstractAlgebra.FPModule{T}}) where {S <: Oscar.GAPGroup, T <: FinFieldElem}
@assert base_ring(C) == base_ring(D)
h = Oscar.iso_oscar_gap(base_ring(C))
Expand Down Expand Up @@ -1568,41 +1519,11 @@ function Oscar.gmodule(::Type{FinGenAbGroup}, C::GModule{T, <:AbstractAlgebra.FP
return Oscar.gmodule(A, Group(C), [hom(A, A, map_entries(lift, matrix(x))) for x = C.ac])
end

function Oscar.abelian_group(M::Generic.FreeModule{ZZRingElem})
A = free_abelian_group(rank(M))
return A, MapFromFunc(A, M, x->M(x.coeff), y->A(y.v))
end

function Oscar.gmodule(::Type{FinGenAbGroup}, C::GModule{T, <:AbstractAlgebra.FPModule{ZZRingElem}}) where {T <: Oscar.GAPGroup}
A, mA = abelian_group(C.M)
return Oscar.gmodule(A, Group(C), [hom(A, A, matrix(x)) for x = C.ac])
end

#TODO: for modern fin. fields as well
function Oscar.abelian_group(M::AbstractAlgebra.FPModule{fqPolyRepFieldElem})
k = base_ring(M)
A = abelian_group([characteristic(k) for i = 1:dim(M)*degree(k)])
n = degree(k)
function to_A(m::AbstractAlgebra.FPModuleElem{fqPolyRepFieldElem})
a = ZZRingElem[]
for i=1:dim(M)
c = m[i]
for j=0:n-1
push!(a, coeff(c, j))
end
end
return A(a)
end
function to_M(a::FinGenAbGroupElem)
m = fqPolyRepFieldElem[]
for i=1:dim(M)
push!(m, k([a[j] for j=(i-1)*n+1:i*n]))
end
return M(m)
end
return A, MapFromFunc(A, M, to_M, to_A)
end

function Oscar.gmodule(chi::Oscar.GAPGroupClassFunction)
f = GAP.Globals.IrreducibleAffordingRepresentation(chi.values)
K = abelian_closure(QQ)[1]
Expand Down Expand Up @@ -1659,44 +1580,6 @@ function Oscar.simplify(C::GModule{<:Any, <:AbstractAlgebra.FPModule{ZZRingElem}
end
end

function Hecke.induce_crt(a::Generic.MatSpaceElem{AbsSimpleNumFieldElem}, b::Generic.MatSpaceElem{AbsSimpleNumFieldElem}, p::ZZRingElem, q::ZZRingElem)
c = parent(a)()
pi = invmod(p, q)
mul!(pi, pi, p)
pq = p*q
z = ZZRingElem(0)

for i=1:nrows(a)
for j=1:ncols(a)
c[i,j] = Hecke.induce_inner_crt(a[i,j], b[i,j], pi, pq, z)
end
end
return c
end

function Hecke.induce_rational_reconstruction(a::Generic.MatSpaceElem{AbsSimpleNumFieldElem}, pg::ZZRingElem; ErrorTolerant::Bool = false)
c = parent(a)()
for i=1:nrows(a)
for j=1:ncols(a)
fl, c[i,j] = rational_reconstruction(a[i,j], pg)#, ErrorTolerant = ErrorTolerant)
fl || return fl, c
end
end
return true, c
end

function Hecke.induce_rational_reconstruction(a::ZZMatrix, pg::ZZRingElem; ErrorTolerant::Bool = false)
c = zero_matrix(QQ, nrows(a), ncols(a))
for i=1:nrows(a)
for j=1:ncols(a)
fl, n, d = rational_reconstruction(a[i,j], pg, ErrorTolerant = ErrorTolerant)
fl || return fl, c
c[i,j] = n//d
end
end
return true, c
end

export extension_of_scalars
export factor_set
export ghom
Expand Down
Loading

0 comments on commit 24e629c

Please sign in to comment.