Skip to content

Commit

Permalink
Add vars for rational functions of multivariate polynomials (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 authored Dec 7, 2023
1 parent 0b469c2 commit 5d52d5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/generic/Fraction-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5d52d5b

Please sign in to comment.