@@ -473,6 +473,13 @@ for (f, fc) in ((:+, :(add!)), (:-, :(subst!)))
473473 end
474474end
475475
476+ function subst! (v:: Taylor1{Taylor1{T}} , a:: Taylor1{Taylor1{T}} , k:: Int ) where {T <: TS.NumberNotSeries }
477+ @inbounds for i in eachindex (v[k])
478+ v[k][i] = - a[k][i]
479+ end
480+ return nothing
481+ end
482+
476483for T in (:Taylor1 , :TaylorN )
477484 @eval begin
478485 function sum! (v:: $T{S} , a:: AbstractArray{$T{S}} ) where {S <: Number }
@@ -640,6 +647,15 @@ function muladd!(c::Taylor1{T}, a::Taylor1{T}, b::Taylor1{T}, k::Int) where
640647 end
641648 return nothing
642649end
650+
651+ function muladd! (c:: Taylor1{T} , a:: Taylor1{T} , b:: Taylor1{T} ) where
652+ {T<: NumberNotSeries }
653+ for k in eachindex (c)
654+ muladd! (c, a, b, k)
655+ end
656+ return nothing
657+ end
658+
643659# function muladd!(v::Taylor1{T}, a::Taylor1{T}, b::NumberNotSeries, k::Int) where
644660# {T<:NumberNotSeries}
645661# @inbounds v[k] += a[k] * b
@@ -1194,7 +1210,7 @@ end
11941210
11951211# @inline
11961212function div! (c:: Taylor1{T} , a:: NumberNotSeries , b:: Taylor1{T} , k:: Int ) where
1197- {T<: Number }
1213+ {T<: NumberNotSeries }
11981214 zero! (c, k)
11991215 iszero (a) && ! iszero (b) && return nothing
12001216 # order and coefficient of first factorized term
@@ -1212,6 +1228,34 @@ function div!(c::Taylor1{T}, a::NumberNotSeries, b::Taylor1{T}, k::Int) where
12121228 return nothing
12131229end
12141230
1231+ function div! (c:: Taylor1 , a:: NumberNotSeries , b:: Taylor1 )
1232+ @inbounds for k in eachindex (c)
1233+ div! (c, a, b, k)
1234+ end
1235+ return nothing
1236+ end
1237+
1238+ @inline function div! (c:: Taylor1{Taylor1{T}} , a:: NumberNotSeries ,
1239+ b:: Taylor1{Taylor1{T}} , k:: Int ) where {T<: NumberNotSeries }
1240+ zero! (c, k)
1241+ iszero (a) && ! iszero (b) && return nothing
1242+ # order and coefficient of first factorized term
1243+ # In this case, since a[k]=0 for k>0, we can simplify to:
1244+ # ordfact, cdivfact = 0, a/b[0]
1245+ if k == 0
1246+ @inbounds div! (c[0 ], a, b[0 ])
1247+ return nothing
1248+ end
1249+ @inbounds mul! (c[k], c[0 ], b[k])
1250+ @inbounds for i = 1 : k- 1
1251+ # c[k] += c[i] * b[k-i]
1252+ muladd! (c[k], c[i], b[k- i])
1253+ end
1254+ # @inbounds c[k] = -c[k]/b[0]
1255+ @inbounds div_scalar! (c[k], - 1 , b[0 ])
1256+ return nothing
1257+ end
1258+
12151259#
12161260# @inline
12171261function div! (c:: Taylor1{Taylor1{T}} , a:: Taylor1{Taylor1{T}} ,
@@ -1261,26 +1305,6 @@ end
12611305# return nothing
12621306# end
12631307
1264- # @inline function div!(c::Taylor1{Taylor1{T}}, a::NumberNotSeries,
1265- # b::Taylor1{Taylor1{T}}, k::Int) where {T<:Number}
1266- # zero!(c, k)
1267- # iszero(a) && !iszero(b) && return nothing
1268- # # order and coefficient of first factorized term
1269- # # In this case, since a[k]=0 for k>0, we can simplify to:
1270- # # ordfact, cdivfact = 0, a/b[0]
1271- # if k == 0
1272- # @inbounds c[0] = a/b[0]
1273- # return nothing
1274- # end
1275-
1276- # @inbounds c[k] = c[0] * b[k]
1277- # @inbounds for i = 1:k-1
1278- # c[k] += c[i] * b[k-i]
1279- # end
1280- # @inbounds c[k] = -c[k]/b[0]
1281- # return nothing
1282- # end
1283-
12841308@inline function div! (c:: Taylor1{TaylorN{T}} , a:: NumberNotSeries ,
12851309 b:: Taylor1{TaylorN{T}} , k:: Int ) where {T<: NumberNotSeries }
12861310 zero! (c, k)
@@ -1381,6 +1405,23 @@ end
13811405 return nothing
13821406end
13831407
1408+ @inline function div_scalar! (c:: Taylor1{T} , scalar:: NumberNotSeries ,
1409+ a:: Taylor1{T} , k:: Int ) where {T <: NumberNotSeries }
1410+ if k== 0
1411+ @inbounds c[0 ] = scalar* constant_term (c) / constant_term (a)
1412+ return nothing
1413+ end
1414+
1415+ aux = c[k] = scalar * c[k]
1416+ @inbounds zero! (c, k)
1417+ @inbounds for i = 0 : k- 1
1418+ c[k] -= c[i] * a[k- i]
1419+ end
1420+ c[k] += aux
1421+ @inbounds c[k] = c[k] / constant_term (a)
1422+ return nothing
1423+ end
1424+
13841425# NOTE: Here `div!` *accumulates* the result of a[k] / b[k] in c[k] (k > 0)
13851426@inline function div! (c:: TaylorN , a:: NumberNotSeries , b:: TaylorN , k:: Int )
13861427 if k== 0
@@ -1413,6 +1454,14 @@ function div_scalar!(c::TaylorN, scalar::NumberNotSeries, a::TaylorN)
14131454 return nothing
14141455end
14151456
1457+ # in-place division c <- scalar*c/a (assumes equal order among TaylorNs)
1458+ function div_scalar! (c:: Taylor1 , scalar:: NumberNotSeries , a:: Taylor1 )
1459+ @inbounds for k in eachindex (c)
1460+ div_scalar! (c, scalar, a, k)
1461+ end
1462+ return nothing
1463+ end
1464+
14161465# c[k] <- (a/b)[k]
14171466function div! (c:: TaylorN , a:: TaylorN , b:: TaylorN )
14181467 @inbounds for k in eachindex (c)
0 commit comments