Skip to content

Commit

Permalink
Move stuff, part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Sep 4, 2023
1 parent ab2dfc1 commit 283cbc6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 178 deletions.
123 changes: 1 addition & 122 deletions src/HeckeMiscMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function denominator(M::QQMatrix)
return d
end

transpose!(A::Union{ZZMatrix, QQMatrix}) = is_square(A) ? transpose!(A, A) : transpose(A)
transpose!(A::Union{ZZMatrix,QQMatrix}) = is_square(A) ? transpose!(A, A) : transpose(A)
transpose!(A::MatrixElem) = transpose(A)

function transpose!(A::ZZMatrix, B::ZZMatrix)
Expand Down Expand Up @@ -355,22 +355,6 @@ end
#
################################################################################

@doc raw"""
kernel(a::MatElem{T}; side::Symbol = :right) -> Int, MatElem{T}
It returns a tuple $(n, M)$, where $n$ is the rank of the kernel and $M$ is a basis for it. If side is $:right$ or not
specified, the right kernel is computed. If side is $:left$, the left kernel is computed.
"""
function kernel(A::MatElem; side::Symbol=:right)
if side == :right
return right_kernel(A)
elseif side == :left
return left_kernel(A)
else
error("Unsupported argument: :$side for side: Must be :left or :right")
end
end

function right_kernel(x::fpMatrix)
z = zero_matrix(base_ring(x), ncols(x), max(nrows(x), ncols(x)))
n = ccall((:nmod_mat_nullspace, libflint), Int, (Ref{fpMatrix}, Ref{fpMatrix}), z, x)
Expand Down Expand Up @@ -497,71 +481,6 @@ function kernel(M::MatrixElem, R::Ring; side::Symbol=:right)
return kernel(MP, side=side)
end

################################################################################
#
# Diagonal (block) matrix creation
#
################################################################################

@doc raw"""
diagonal_matrix(x::T...) where T <: RingElem -> MatElem{T}
diagonal_matrix(x::Vector{T}) where T <: RingElem -> MatElem{T}
diagonal_matrix(Q, x::Vector{T}) where T <: RingElem -> MatElem{T}
Returns a diagonal matrix whose diagonal entries are the elements of $x$.
# Examples
```jldoctest
julia> diagonal_matrix(QQ(1), QQ(2))
[1 0]
[0 2]
julia> diagonal_matrix([QQ(3), QQ(4)])
[3 0]
[0 4]
julia> diagonal_matrix(QQ, [5, 6])
[5 0]
[0 6]
```
"""
function diagonal_matrix(R::Ring, x::Vector{<:RingElement})
x = R.(x)
M = zero_matrix(R, length(x), length(x))
for i = 1:length(x)
M[i, i] = x[i]
end
return M
end

function diagonal_matrix(x::T, xs::T...) where {T<:RingElem}
return diagonal_matrix(collect((x, xs...)))
end

diagonal_matrix(x::Vector{<:RingElement}) = diagonal_matrix(parent(x[1]), x)

@doc raw"""
diagonal_matrix(x::Vector{T}) where T <: MatElem -> MatElem
Returns a block diagonal matrix whose diagonal blocks are the matrices in $x$.
"""
function diagonal_matrix(x::Vector{T}) where {T<:MatElem}
return cat(x..., dims=(1, 2))::T
end

function diagonal_matrix(x::T, xs::T...) where {T<:MatElem}
return cat(x, xs..., dims=(1, 2))::T
end

function diagonal_matrix(R::Ring, x::Vector{<:MatElem})
if length(x) == 0
return zero_matrix(R, 0, 0)
end
x = [change_base_ring(R, i) for i in x]
return diagonal_matrix(x)
end

################################################################################
#
# Reduce the entries of a matrix modulo p
Expand Down Expand Up @@ -1155,49 +1074,9 @@ function to_array(M::QQMatrix)
return A
end

################################################################################
#
# Minpoly and Charpoly
#
################################################################################

function minpoly(M::MatElem)
k = base_ring(M)
kx, x = polynomial_ring(k, cached=false)
return minpoly(kx, M)
end

function charpoly(M::MatElem)
k = base_ring(M)
kx, x = polynomial_ring(k, cached=false)
return charpoly(kx, M)
end

###############################################################################
#
# Sub
#
###############################################################################

function sub(M::MatElem, rows::Vector{Int}, cols::Vector{Int})
N = zero_matrix(base_ring(M), length(rows), length(cols))
for i = 1:length(rows)
for j = 1:length(cols)
N[i, j] = M[rows[i], cols[j]]
end
end
return N
end

function sub(M::MatElem{T}, r::AbstractUnitRange{<:Integer}, c::AbstractUnitRange{<:Integer}) where {T}
z = similar(M, length(r), length(c))
for i in 1:length(r)
for j in 1:length(c)
z[i, j] = M[r[i], c[j]]
end
end
return z
end

################################################################################
#
Expand Down
57 changes: 1 addition & 56 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ function mul!(z::acb, x::acb, y::arb)
return z
end

#TODO: should be done in Nemo/AbstractAlgebra s.w.
# needed by ^ (the generic power in Base using square and multiply)
Base.copy(f::Generic.MPoly) = deepcopy(f)
Base.copy(f::Generic.Poly) = deepcopy(f)

@doc raw"""
valuation(G::QQMatrix, p)
Expand Down Expand Up @@ -173,21 +168,6 @@ end

ZZMatrix(M::Matrix{Int}) = matrix(FlintZZ, M)

zero_matrix(::Type{Int}, r, c) = zeros(Int, r, c)

base_ring(::Vector{Int}) = Int

function AbstractAlgebra.is_symmetric(M::MatElem)
for i in 1:nrows(M)
for j in i:ncols(M)
if M[i, j] != M[j, i]
return false
end
end
end
return true
end

################################################################################
#
# Create a matrix from rows
Expand All @@ -213,15 +193,7 @@ end

order(::ZZRingElem) = FlintZZ

export neg!, rem!

sub!(z::Rational{Int}, x::Rational{Int}, y::Int) = x - y

neg!(z::Rational{Int}, x::Rational{Int}) = -x

add!(z::Rational{Int}, x::Rational{Int}, y::Int) = x + y

mul!(z::Rational{Int}, x::Rational{Int}, y::Int) = x * y
export rem!

is_negative(x::Rational) = x.num < 0

Expand Down Expand Up @@ -523,31 +495,6 @@ end

base_field(_::AnticNumberField) = FlintQQ

#trivia to make life easier

gens(L::SimpleNumField{T}) where {T} = [gen(L)]

function gen(L::SimpleNumField{T}, i::Int) where {T}
i == 1 || error("index must be 1")
return gen(L)
end

function Base.getindex(L::SimpleNumField{T}, i::Int) where {T}
if i == 0
return one(L)
elseif i == 1
return gen(L)
else
error("index has to be 0 or 1")
end
end

ngens(L::SimpleNumField{T}) where {T} = 1

is_unit(a::NumFieldElem) = !iszero(a)

canonical_unit(a::NumFieldElem) = a

################################################################################
#
# Base case for dot products
Expand Down Expand Up @@ -1830,8 +1777,6 @@ function divexact!(A::Generic.Mat{nf_elem}, p::ZZRingElem)
end
end

elem_type(::Type{Generic.ResidueRing{T}}) where {T} = Generic.ResidueRingElem{T}

#
# Lifts a matrix from F_p to Z/p^nZ
#
Expand Down

0 comments on commit 283cbc6

Please sign in to comment.