143143
144144Base. show (io:: IO , z:: Dual ) = dual_show (io, z, get (IOContext (io), :compact , false ))
145145
146- @static if VERSION < v " 0.7.0-DEV.4524"
147- Base. showcompact (io:: IO , z:: Dual ) = dual_show (io, z, true )
148- end
149-
150146function Base. read (s:: IO , :: Type{Dual{T}} ) where T<: ReComp
151147 x = read (s, T)
152148 y = read (s, T)
@@ -212,6 +208,10 @@ function Base.angle(z::Dual{Complex{T}}) where T<:Real
212208 end
213209end
214210
211+ Base. flipsign (x:: Dual ,y:: Dual ) = y == 0 ? flipsign (x, epsilon (y)) : flipsign (x, value (y))
212+ Base. flipsign (x, y:: Dual ) = y == 0 ? flipsign (x, epsilon (y)) : flipsign (x, value (y))
213+ Base. flipsign (x:: Dual , y) = dual (flipsign (value (x), y), flipsign (epsilon (x), y))
214+
215215# algebraic definitions
216216conjdual (z:: Dual ) = Dual (value (z),- epsilon (z))
217217absdual (z:: Dual ) = abs (value (z))
@@ -264,6 +264,8 @@ Base.:^(z::Dual, n::Number) = Dual(value(z)^n, epsilon(z)*n*value(z)^(n-1))
264264NaNMath. pow (z:: Dual , n:: Number ) = Dual (NaNMath. pow (value (z),n), epsilon (z)* n* NaNMath. pow (value (z),n- 1 ))
265265NaNMath. pow (z:: Number , w:: Dual ) = Dual (NaNMath. pow (z,value (w)), epsilon (w)* NaNMath. pow (z,value (w))* log (z))
266266
267+ inv (z:: Dual ) = dual (inv (value (z)),- epsilon (z)/ value (z)^ 2 )
268+
267269# force use of NaNMath functions in derivative calculations
268270function to_nanmath (x:: Expr )
269271 if x. head == :call
@@ -275,14 +277,25 @@ function to_nanmath(x::Expr)
275277end
276278to_nanmath (x) = x
277279
280+
281+
282+
278283for (funsym, exp) in Calculus. symbolic_derivatives_1arg ()
279284 funsym == :exp && continue
280285 funsym == :abs2 && continue
281- isdefined (Base, funsym) || continue
282- @eval function Base. $ (funsym)(z:: Dual )
283- x = value (z)
284- xp = epsilon (z)
285- Dual ($ (funsym)(x),xp* $ exp)
286+ funsym == :inv && continue
287+ if isdefined (SpecialFunctions, funsym)
288+ @eval function SpecialFunctions. $ (funsym)(z:: Dual )
289+ x = value (z)
290+ xp = epsilon (z)
291+ Dual ($ (funsym)(x),xp* $ exp)
292+ end
293+ elseif isdefined (Base, funsym)
294+ @eval function Base. $ (funsym)(z:: Dual )
295+ x = value (z)
296+ xp = epsilon (z)
297+ Dual ($ (funsym)(x),xp* $ exp)
298+ end
286299 end
287300 # extend corresponding NaNMath methods
288301 if funsym in (:sin , :cos , :tan , :asin , :acos , :acosh , :atanh , :log , :log2 , :log10 ,
0 commit comments