Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move code from Oscar.jl/experimental/GModule/Misc.jl here #1456

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/GrpAb/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
gens(G::FinGenAbGroup) = FinGenAbGroupElem[G[i] for i = 1:ngens(G)]

@doc raw"""
gen(G::FinGenAbGroup, i::Int) -> Vector{FinGenAbGroupElem}
gen(G::FinGenAbGroup, i::Int) -> FinGenAbGroupElem

The $i$-th generator of $G$.
"""
Expand Down Expand Up @@ -293,6 +293,12 @@
return z
end

function (A::FinGenAbGroup)(x::FinGenAbGroupElem)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasBreuer @fieker so this is the function we talked about this morning, which is the reason (or at least a reason) why the GModule tests are run in Oscar even when "exclude experimental" is active...

But this PR here is waiting for @ThomasBreuer to finish it up -- then we can make a Hecke release, adjust Oscar, and perhaps get rid of that hack in Oscar....

fl, m = is_subgroup(parent(x), A)
@assert fl
return m(x)

Check warning on line 299 in src/GrpAb/Elem.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/Elem.jl#L296-L299

Added lines #L296 - L299 were not covered by tests
end

function (A::FinGenAbGroup)()
y = zero_matrix(FlintZZ, 1, ngens(A))
z = FinGenAbGroupElem(A, y)
Expand Down
59 changes: 59 additions & 0 deletions src/GrpAb/GrpAbFinGen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@
return abelian_group(FinGenAbGroup, M, name=name)
end

function 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))

Check warning on line 89 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L87-L89

Added lines #L87 - L89 were not covered by tests
end

#TODO: for modern fin. fields as well
function 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)

Check warning on line 105 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L93-L105

Added lines #L93 - L105 were not covered by tests
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)

Check warning on line 112 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L107-L112

Added lines #L107 - L112 were not covered by tests
end
return A, MapFromFunc(A, M, to_M, to_A)

Check warning on line 114 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L114

Added line #L114 was not covered by tests
end

function abelian_group(::Type{FinGenAbGroup}, M::AbstractMatrix{<:IntegerUnion}; name::String = "")
return abelian_group(matrix(FlintZZ, M), name=name)
end
Expand Down Expand Up @@ -662,6 +692,27 @@
return _direct_product(:sum, G...; task = task, kwargs...)
end

@doc raw"""
direct_sum(G::FinGenAbGroup, H::FinGenAbGroup, V::Vector{<:Map{FinGenAbGroup, FinGenAbGroup}})

For groups `G = prod G_i` and `H = prod H_i` as well as maps `V_i: G_i -> H_i`,
build the induced map from `G -> H`.
"""
function direct_sum(G::FinGenAbGroup, H::FinGenAbGroup, V::Vector{<:Map{FinGenAbGroup, FinGenAbGroup}})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is already added in #1488 under the name hom_direct_sum. Once #1488 gets merged, this should get removed here.

dG = get_attribute(G, :direct_product)
dH = get_attribute(H, :direct_product)

Check warning on line 703 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L701-L703

Added lines #L701 - L703 were not covered by tests

if dG === nothing || dH === nothing
error("both groups need to be direct products")

Check warning on line 706 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L705-L706

Added lines #L705 - L706 were not covered by tests
end
@assert length(V) == length(dG) == length(dH)

Check warning on line 708 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L708

Added line #L708 was not covered by tests

@assert all(i -> domain(V[i]) == dG[i] && codomain(V[i]) == dH[i], 1:length(V))
h = hom(G, H, cat([matrix(V[i]) for i=1:length(V)]..., dims=(1,2)), check = !true)
return h

Check warning on line 712 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L710-L712

Added lines #L710 - L712 were not covered by tests
end


@doc raw"""
direct_product(G::FinGenAbGroup...) -> FinGenAbGroup, Vector{FinGenAbGroupHom}

Expand Down Expand Up @@ -839,6 +890,13 @@
return identity_matrix(FlintZZ, ngens(domain(M)))
end

function 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))

Check warning on line 897 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L893-L897

Added lines #L893 - L897 were not covered by tests
end

@doc raw"""
hom(G::FinGenAbGroup, H::FinGenAbGroup, A::Matrix{ <: Map{FinGenAbGroup, FinGenAbGroup}}) -> Map

Expand Down Expand Up @@ -1506,6 +1564,7 @@

#checks if the image of mG contains the image of mH

is_sub_with_data(M::FinGenAbGroup, N::FinGenAbGroup) = is_subgroup(M, N)

Check warning on line 1567 in src/GrpAb/GrpAbFinGen.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/GrpAbFinGen.jl#L1567

Added line #L1567 was not covered by tests

#cannot define == as this produces problems elsewhere... need some thought
function is_eq(G::FinGenAbGroup, H::FinGenAbGroup, L::GrpAbLattice = GroupLattice)
Expand Down
3 changes: 3 additions & 0 deletions src/GrpAb/Map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@
return quo(codomain(h), FinGenAbGroupElem[mS(g) for g in gens(S)], add_to_lattice)
end

cokernel(h::Map) = quo(codomain(h), image(h)[1])

Check warning on line 345 in src/GrpAb/Map.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/Map.jl#L345

Added line #L345 was not covered by tests


################################################################################
#
# Surjectivity
Expand Down
2 changes: 2 additions & 0 deletions src/LocalField/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
end
end

parent(f::LocalFieldMor) = NfMorSet(domain(f))

Check warning on line 32 in src/LocalField/map.jl

View check run for this annotation

Codecov / codecov/patch

src/LocalField/map.jl#L32

Added line #L32 was not covered by tests

################################################################################
#
# Identity
Expand Down
4 changes: 4 additions & 0 deletions src/Map/Map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
return InverseMap(a)
end

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

Check warning on line 22 in src/Map/Map.jl

View check run for this annotation

Codecov / codecov/patch

src/Map/Map.jl#L21-L22

Added lines #L21 - L22 were not covered by tests
end

#function show(io::IO, M::CoerceMap)
# println(io, "Coerce: $(domain(M)) -> $(codomain(M))")
#end
Expand Down
2 changes: 2 additions & 0 deletions src/Map/NumberField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
return morphism_type(T, T)
end

elem_type(::Type{NfMorSet{T}}) where {T <: LocalField} = LocalFieldMor{T, T}

Check warning on line 9 in src/Map/NumberField.jl

View check run for this annotation

Codecov / codecov/patch

src/Map/NumberField.jl#L9

Added line #L9 was not covered by tests

function show(io::IO, S::NfMorSet{T}) where {T}
print(io, "Set of automorphisms of ", S.field)
end
Expand Down
34 changes: 34 additions & 0 deletions src/Misc/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,37 @@
return dot(f.B, (f.L).(map(f.f, v)))::elem_type(f.L)
end

#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)

Check warning on line 188 in src/Misc/Fields.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/Fields.jl#L182-L188

Added lines #L182 - L188 were not covered by tests
#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

Check warning on line 196 in src/Misc/Fields.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/Fields.jl#L191-L196

Added lines #L191 - L196 were not covered by tests
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))

Check warning on line 210 in src/Misc/Fields.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/Fields.jl#L198-L210

Added lines #L198 - L210 were not covered by tests
end
return h, coordinates, rep_mat

Check warning on line 212 in src/Misc/Fields.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/Fields.jl#L212

Added line #L212 was not covered by tests
end
23 changes: 23 additions & 0 deletions src/Misc/RatRecon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@
return fl!=0, numerator(res), denominator(res)
end

function 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

Check warning on line 122 in src/Misc/RatRecon.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/RatRecon.jl#L113-L122

Added lines #L113 - L122 were not covered by tests
end

#Note: the vector version might be useful - or the mult by previous den version
#Note: missing reconstruction modulo a true ideal. W/o denominators

Expand Down Expand Up @@ -137,6 +149,17 @@
return true, K(res)
end

function 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

Check warning on line 160 in src/Misc/RatRecon.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/RatRecon.jl#L152-L160

Added lines #L152 - L160 were not covered by tests
end

# to appease the Singular crowd...
farey_lift = rational_reconstruction

Expand Down
2 changes: 2 additions & 0 deletions src/NumField/ComplexEmbeddings/Generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
"""
restrict(f::NumFieldEmb, K::NumFieldHom)

restrict(::Hecke.NumFieldEmb, ::Map{QQField, AbsSimpleNumField}) = complex_embeddings(QQ)[1]

Check warning on line 160 in src/NumField/ComplexEmbeddings/Generic.jl

View check run for this annotation

Codecov / codecov/patch

src/NumField/ComplexEmbeddings/Generic.jl#L160

Added line #L160 was not covered by tests

################################################################################
#
# Extension
Expand Down
2 changes: 2 additions & 0 deletions src/NumField/ComplexEmbeddings/QQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

is_real(::QQEmb) = true

extend(::QQEmb, mp::MapFromFunc{QQField, AbsSimpleNumField}) = complex_embeddings(codomain(mp))

Check warning on line 28 in src/NumField/ComplexEmbeddings/QQ.jl

View check run for this annotation

Codecov / codecov/patch

src/NumField/ComplexEmbeddings/QQ.jl#L28

Added line #L28 was not covered by tests

restrict(::NumFieldEmb, ::QQField) = QQEmb()

restrict(e::NumFieldEmb, f::NumFieldHom{QQField}) = QQEmb()
Expand Down
15 changes: 15 additions & 0 deletions src/NumField/NfAbs/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@
return c
end

function 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)

Check warning on line 239 in src/NumField/NfAbs/Elem.jl

View check run for this annotation

Codecov / codecov/patch

src/NumField/NfAbs/Elem.jl#L234-L239

Added lines #L234 - L239 were not covered by tests

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

Check warning on line 246 in src/NumField/NfAbs/Elem.jl

View check run for this annotation

Codecov / codecov/patch

src/NumField/NfAbs/Elem.jl#L241-L246

Added lines #L241 - L246 were not covered by tests
end

################################################################################
#
# Norm
Expand Down
1 change: 1 addition & 0 deletions src/NumFieldOrd/NfOrd/Ideal/Relative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
return minimum(m, numerator(I))//denominator(I)
end

Base.minimum(::Map{QQField, AbsSimpleNumField}, I::Union{Hecke.AbsNumFieldOrderIdeal, Hecke.AbsNumFieldOrderFractionalIdeal}) = minimum(I)*ZZ

Check warning on line 100 in src/NumFieldOrd/NfOrd/Ideal/Relative.jl

View check run for this annotation

Codecov / codecov/patch

src/NumFieldOrd/NfOrd/Ideal/Relative.jl#L100

Added line #L100 was not covered by tests

################################################################################
#
Expand Down
34 changes: 34 additions & 0 deletions src/QuadForm/Spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@
return AbstractSpaceMor(V, W, B)
end

function 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))))))

Check warning on line 28 in src/QuadForm/Spaces.jl

View check run for this annotation

Codecov / codecov/patch

src/QuadForm/Spaces.jl#L24-L28

Added lines #L24 - L28 were not covered by tests
end

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

Check warning on line 32 in src/QuadForm/Spaces.jl

View check run for this annotation

Codecov / codecov/patch

src/QuadForm/Spaces.jl#L31-L32

Added lines #L31 - L32 were not covered by tests
end

function 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)))

Check warning on line 39 in src/QuadForm/Spaces.jl

View check run for this annotation

Codecov / codecov/patch

src/QuadForm/Spaces.jl#L35-L39

Added lines #L35 - L39 were not covered by tests
end

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

Check warning on line 42 in src/QuadForm/Spaces.jl

View check run for this annotation

Codecov / codecov/patch

src/QuadForm/Spaces.jl#L42

Added line #L42 was not covered by tests

matrix(f::AbstractSpaceMor) = f.matrix

function image(f::AbstractSpaceMor, v::Vector)
Expand Down Expand Up @@ -755,6 +775,20 @@

direct_product(x::Vararg{AbstractSpace}) = direct_product(collect(x))

function direct_product(M::AbstractAlgebra.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

Check warning on line 787 in src/QuadForm/Spaces.jl

View check run for this annotation

Codecov / codecov/patch

src/QuadForm/Spaces.jl#L778-L787

Added lines #L778 - L787 were not covered by tests
end
error("illegal task")

Check warning on line 789 in src/QuadForm/Spaces.jl

View check run for this annotation

Codecov / codecov/patch

src/QuadForm/Spaces.jl#L789

Added line #L789 was not covered by tests
end

@doc raw"""
biproduct(x::Vararg{T}) where T <: AbstractSpace -> T, Vector{AbstractSpaceMor}, Vector{AbstractSpaceMor}
biproduct(x::Vector{T}) where T <: AbstractSpace -> T, Vector{AbstractSpaceMor}, Vector{AbstractSpaceMor}
Expand Down
1 change: 1 addition & 0 deletions src/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ export reduction_type
export refine_alpha_bound
export regulator
export relations
export relative_field
export relative_residue_field
export relative_simple_extension
export rels
Expand Down
Loading