From e7301a2fe1165ec5477e39dcf204151d55f2cba3 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 29 Nov 2024 00:05:49 +0100 Subject: [PATCH] Enable factor(::Rational) Also enables `factor(ZZ, 28//15)` in Nemo, Hecke, Oscar. Alas, no tests for this here as we have no `factor` methods for any integer types here in AA. --- src/Fields.jl | 2 +- src/generic/Misc/Poly.jl | 2 +- test/generic/Fraction-test.jl | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Fields.jl b/src/Fields.jl index a389cfda4f..4df6c4043a 100644 --- a/src/Fields.jl +++ b/src/Fields.jl @@ -38,7 +38,7 @@ function gcdx(x::T, y::T) where {T <: FieldElem} end end -function factor(x::FieldElem) +function factor(x::FieldElement) @req !is_zero(x) "Element must be non-zero" return Fac(x, Dict{typeof(x), Int}()) end diff --git a/src/generic/Misc/Poly.jl b/src/generic/Misc/Poly.jl index 3d50943a27..0846e020d3 100644 --- a/src/generic/Misc/Poly.jl +++ b/src/generic/Misc/Poly.jl @@ -28,7 +28,7 @@ function factor(R::Field, f::PolyRingElem) return factor(f1) end -function factor(R::Ring, f::FracElem) +function factor(R::Ring, f::Union{FracElem, Rational}) fn = factor(R(numerator(f))) fd = factor(R(denominator(f))) fn.unit = divexact(fn.unit, fd.unit) diff --git a/test/generic/Fraction-test.jl b/test/generic/Fraction-test.jl index 51daa90483..7c41b59939 100644 --- a/test/generic/Fraction-test.jl +++ b/test/generic/Fraction-test.jl @@ -398,4 +398,11 @@ end @test length(f) == 0 @test unit(f) == a @test_throws ArgumentError factor(zero(F)) + + F = QQ + a = 28//15 + f = factor(a) + @test length(f) == 0 + @test unit(f) == a + @test_throws ArgumentError factor(zero(F)) end