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

Add is_euclidean_type trait #1943

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions src/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

is_domain_type(::Type{T}) where {T <: FieldElem} = true

is_euclidean_type(::Type{T}) where {T <: FieldElem} = true

Check warning on line 9 in src/Fields.jl

View check run for this annotation

Codecov / codecov/patch

src/Fields.jl#L9

Added line #L9 was not covered by tests

is_zero_divisor(a::T) where T <: FieldElem = is_zero(a)

is_unit(a::FieldElem) = !iszero(a)
Expand Down
11 changes: 5 additions & 6 deletions src/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

dense_poly_type(::Type{T}) where T<:RingElement = Generic.Poly{T}

function is_domain_type(::Type{T}) where {S <: RingElement, T <: PolyRingElem{S}}
return is_domain_type(S)
end
is_exact_type(::Type{<:PolyRingElem{T}}) where {T <: RingElement} = is_exact_type(T)

function is_exact_type(a::Type{T}) where {S <: RingElement, T <: PolyRingElem{S}}
return is_exact_type(S)
end
is_domain_type(::Type{<:PolyRingElem{T}}) where {T <: RingElement} = is_domain_type(T)

is_euclidean_type(::Type{<:PolyRingElem{T}}) where {T <: RingElem} = T <: FieldElem

Check warning on line 23 in src/Poly.jl

View check run for this annotation

Codecov / codecov/patch

src/Poly.jl#L23

Added line #L23 was not covered by tests
# TODO: what about polynomials over `Rational{BigInt}`?

@doc raw"""
var(a::PolyRing)
Expand Down
31 changes: 30 additions & 1 deletion src/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,41 @@

# Type can only represent elements of an exact ring
# true unless explicitly specified
#
# implementors should only implement this trait for RingElem subtypes, but for
# convenience we support calling this also on Ring subtypes as well as Ring
# and RingElem instances
is_exact_type(R::Type{T}) where T <: RingElem = true

# Type can only represent elements of domains
is_exact_type(x) = is_exact_type(typeof(x))
is_exact_type(x::Type{<:Ring}) = is_exact_type(elem_type(x))
is_exact_type(T::DataType) = throw(MethodError(is_exact_type, (T,)))

Check warning on line 106 in src/Rings.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings.jl#L104-L106

Added lines #L104 - L106 were not covered by tests

# Type can only represent elements of domains, i.e. without zero divisors
# false unless explicitly specified
#
# implementors should only implement this trait for RingElem subtypes, but for
# convenience we support calling this also on Ring subtypes as well as Ring
# and RingElem instances
is_domain_type(R::Type{T}) where T <: RingElem = false

is_domain_type(x) = is_domain_type(typeof(x))
is_domain_type(x::Type{<:Ring}) = is_domain_type(elem_type(x))
is_domain_type(T::DataType) = throw(MethodError(is_domain_type, (T,)))

Check warning on line 118 in src/Rings.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings.jl#L116-L118

Added lines #L116 - L118 were not covered by tests

# Type can only represent elements of euclidean rings (which do not need to be domains)
# false unless explicitly specified
#
# implementors should only implement this trait for RingElem subtypes, but for
# convenience we support calling this also on Ring subtypes as well as Ring
# and RingElem instances
is_euclidean_type(R::Type{T}) where T <: RingElem = false

Check warning on line 126 in src/Rings.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings.jl#L126

Added line #L126 was not covered by tests

is_euclidean_type(x) = is_euclidean_type(typeof(x))
is_euclidean_type(x::Type{<:Ring}) = is_euclidean_type(elem_type(x))
is_euclidean_type(T::DataType) = throw(MethodError(is_euclidean_type, (T,)))

Check warning on line 130 in src/Rings.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings.jl#L128-L130

Added lines #L128 - L130 were not covered by tests


###############################################################################
#
# Exponential function for generic rings
Expand Down
Loading