Skip to content

Commit

Permalink
Add is_euclidean_type trait
Browse files Browse the repository at this point in the history
The idea is that this true for ring / ring elem types that
explicitly support a euclidean division with remainder, and
ideally also a euclidean degree (to be defined in the interface).
This is just a draft to have a point for discussion and
experiments: it is missing many things, including documentation as
to what is_euclidean_type(x)==true means, which promises this
incurrs; and of course also code needs to be adapted to use it
(e.g. the residue ring or ideal constructions or whatnot that only
work sensible for euclidean rings should check this.
  • Loading branch information
fingolfin committed Dec 20, 2024
1 parent 28b0cb3 commit f5d43f0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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 @@ coefficient_ring(R::PolyRing) = base_ring(R)

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
13 changes: 13 additions & 0 deletions src/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ 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

0 comments on commit f5d43f0

Please sign in to comment.