Skip to content

Commit

Permalink
Add missing 'check' argument to several divexact methods (#1332)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored Dec 22, 2023
1 parent fac876f commit 4fb1f9b
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 58 deletions.
4 changes: 2 additions & 2 deletions examples/MultDep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ function *(a::GeIdeal, b::GeIdeal)
return GeIdeal(a.a * b.a)
end

function divexact(a::GeIdeal, b::GeIdeal)
function divexact(a::GeIdeal, b::GeIdeal; check::Bool=true)
make_compatible!(a, b)
return GeIdeal(divexact(a.a, b.a))
return GeIdeal(divexact(a.a, b.a; check=check))
end

Hecke.norm(a::GeIdeal) = norm(a.a)
Expand Down
2 changes: 1 addition & 1 deletion examples/Suri.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ parent(a::RRSelem) = a.R
+(a::RRSelem, b::RRSelem) = RRSelem(a.R, [mod(a.x[i]+b.x[i], a.R.p[i]) for i=1:length(a.x)], mod(a.r+b.r, a.R.r))
*(a::RRSelem, b::RRSelem) = RRSelem(a.R, [mod(a.x[i]*b.x[i], a.R.p[i]) for i=1:length(a.x)], mod(a.r*b.r, a.R.r))
*(a::Integer, b::RRSelem) = RRSelem(b.R, [mod(a*b.x[i], b.R.p[i]) for i=1:length(b.x)], mod(a*b.r, b.R.r))
divexact(a::RRSelem, b::RRSelem) = RRSelem(a.R, [mod(a.x[i]*invmod(b.x[i], a.R.p[i]), a.R.p[i]) for i=1:length(a.x)], mod(a.r*invmod(b.r, a.R.r), a.R.r))
divexact(a::RRSelem, b::RRSelem; check::Bool=true) = RRSelem(a.R, [mod(a.x[i]*invmod(b.x[i], a.R.p[i]), a.R.p[i]) for i=1:length(a.x)], mod(a.r*invmod(b.r, a.R.r), a.R.r))
-(a::RRSelem) = RRSelem(a.R, [mod(-a.x[i], a.R.p[i]) for i=1:length(a.x)], -a.r)
^(a::RRSelem, e::Integer) = RRSelem(a.R, [powermod(a.x[i], e, a.R.p[i]) for i=1:length(a.x)], powermod(a.r, e, a.R.r))
(R::RRS)() = RRSelem(R, ZZRingElem[0 for i=1:length(R.p)], ZZRingElem(0))
Expand Down
6 changes: 3 additions & 3 deletions src/AlgAss/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ function is_divisible(a::AbsAlgAssElem, b::AbsAlgAssElem, action::Symbol)
end

# Computes a/b if action is :right and b\a if action is :left (and if this is possible)
function divexact(a::AbsAlgAssElem, b::AbsAlgAssElem, action::Symbol = :left)
function divexact(a::AbsAlgAssElem, b::AbsAlgAssElem, action::Symbol = :left; check::Bool=true)
t, c = is_divisible(a, b, action)
if !t
error("Division not possible")
Expand All @@ -426,14 +426,14 @@ end
Returns an element $c$ such that $a = c \cdot b$.
"""
divexact_right(a::AbsAlgAssElem, b::AbsAlgAssElem) = divexact(a, b, :right)
divexact_right(a::AbsAlgAssElem, b::AbsAlgAssElem; check::Bool=true) = divexact(a, b, :right; check=check)

@doc raw"""
divexact_left(a::AbsAlgAssElem, b::AbsAlgAssElem) -> AbsAlgAssElem
Returns an element $c$ such that $a = b \cdot c$.
"""
divexact_left(a::AbsAlgAssElem, b::AbsAlgAssElem) = divexact(a, b, :left)
divexact_left(a::AbsAlgAssElem, b::AbsAlgAssElem; check::Bool=true) = divexact(a, b, :left; check=check)

################################################################################
#
Expand Down
12 changes: 6 additions & 6 deletions src/AlgAssAbsOrd/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,26 +227,26 @@ function divexact(a::T, b::T, action::Symbol, check::Bool = true) where { T <: U
end

@doc raw"""
divexact_right(a::AlgAssAbsOrdElem, b::AlgAssAbsOrdElem, check::Bool = true)
divexact_right(a::AlgAssRelOrdElem, b::AlgAssRelOrdElem, check::Bool = true)
divexact_right(a::AlgAssAbsOrdElem, b::AlgAssAbsOrdElem; check::Bool = true)
divexact_right(a::AlgAssRelOrdElem, b::AlgAssRelOrdElem; check::Bool = true)
-> AlgAssRelOrdElem
Returns an element $c \in O$ such that $a = c \cdot b$ where $O$ is the order
containing $a$.
If `check` is `false`, it is not checked whether $c$ is an element of $O$.
"""
divexact_right(a::T, b::T, check::Bool = true) where { T <: Union{ AlgAssAbsOrdElem, AlgAssRelOrdElem } } = divexact(a, b, :right, check)
divexact_right(a::T, b::T; check::Bool = true) where { T <: Union{ AlgAssAbsOrdElem, AlgAssRelOrdElem } } = divexact(a, b, :right, check)

@doc raw"""
divexact_left(a::AlgAssAbsOrdElem, b::AlgAssAbsOrdElem, check::Bool = true)
divexact_left(a::AlgAssRelOrdElem, b::AlgAssRelOrdElem, check::Bool = true)
divexact_left(a::AlgAssAbsOrdElem, b::AlgAssAbsOrdElem; check::Bool = true)
divexact_left(a::AlgAssRelOrdElem, b::AlgAssRelOrdElem; check::Bool = true)
-> AlgAssRelOrdElem
Returns an element $c \in O$ such that $a = b \cdot c$ where $O$ is the order
containing $a$.
If `check` is `false`, it is not checked whether $c$ is an element of $O$.
"""
divexact_left(a::T, b::T, check::Bool = true) where { T <: Union{ AlgAssAbsOrdElem, AlgAssRelOrdElem } } = divexact(a, b, :left, check)
divexact_left(a::T, b::T; check::Bool = true) where { T <: Union{ AlgAssAbsOrdElem, AlgAssRelOrdElem } } = divexact(a, b, :left, check)

################################################################################
#
Expand Down
4 changes: 2 additions & 2 deletions src/AlgAssAbsOrd/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ end
Returns an ideal $c$ such that $a = b \cdot c$.
"""
function divexact_left(a::AlgAssAbsOrdIdl{S, T}, b::AlgAssAbsOrdIdl{S, T}) where { S, T }
function divexact_left(a::AlgAssAbsOrdIdl{S, T}, b::AlgAssAbsOrdIdl{S, T}; check::Bool=true) where { S, T }
@assert algebra(a) === algebra(b)
M = _colon_raw(a, b, :left)
c = ideal(algebra(a), M)
Expand All @@ -1371,7 +1371,7 @@ end
Returns an ideal $c$ such that $a = c \cdot b$.
"""
function divexact_right(a::AlgAssAbsOrdIdl{S, T}, b::AlgAssAbsOrdIdl{S, T}) where { S, T }
function divexact_right(a::AlgAssAbsOrdIdl{S, T}, b::AlgAssAbsOrdIdl{S, T}; check::Bool=true) where { S, T }
@assert algebra(a) === algebra(b)
M = _colon_raw(a, b, :right)
c = ideal(algebra(a), M)
Expand Down
4 changes: 2 additions & 2 deletions src/AlgAssRelOrd/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ end
Returns an ideal $c$ such that $a = b \cdot c$.
"""
function divexact_left(a::AlgAssRelOrdIdl{S, T, U}, b::AlgAssRelOrdIdl{S, T, U}) where { S, T, U }
function divexact_left(a::AlgAssRelOrdIdl{S, T, U}, b::AlgAssRelOrdIdl{S, T, U}; check::Bool=true) where { S, T, U }
@assert algebra(a) === algebra(b)
PM = _colon_raw(a, b, :left)
c = ideal(algebra(a), PM)
Expand All @@ -1582,7 +1582,7 @@ end
Returns an ideal $c$ such that $a = c \cdot b$.
"""
function divexact_right(a::AlgAssRelOrdIdl{S, T, U}, b::AlgAssRelOrdIdl{S, T, U}) where { S, T, U }
function divexact_right(a::AlgAssRelOrdIdl{S, T, U}, b::AlgAssRelOrdIdl{S, T, U}; check::Bool=true) where { S, T, U }
@assert algebra(a) === algebra(b)
PM = _colon_raw(a, b, :right)
c = ideal(algebra(a), PM)
Expand Down
8 changes: 8 additions & 0 deletions src/Deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@

@deprecate field_of_fractions(O::GenOrd) function_field(O::GenOrd)

# Deprecated during 0.23.*

@deprecate divexact_right(a::T, b::T, check::Bool) where { T <: Union{ AlgAssAbsOrdElem, AlgAssRelOrdElem } } divexact(a, b, :right, check)
@deprecate divexact_left(a::T, b::T, check::Bool) where { T <: Union{ AlgAssAbsOrdElem, AlgAssRelOrdElem } } divexact(a, b, :left, check)
@deprecate divexact(a::NumFieldOrdElem, b::Integer, check::Bool) divexact(a, b; check=check)
@deprecate divexact(a::NumFieldOrdElem, b::ZZRingElem, check::Bool) divexact(a, b; check=check)
@deprecate divexact(x::T, y::T, check::Bool) where T <: NumFieldOrdElem divexact(x, y; check=check)

# Things that moved to Nemo

# > 0.18.1
Expand Down
6 changes: 3 additions & 3 deletions src/GrpAb/Dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ function *(a::Integer, b::QmodnZElem)
return QmodnZElem(b.parent, a*b.elt)
end

function divexact(a::QmodnZElem, b::ZZRingElem)
function divexact(a::QmodnZElem, b::ZZRingElem; check::Bool=true)
iszero(b) && throw(DivideError())
return QmodnZElem(a.parent, a.elt // b)
end

function divexact(a::QmodnZElem, b::Integer)
function divexact(a::QmodnZElem, b::Integer; check::Bool=true)
iszero(b) && throw(DivideError())
return QmodnZElem(a.parent, a.elt // b)
end
Expand Down Expand Up @@ -292,7 +292,7 @@ function H2_G_QmodZ_restriction(G::GrpAbFinGen, U::Vector{GrpAbFinGen})
sigma should be unique if g, h run through the generattors
Let chi in Dual(H) and U < G a subgrooup
Dual(G) -> Dual(U) is the composition: U->G
Dual(G) -> Dual(U) is the composition: U->G
=#
#function chi(sigma) #in H return the cocycle
# return (g, h) -> mD(sigma)(H([g[i]*h[j] - g[j]*h[i] for i=1:length(e) for j=i+1:length(e)]))
Expand Down
12 changes: 6 additions & 6 deletions src/LocalField/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ end
#
################################################################################

iszero(a::LocalFieldElem) = iszero(a.data)
iszero(a::LocalFieldElem) = iszero(a.data)

#in ramified fields the generator is the uniformizer and has valuation 1
# precision is measured in powers of a uniformizer, but the uniformizer
Expand Down Expand Up @@ -304,7 +304,7 @@ end
@doc raw"""
valuation(a::LocalFieldElem) -> QQFieldElem
The valuation of $a$, normalized so that $v(p) = 1$. Scale by the
The valuation of $a$, normalized so that $v(p) = 1$. Scale by the
`absolute_ramification_index` to get a surjection onto ZZ.
"""
function valuation(a::LocalFieldElem{S, T}) where {S <: FieldElem, T <: LocalFieldParameter}
Expand Down Expand Up @@ -634,15 +634,15 @@ end

function uniformizer(L::LocalField, v::Int; prec::Int = 20) #precision????
if v > 0
return setprecision(L, prec) do
return setprecision(L, prec) do
uniformizer(L)^v
end
end

if !isa(L, LocalField{<:Any, EisensteinLocalField})
return L(uniformizer(base_field(L), v, prec = prec))
end

#possibly compute the pi^v only for v mod e the complicated way, and scale
#by prime number afterwards
#also: find out abs and rel prec....
Expand Down Expand Up @@ -836,7 +836,7 @@ function _log_one_units(a::LocalFieldElem)
return r
end

function divexact(a::LocalFieldElem, b::Union{Integer, ZZRingElem})
function divexact(a::LocalFieldElem, b::Union{Integer, ZZRingElem}; check::Bool=true)
iszero(a) && return a
p = prime(parent(a))
v = valuation(b, p)
Expand Down
2 changes: 1 addition & 1 deletion src/LocalField/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ function gcdx(f::Generic.Poly{T}, g::Generic.Poly{T}) where T <: Union{padic, qa
return (DD, UU, VV)::Tuple{Generic.Poly{T}, Generic.Poly{T}, Generic.Poly{T}}
end

function divexact(f1::AbstractAlgebra.PolyRingElem{T}, g1::AbstractAlgebra.PolyRingElem{T}) where T <: Union{padic, qadic, LocalFieldElem}
function divexact(f1::AbstractAlgebra.PolyRingElem{T}, g1::AbstractAlgebra.PolyRingElem{T}; check::Bool=true) where T <: Union{padic, qadic, LocalFieldElem}
check_parent(f1, g1)
iszero(g1) && throw(DivideError())
if iszero(f1)
Expand Down
2 changes: 1 addition & 1 deletion src/LocalField/Ring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end

==(a::QadicRingElem, b::QadicRingElem) = a.x == b.x

function divexact(a::QadicRingElem, b::QadicRingElem)
function divexact(a::QadicRingElem, b::QadicRingElem; check::Bool=true)
@assert !iszero(b.x)
iszero(a) && return a
valuation(a.x) >= valuation(b.x) || error("division not exact")
Expand Down
8 changes: 4 additions & 4 deletions src/NumField/NfRel/NfRel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ function Base.:(-)(a::T, b::NfRelElem{T}) where {T <: NumFieldElem}
return parent(b)(a - data(b))
end

function divexact(a::NfRelElem{T}, b::T) where {T <: NumFieldElem}
return parent(a)(divexact(data(a), b))
function divexact(a::NfRelElem{T}, b::T; check::Bool=true) where {T <: NumFieldElem}
return parent(a)(divexact(data(a), b; check=check))
end

Base.:(//)(a::NfRelElem{T}, b::T) where {T <: NumFieldElem} = divexact(a, b)
Expand All @@ -404,8 +404,8 @@ for F in [ZZRingElem, QQFieldElem, Int]
return parent(b)(a - data(b))
end

function divexact(a::NfRelElem{T}, b::$F) where {T <: NumFieldElem}
return parent(a)(divexact(data(a), b))
function divexact(a::NfRelElem{T}, b::$F; check::Bool=true) where {T <: NumFieldElem}
return parent(a)(divexact(data(a), b; check=check))
end

Base.:(//)(a::NfRelElem{T}, b::$F) where {T <: NumFieldElem} = divexact(a, b)
Expand Down
18 changes: 9 additions & 9 deletions src/NumFieldOrd/NfOrd/Ideal/Arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -864,51 +864,51 @@ end
#
################################################################################

divexact(A::NfAbsOrdIdl, b::Integer) = divexact(A, ZZRingElem(b))
divexact(A::NfAbsOrdIdl, b::Integer; check::Bool=true) = divexact(A, ZZRingElem(b); check=check)

#TODO: write a divexact! to change the ideal?
# difficult due to Julia's inability to unset entries...

function divexact(A::NfAbsOrdIdl, b::ZZRingElem)
function divexact(A::NfAbsOrdIdl, b::ZZRingElem; check::Bool=true)
if iszero(A)
return A
end
zk = order(A)
b = abs(b)
if has_2_elem(A)
B = ideal(zk, divexact(A.gen_one, b), divexact(A.gen_two, b))
B = ideal(zk, divexact(A.gen_one, b; check=check), divexact(A.gen_two, b; check=check))
if isdefined(A, :gens_normal)
B.gens_normal = A.gens_normal
end
B.gens_weakly_normal = A.gens_weakly_normal
if has_basis_matrix(A)
B.basis_matrix = divexact(A.basis_matrix, b)
B.basis_matrix = divexact(A.basis_matrix, b; check=check)
end
if false && has_basis_mat_inv(A)
error("not defined at all")
B.basis_mat_inv = b*A.basis_mat_inv
end
else
B = ideal(zk, divexact(A.basis_matrix, b))
B = ideal(zk, divexact(A.basis_matrix, b; check=check))
if false && has_basis_mat_inv(A)
error("not defined at all")
B.basis_mat_inv = b*A.basis_mat_inv
end
end
if has_minimum(A)
B.minimum = divexact(A.minimum, b)
B.minimum = divexact(A.minimum, b; check=check)
end
if has_norm(A)
B.norm = divexact(A.norm, b^degree(zk))
B.norm = divexact(A.norm, b^degree(zk); check=check)
end
if has_princ_gen(A)
B.princ_gen = divexact(A.princ_gen, b)
B.princ_gen = divexact(A.princ_gen, b; check=check)
end
#TODO princ_gen_special missing
return B
end

function divexact(A::NfOrdIdl, B::NfOrdIdl)
function divexact(A::NfOrdIdl, B::NfOrdIdl; check::Bool=true)
check_parent(A, B)
# It is assumed that B divides A, that is, A \subseteq B
t_prod = 0.0
Expand Down
6 changes: 3 additions & 3 deletions src/NumFieldOrd/NfRelOrd/FracIdeal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,11 @@ end
#
################################################################################

divexact(a::NfRelOrdFracIdl{T, S}, b::NfRelOrdFracIdl{T, S}) where {T, S} = a*inv(b)
divexact(a::NfRelOrdFracIdl{T, S}, b::NfRelOrdFracIdl{T, S}; check::Bool=true) where {T, S} = a*inv(b)

divexact(a::NfRelOrdFracIdl{T, S}, b::NfRelOrdIdl{T, S}) where {T, S} = a*inv(b)
divexact(a::NfRelOrdFracIdl{T, S}, b::NfRelOrdIdl{T, S}; check::Bool=true) where {T, S} = a*inv(b)

function divexact(a::NfRelOrdIdl{T, S}, b::NfRelOrdFracIdl{T, S}) where {T, S}
function divexact(a::NfRelOrdIdl{T, S}, b::NfRelOrdFracIdl{T, S}; check::Bool=true) where {T, S}
O = order(a)
return fractional_ideal(O, basis_pmatrix(a, copy = false); M_in_hnf=true)*inv(b)
end
Expand Down
2 changes: 1 addition & 1 deletion src/NumFieldOrd/NfRelOrd/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ end
#
################################################################################

function divexact(a::NfRelOrdIdl{T, S}, b::NfRelOrdIdl{T, S}) where {T, S}
function divexact(a::NfRelOrdIdl{T, S}, b::NfRelOrdIdl{T, S}; check::Bool=true) where {T, S}
O = order(a)
return fractional_ideal(O, basis_pmatrix(a, copy = false); M_in_hnf=true)*inv(b)
end
Expand Down
4 changes: 2 additions & 2 deletions src/NumFieldOrd/NumFieldOrdElem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function -(x::T, y::T) where T <: NumFieldOrdElem
return z
end

function divexact(x::T, y::T, check::Bool = true) where T <: NumFieldOrdElem
function divexact(x::T, y::T; check::Bool = true) where T <: NumFieldOrdElem
!check_parent(x, y) && error("Wrong parents")
a = divexact(x.elem_in_nf, y.elem_in_nf)
if check
Expand Down Expand Up @@ -174,7 +174,7 @@ for T in [Integer, ZZRingElem]
return z
end

function divexact(a::NumFieldOrdElem, b::$T, check::Bool = true)
function divexact(a::NumFieldOrdElem, b::$T; check::Bool = true)
t = divexact(a.elem_in_nf, b)
if check
if !in(t, parent(a))
Expand Down
7 changes: 4 additions & 3 deletions src/QuadForm/QuadBin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ function Base.:(*)(c::Integer, f::QuadBin)
return binary_quadratic_form(c * f[1], c * f[2], c * f[3])
end

function divexact(f::QuadBin{T}, c::T) where T <: RingElem
return binary_quadratic_form(divexact(f[1], c), divexact(f[2], c),
divexact(f[3], c))
function divexact(f::QuadBin{T}, c::T; check::Bool=true) where T <: RingElem
return binary_quadratic_form(divexact(f[1], c; check=check),
divexact(f[2], c; check=check),
divexact(f[3], c; check=check))
end

###############################################################################
Expand Down
10 changes: 5 additions & 5 deletions src/Sparse/Row.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,25 +537,25 @@ function div(A::SRow{T}, b::Integer) where T
return div(A, base_ring(A)(b))
end

function divexact(A::SRow{T}, b::T) where T
function divexact(A::SRow{T}, b::T; check::Bool=true) where T
B = sparse_row(base_ring(A))
if iszero(b)
return error("Division by zero")
end
for (p,v) = A
nv = divexact(v, b)
nv = divexact(v, b; check=check)
@assert !iszero(nv)
push!(B.pos, p)
push!(B.values, nv)
end
return B
end

function divexact(A::SRow{T}, b::Integer) where T
function divexact(A::SRow{T}, b::Integer; check::Bool=true) where T
if length(A.values) == 0
return deepcopy(A)
end
return divexact(A, base_ring(A)(b))
return divexact(A, base_ring(A)(b); check=check)
end

################################################################################
Expand Down Expand Up @@ -723,7 +723,7 @@ end
@doc raw"""
sparse_row(A::MatElem)
Convert `A` to a sparse row.
Convert `A` to a sparse row.
`nrows(A) == 1` must hold.
"""
function sparse_row(A::MatElem)
Expand Down
Loading

0 comments on commit 4fb1f9b

Please sign in to comment.