diff --git a/Project.toml b/Project.toml index 10a18d51..3c8d2217 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TaylorSeries" uuid = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea" repo = "https://github.com/JuliaDiff/TaylorSeries.jl.git" -version = "0.11.1" +version = "0.11.2" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" @@ -10,7 +10,7 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] -IntervalArithmetic = "0.15, 0.16, 0.17" +IntervalArithmetic = "0.15, 0.16, 0.17, 0.18" Requires = "0.5.2, 1.0, 1.1" julia = "1" diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 8f6836d5..0e639a63 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -23,6 +23,12 @@ for T in (:Taylor1, :TaylorN) end end +function ==(a::Taylor1{TaylorN{T}}, b::TaylorN{Taylor1{S}}) where {T,S} + R = promote_type(S,T) + return a == convert(Taylor1{TaylorN{R}},b) +end +==(b::TaylorN{Taylor1{S}}, a::Taylor1{TaylorN{T}}) where {T,S} = a == b + function ==(a::HomogeneousPolynomial, b::HomogeneousPolynomial) a.order == b.order && return a.coeffs == b.coeffs return iszero(a.coeffs) && iszero(b.coeffs) @@ -410,6 +416,14 @@ for T in (:HomogeneousPolynomial, :TaylorN) return $T(coeffs, b.order) end + @eval function /(b::$T{Taylor1{T}}, a::S) where {T<:NumberNotSeries,S<:NumberNotSeries} + @inbounds aux = b.coeffs[1] / a + R = typeof(aux) + coeffs = Array{R}(undef, length(b.coeffs)) + @__dot__ coeffs = b.coeffs / a + return $T(coeffs, b.order) + end + @eval function /(b::Taylor1{$T{S}}, a::$T{T}) where {T<:NumberNotSeries,S<:NumberNotSeries} @inbounds aux = b[0] / a diff --git a/src/conversion.jl b/src/conversion.jl index f053f071..7e038f21 100644 --- a/src/conversion.jl +++ b/src/conversion.jl @@ -209,6 +209,10 @@ promote_rule(::Type{S}, ::Type{T}) where promote_rule(::Type{Taylor1{T}}, ::Type{TaylorN{S}}) where {T<:NumberNotSeries,S<:NumberNotSeries} = throw(ArgumentError("There is no reasonable promotion among `Taylor1{$T}` and `TaylorN{$S}` types")) +promote_rule(::Type{Taylor1{TaylorN{T}}}, ::Type{TaylorN{Taylor1{S}}}) where + {T<:NumberNotSeries, S<:NumberNotSeries} = Taylor1{TaylorN{promote_type(T,S)}} +promote_rule(::Type{TaylorN{Taylor1{T}}}, ::Type{Taylor1{TaylorN{S}}}) where + {T<:NumberNotSeries, S<:NumberNotSeries} = Taylor1{TaylorN{promote_type(T,S)}} # Nested Taylor1's function promote(a::Taylor1{Taylor1{T}}, b::Taylor1{T}) where {T<:NumberNotSeriesN} diff --git a/test/mixtures.jl b/test/mixtures.jl index 25e02801..857af8a7 100644 --- a/test/mixtures.jl +++ b/test/mixtures.jl @@ -123,6 +123,27 @@ using LinearAlgebra, SparseArrays @test evaluate!([t1N, t1N^2], 0.0, v) == nothing @test v == [TaylorN(1), TaylorN(1)^2] + # Tests for functions of mixtures + t1N = Taylor1([zero(TaylorN(Float64,1)), one(TaylorN(Float64,1))], 6) + t = Taylor1(3) + xHt = HomogeneousPolynomial([one(t), zero(t)]) + yHt = HomogeneousPolynomial([zero(t), t]) + x = TaylorN(1, order=2) + y = TaylorN(2, order=2) + xN1 = TaylorN([HomogeneousPolynomial(zero(t), 0), xHt, zero(yHt)], 2) + yN1 = TaylorN([HomogeneousPolynomial(zero(t), 0), zero(xHt), yHt], 2) + for fn in (exp, log, sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, asinh, acosh, atanh) + if fn == asin || fn == acos || fn == atanh + cc = 0.5 + elseif fn == asinh || fn == acosh + cc = 1.5 + else + cc = 1.0 + end + @test x*fn(cc+t1N) == fn(cc+t)*xN1 + @test t*fn(cc+xN1) == fn(cc+x)*t1N + end + vt = zeros(Taylor1{Float64},2) @test evaluate!([tN1, tN1^2], [t, t], vt) == nothing @test vt == [2t, 4t^2]