diff --git a/src/polyform.jl b/src/polyform.jl index 09c871fa5..873e332a8 100644 --- a/src/polyform.jl +++ b/src/polyform.jl @@ -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) diff --git a/test/polyform.jl b/test/polyform.jl index 4500763e9..9fb088a7f 100644 --- a/test/polyform.jl +++ b/test/polyform.jl @@ -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