Skip to content

Commit 97e4466

Browse files
committed
Add fraction_field_type
1 parent 576dc3e commit 97e4466

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Fraction.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,38 @@ function fraction_field(F::Field; cached::Bool=true)
828828
return F
829829
end
830830

831+
832+
@doc raw"""
833+
fraction_field_type(a)
834+
835+
Return the type of the base ring of the given element, element type, parent or parent type $a$.
836+
837+
# Examples
838+
```jldoctest
839+
julia> R, x = polynomial_ring(ZZ, :x)
840+
(Univariate polynomial ring in x over integers, x)
841+
842+
julia> fraction_field_type(R) == typeof(base_ring(R))
843+
true
844+
845+
julia> fraction_field_type(zero(R)) == typeof(base_ring(zero(R)))
846+
true
847+
848+
julia> fraction_field_type(typeof(R)) == typeof(base_ring(R))
849+
true
850+
851+
julia> fraction_field_type(typeof(zero(R))) == typeof(base_ring(zero(R)))
852+
true
853+
```
854+
"""
855+
fraction_field_type(x) = fraction_field_type(typeof(x))
856+
fraction_field_type(x::Type{<:RingElement}) = fraction_field_type(parent_type(x))
857+
fraction_field_type(T::DataType) = throw(MethodError(fraction_field_type, (T,)))
858+
859+
fraction_field_type(::Type{T}) where {T <: Field} = T
860+
fraction_field_type(::Type{T}) where {T <: Ring} = AbstractAlgebra.Generic.FracField{elem_type(T)}
861+
862+
831863
@doc raw"""
832864
factored_fraction_field(R::Ring; cached::Bool=true)
833865

src/exports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export find_pivot_popov
227227
export finish
228228
export fit!
229229
export fraction_field
230+
export fraction_field_type
230231
export free_associative_algebra
231232
export free_associative_algebra_type
232233
export free_module

0 commit comments

Comments
 (0)