Skip to content

Commit

Permalink
Add more concrete method for / (#283)
Browse files Browse the repository at this point in the history
* Add more concrete method for /

* Update version of IntervalArithmetics

* Further fixes in mixtures and tests

* Bump patch version

* Fix tests
  • Loading branch information
lbenet authored Jun 25, 2021
1 parent a4b38ad commit d927c21
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"

Expand Down
14 changes: 14 additions & 0 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
21 changes: 21 additions & 0 deletions test/mixtures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

2 comments on commit d927c21

@lbenet
Copy link
Member Author

@lbenet lbenet commented on d927c21 Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/39635

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.2 -m "<description of version>" d927c21f7e79428ab96542106a36aa68192de4a8
git push origin v0.11.2

Please sign in to comment.