# UnitfulDual.jl - Combining dual numbers with physical units

**URL:** <https://discourse.julialang.org/t/unitfuldual-jl-combining-dual-numbers-with-physical-units/27168>\
**Category:** Package Announcements\
**Tags:** unitful\
**Created:** [August 5, 2019, 7:38am UTC](https://discourse.julialang.org/t/unitfuldual-jl-combining-dual-numbers-with-physical-units/27168 "2019-08-05T07:38:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AleMorales](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alemorales/32/48720_2.png) [@AleMorales](https://discourse.julialang.org/u/AleMorales)\
**Post date:** [August 5, 2019, 7:38am UTC](https://discourse.julialang.org/t/unitfuldual-jl-combining-dual-numbers-with-physical-units/27168/1 "2019-08-05T07:38:44Z")

</div>

Not sure where to post this, so I will give it a try here.

I write scientific models for my job and I always like to use [Unitful.jl](https://github.com/PainterQubits/Unitful.jl) to avoid manually tracking unit conversions and also as a basic check that the model is correct, at least from the point of view of physical dimensions. At the same time, I like to use dual numbers as in [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) to quickly and accurately calculate the local sensitivity of the model’s predictions to the different parameters. In the past I never manage to get both to work well together. I won’t go into the details but I think it ultimately boiled down to dual numbers assuming that data type use for the value and partial derivative being the same.

[UnitfulDual.jl](https://github.com/AleMorales/UnitfulDual.jl) implements dual numbers in a very similar fashion ForwardDiff.jl, the main difference being that partial derivatives can be of different types (with respect to the main value and to each other, so not an `NTuple`). This alone allows to propagate physical dimensions and units through both the value and partial derivatives in a type stable manner. I am also experimenting with using a named tuple for the partial derivatives which I think can make it easier to construct dual numbers and extract derivative information from the output.

The package is not registered and I have only tested it in a couple of real life examples. I would appreciate if people who have faced similar problems could give it a try and provide some feedback and tell me if they find it useful.
