diff --git a/src/taylor.jl b/src/taylor.jl index 0c9766d85..5a3f67260 100644 --- a/src/taylor.jl +++ b/src/taylor.jl @@ -17,6 +17,9 @@ function taylor_coeff(f, x, n; rationalize=true) end return c end +function taylor_coeff(eq::Equation, args...; kwargs...) + return taylor_coeff(eq.lhs, args...; kwargs...) ~ taylor_coeff(eq.rhs, args...; kwargs...) +end """ taylor(f, x, [x0=0,] n; rationalize=true) @@ -56,3 +59,6 @@ function taylor(f, x, x0, n; kwargs...) # 3) substitute back x = x′ + x0 return substitute(s, x′ => x - x0) end +function taylor(eq::Equation, args...; kwargs...) + return taylor(eq.lhs, args...; kwargs...) ~ taylor(eq.rhs, args...; kwargs...) +end diff --git a/test/taylor.jl b/test/taylor.jl index de927e158..7cf8c7223 100644 --- a/test/taylor.jl +++ b/test/taylor.jl @@ -26,3 +26,9 @@ end # around x ≠ 0 @test substitute(taylor(√(x), x, 1, 0:6), x => x + 1) - taylor(√(1+x), x, 0:6) == 0 + +# equations +eq = sin(2*x) ~ 2*sin(x)*cos(x) +eq = taylor(eq, x, 0:7) +eqs = [Symbolics.taylor_coeff(eq, x, n) for n in 0:7] +@test all(isequal(eq.lhs, eq.rhs) for eq in eqs)