JuliaDiff / DualNumbers.jl

Julia package for representing dual numbers and for performing dual algebra
Other
80 stars 30 forks source link

Fix conj and abs. Add abs2. Make one(Dual) return a dual number. #4

Closed andreasnoack closed 10 years ago

andreasnoack commented 10 years ago

I think these are fixes. See e.g. here

mlubin commented 10 years ago

conj is a bit confusing to think about, but I do know that conj{T<:Real}(d::Dual{T}) must be equal to d, simply because conj(x::Real) = x. Otherwise the derivative information isn't correct. We've chosen to define functions so that f(d::Dual) = Dual(f(real(d)),dual(d)*f'(real(d))) always, even if this conflicts with the algebraic definition.

papamarkou commented 10 years ago

@andreasnoackjensen, @mlubin, what choice would you like us to make? I agree with @andreasnoackjensen' changes, as it seems more natural to me. Nevertheless, I see your point @mlubin, we don't want to violate differentiation.

andreasnoack commented 10 years ago

When you want to use Dual for differentiation of real functions you shouldn't use conj in your code, right? Wouldn't it be better to document that instead of having non-standard behaviour?

papamarkou commented 10 years ago

Yes, I agree with your remark and suggestion @andreasnoackjensen. @mlubin, if you don't object, I would agree for these changes to be merged.

mlubin commented 10 years ago

Unfortunately conj is used in many places in Base, for example, in dot and other vector operations. If we make this change, then dot of two Vector{Dual}s will not give the correct derivatives. I think it makes more sense to define a function conjdual that has the algebraic definition. Of course, this behavior should be well documented.

andreasnoack commented 10 years ago

@mlubin I see your point, and differentiation is the main point of the DualNumbers, but it just feels wrong not to have the math definitions right.