Skip to content

Commit

Permalink
Merge pull request #550 from JuliaSymbolics/s/fix-Rational-div
Browse files Browse the repository at this point in the history
Fix div with rational numbers to fix simplify_fractions
  • Loading branch information
shashi authored Sep 8, 2023
2 parents 7c28c42 + 7737865 commit 6505233
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/polyform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ end
# forward gcd

PF = :(PolyForm{promote_symtype(/, symtype(x), symtype(y))})
const FriendlyCoeffType = Union{Integer, Rational}
@eval begin
Base.div(x::PolyForm, y::PolyForm) = $PF(div(x.p, y.p), mix_dicts(x, y)...)
Base.div(x::Integer, y::PolyForm) = $PF(div(x, y.p), y.pvar2sym, y.sym2term)
Base.div(x::PolyForm, y::Integer) = $PF(div(x.p, y), x.pvar2sym, x.sym2term)
Base.div(x::FriendlyCoeffType, y::PolyForm) = $PF(div(x, y.p), y.pvar2sym, y.sym2term)
Base.div(x::PolyForm, y::FriendlyCoeffType) = $PF(div(x.p, y), x.pvar2sym, x.sym2term)

Base.gcd(x::PolyForm, y::PolyForm) = $PF(_gcd(x.p, y.p), mix_dicts(x, y)...)
Base.gcd(x::Integer, y::PolyForm) = $PF(_gcd(x, y.p), y.pvar2sym, y.sym2term)
Base.gcd(x::PolyForm, y::Integer) = $PF(_gcd(x.p, y), x.pvar2sym, x.sym2term)
Base.gcd(x::FriendlyCoeffType, y::PolyForm) = $PF(_gcd(x, y.p), y.pvar2sym, y.sym2term)
Base.gcd(x::PolyForm, y::FriendlyCoeffType) = $PF(_gcd(x.p, y), x.pvar2sym, x.sym2term)
end

_isone(p::PolyForm) = isone(p.p)
Expand Down
3 changes: 3 additions & 0 deletions test/polyform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ end
##404#issuecomment-939404030
a = 1 / (x - (2//1)) + ((-5//1) - x) / ((x - (2//1))^2)
@test isequal(simplify_fractions(a), -7/(x-2)^2)

# https://github.com/JuliaSymbolics/Symbolics.jl/issues/968
@eqtest simplify_fractions((x * y + (1//2) * x) / (2 * x)) == 1//4 * (1 + 2y)
end

@testset "isone iszero" begin
Expand Down

0 comments on commit 6505233

Please sign in to comment.