From df474ee9b5e64456c95acdd46e42a5f77c0cd6ca Mon Sep 17 00:00:00 2001 From: Alexander Demin Date: Thu, 7 Dec 2023 01:03:48 +0300 Subject: [PATCH 1/2] Add vars for rational functions of multivariate polynomials --- src/Fraction.jl | 15 +++++++++++++++ test/generic/Fraction-test.jl | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Fraction.jl b/src/Fraction.jl index e39f7372a8..293824cbdf 100644 --- a/src/Fraction.jl +++ b/src/Fraction.jl @@ -39,6 +39,21 @@ function check_parent(a::FracElem, b::FracElem, throw::Bool = true) return !fl end +@doc raw""" + vars(a::FracElem{S}) where {S <: MPolyRingElem{<: RingElement}} + +Return the variables actually occurring in $a$. Returned variables are elements +of `base_ring(a)`. The variables from the numerator go first. +""" +function vars(a::FracElem{S}) where {S <: MPolyRingElem{<: RingElement}} + n = numerator(a, false) + d = denominator(a, false) + n_vars = vars(n) + d_vars = vars(d) + nd_vars = union!(n_vars, d_vars) + return(nd_vars) +end + ############################################################################### # # Constructors diff --git a/test/generic/Fraction-test.jl b/test/generic/Fraction-test.jl index c6eba68bb3..813531dbd4 100644 --- a/test/generic/Fraction-test.jl +++ b/test/generic/Fraction-test.jl @@ -61,6 +61,18 @@ end @test !occursin("\n", sprint(show, fraction_field(S))) end +@testset "Generic.FracFieldElem.vars" begin + S, (x,y,z) = polynomial_ring(QQ, ["x", "y", "z"]) + K = fraction_field(S) + + a = K(zero(S), one(S)) + res = vars(a) + @test isempty(res) && eltype(res) == elem_type(S) + + @test parent(first(vars(1 // z))) == base_ring(a) + @test vars((2y) // 3one(S)) == [y] + @test vars((y + z) // (x + y)) == [y, z, x] +end @testset "Generic.FracFieldElem.rand" begin S, x = polynomial_ring(ZZ, "x") From 3dce787cddba30a5c99cd4e69eb4f49dcf9b0187 Mon Sep 17 00:00:00 2001 From: Alexander Demin <60229118+sumiya11@users.noreply.github.com> Date: Thu, 7 Dec 2023 01:47:02 +0300 Subject: [PATCH 2/2] Update src/Fraction.jl Co-authored-by: Max Horn --- src/Fraction.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fraction.jl b/src/Fraction.jl index 293824cbdf..9a3a116172 100644 --- a/src/Fraction.jl +++ b/src/Fraction.jl @@ -51,7 +51,7 @@ function vars(a::FracElem{S}) where {S <: MPolyRingElem{<: RingElement}} n_vars = vars(n) d_vars = vars(d) nd_vars = union!(n_vars, d_vars) - return(nd_vars) + return nd_vars end ###############################################################################