@@ -147,7 +147,7 @@ for T in (:Taylor1, :TaylorN)
147
147
end
148
148
end
149
149
150
- # Functions for StaticTaylor
150
+ # Functions for STaylor1
151
151
@generated function exp (a:: STaylor1{N,T} ) where {N, T <: Number }
152
152
ex_calc = quote end
153
153
append! (ex_calc. args, Any[nothing for i in 1 : N])
180
180
end
181
181
end
182
182
183
+ @generated function log (a:: STaylor1{N,T} ) where {N, T <: Number }
184
+ ex_calc = quote end
185
+ append! (ex_calc. args, Any[nothing for i in 1 : N])
186
+ syms = Symbol[Symbol (" c$i " ) for i in 1 : N]
187
+
188
+ (N >= 1 ) && (ex_calc. args[1 ] = :($ (syms[1 ]) = log (constant_term (a))))
189
+ (N >= 2 ) && (ex_calc. args[2 ] = :($ (syms[2 ]) = a[1 ]/ constant_term (a)))
190
+
191
+ for k in 2 : (N- 1 )
192
+ ex_line = :($ (k- 1 )* a[1 ]* $ (syms[k]))
193
+ @inbounds for i = 2 : k- 1
194
+ ex_line = :($ ex_line + $ (k- i)* a[$ i] * $ (syms[k+ 1 - i]))
195
+ end
196
+ ex_line = :((a[$ k] - ($ ex_line)/ $ (convert (T,k)))/ constant_term (a))
197
+ ex_line = :($ (syms[k+ 1 ]) = $ ex_line)
198
+ ex_calc. args[k+ 1 ] = ex_line
199
+ end
200
+
201
+ exout = :(($ (syms[1 ]),))
202
+ for i = 2 : N
203
+ push! (exout. args, syms[i])
204
+ end
205
+
206
+ return quote
207
+ Base. @_inline_meta
208
+ iszero (constant_term (a)) && throw (ArgumentError ("""
209
+ The 0-th order `STaylor1` coefficient must be non-zero
210
+ in order to expand `log` around 0.
211
+ """ ))
212
+ $ ex_calc
213
+ return STaylor1 {N,T} ($ exout)
214
+ end
215
+ end
216
+
183
217
# Recursive functions (homogeneous coefficients)
184
218
for T in (:Taylor1 , :TaylorN )
185
219
@eval begin
0 commit comments