Skip to content

Commit

Permalink
Add is_associated
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Feb 28, 2024
1 parent 7837669 commit 0004eaa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ export inverse_fn
export inverse_image_fn
export inverse_mat
export invmod
export is_associated
export is_compatible
export is_constant
export is_degree
Expand Down
9 changes: 9 additions & 0 deletions src/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ function is_divisible_by(x::T, y::T) where T <: RingElem
return divides(x, y)[1]
end

"""
is_associated(x::T, y::T) where T <: RingElem
Check if `x` and `y` are associated, i.e. if `x` is a unit times `y`.
"""
function is_associated(x::T, y::T) where T <: RingElem
return is_divisible_by(x, y) && is_divisible_by(y, x)
end

###############################################################################
#
# Evaluation
Expand Down
4 changes: 4 additions & 0 deletions src/julia/Integer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ function is_divisible_by(a::BigInt, b::UInt)
(Ref{BigInt}, UInt), a, b))
end

function is_associated(x::Integer, y::Integer)
return x == y || x == -y

Check warning on line 153 in src/julia/Integer.jl

View check run for this annotation

Codecov / codecov/patch

src/julia/Integer.jl#L152-L153

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

###############################################################################
#
# Exact division
Expand Down
16 changes: 16 additions & 0 deletions test/Rings-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,19 @@ end
@test is_finite(GF(2))
@test !is_finite(QQ)
end

@testset "is_associated" begin
F = GF(13)
for x in F, y in F
@test is_associated(x, y) == (iszero(x) == iszero(y))
end

Fx, x = polynomial_ring(F)
f = x^3 + 4x + 3
@test is_associated(f, f)
@test is_associated(f, 6*f)
@test is_associated(7*f, f)
@test !is_associated(f, 0*f)
@test !is_associated(0*f, f)
@test !is_associated(f, 2x^2-x+2)
end

0 comments on commit 0004eaa

Please sign in to comment.