Skip to content

Commit

Permalink
Move more obvious piracy from Hecke to Nemo
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Jun 29, 2023
1 parent fc4b618 commit ab672f0
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HeckeMiscMatrix.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export is_zero_row, is_diagonal, is_positive_entry, diagonal
export is_zero_row, is_diagonal, is_lower_triangular, is_positive_entry, is_upper_triangular, diagonal

import LinearAlgebra
LinearAlgebra.dot(a::RingElem, b::RingElem) = a * b
Expand Down
68 changes: 68 additions & 0 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function copy(a::ZZRingElem)
return deepcopy(a)
end

function QQMatrix(x::ZZMatrix)
z = zero_matrix(FlintQQ, nrows(x), ncols(x))
ccall((:fmpq_mat_set_fmpz_mat, libflint), Nothing, (Ref{QQMatrix}, Ref{ZZMatrix}), z, x)
return z
end

function round(::Type{Int}, a::QQFieldElem)
return round(Int, Rational{BigInt}(a))
end

function matrix(a::Vector{Vector{T}}) where {T}
return matrix(permutedims(reduce(hcat, a), (2, 1)))
end

function prime_field(_::NumField)
return QQField()
end

function prime_field(F::fqPolyRepField; cached::Bool=true)
return Native.GF(Int(characteristic(F)), cached=cached)
end

function prime_field(F::FqPolyRepField; cached::Bool=true)
return Native.GF(characteristic(F), cached=cached)
end

function prime_field(F::T; cached::Bool=true) where {T<:Union{fpField,FpField}}
return F
end

function evaluate(f::ZZPolyRingElem, r::fqPolyRepFieldElem)
#Horner - stolen from Claus

if length(f) == 0
return parent(r)()
end

l = f.length - 1
s = parent(r)(coeff(f, l))
for i = l-1:-1:0
s = s * r + parent(r)(coeff(f, i))
end
return s
end

function evaluate!(z::fqPolyRepFieldElem, f::ZZPolyRingElem, r::fqPolyRepFieldElem)
#Horner - stolen from Claus

zero!(z)

if length(f) == 0
return z
end

l = f.length - 1
set!(z, parent(r)(coeff(f, l)))
#s = parent(r)(coeff(f, l))
for i = l-1:-1:0
mul!(z, z, r)
add!(z, z, parent(r)(coeff(f, i)))
#s = s*r + parent(r)(coeff(f, i))
end
return z
end
1 change: 1 addition & 0 deletions src/Nemo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ include("Rings.jl")
include("HeckeMiscInteger.jl")
include("HeckeMiscMatrix.jl")
include("HeckeMiscPoly.jl")
include("HeckeMoreStuff.jl")

###############################################################################
#
Expand Down
14 changes: 14 additions & 0 deletions src/arb/acb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,20 @@ function inv(x::acb)
return z
end

################################################################################
#
# Sign
#
################################################################################

function sign(::Type{Int}, x::acb)
if isreal(x)
return sign(Int, real(x))
else
error("Element is not real")
end
end

################################################################################
#
# Shifting
Expand Down
22 changes: 22 additions & 0 deletions src/arb/arb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,22 @@ function add_error!(x::arb, y::arb)
ccall((:arb_add_error, libarb), Nothing, (Ref{arb}, Ref{arb}), x, y)
end

################################################################################
#
# Sign
#
################################################################################

function sign(::Type{Int}, x::arb)
if is_positive(x)
return 1
elseif is_negative(x)
return -1
else
error("Could not determine sign")
end
end

################################################################################
#
# Unary operations
Expand Down Expand Up @@ -1993,6 +2009,12 @@ function addeq!(z::arb, x::arb)
return z
end

function addmul!(z::arb, x::arb, y::ZZRingElem)
q = max(bits(z), bits(x))
ccall((:arb_addmul_fmpz, libarb), Nothing, (Ref{arb}, Ref{arb}, Ref{ZZRingElem}, Int), z, x, y, q)
return nothing
end

################################################################################
#
# Unsafe setting
Expand Down

0 comments on commit ab672f0

Please sign in to comment.