Dual Matrix Tools

DualMatrixTools is a Julia package for solving dual-valued linear systems.

Essentially, it provides an overload for Julia’s factorize and \ functions that work with dual-valued arrays. It uses the dual type defined by the DualNumbers.jl package. The idea is that for a dual-valued matrix

$$M = A + \varepsilon B,$$

its inverse is given by

$$M^{-1} = (I - \varepsilon A^{-1} B) A^{-1}.$$

Therefore, only the inverse of $A$ is required to evaluate the inverse of $M$. This package makes available a DualFactors type which containts (i) the factors of $A$ and (ii) the non-real part, $B$. It also overloads factorize to create an instance of DualFactors (when invoked with a dual-valued matrix), which can then be called with \ to efficiently solve dual-valued linear systems of the type $M \, x = B$.

This package should be useful for autodifferentiation of functions that use \. Note the same idea extends to hyper dual numbers (see the HyperDualMatrixTools.jl package).

Usage

First, create your dual-valued matrix M:

julia> M = A + ε * B

Then, apply \ to solve systems of the type M * x = b

  • without factorization:
julia> x = M \ b
  • or better, with prior factorization:
julia> Mf = factorize(M)

julia> x = Mf \ b

(This is better in case you want to solve for another b!)

Advanced usage

In the context of iterative processes with multiple factorizations and forward and back substitutions, you may want to propagate dual-valued numbers while leveraging (potentially) the fact the real part of the matrices to be factorized remains the same throughout. This package provides an in-place factorize, with a flag to update (or not) the factors. Usage is straightforward. By default, factorize does not update the factors

julia> factorize(Mf, M) # only Mf.B is updated

If you want to update the real-valued factors too, use

julia> factorize(Mf, M, update_factors=true) # Mf.B and Mf.Af are updated

Citation

If you use this package, please cite it! Use the button at the top of this page, or go to the Zenodo record of the package and export the citation from there (the “Export” box at the bottom of that page).

Avatar
Benoît Pasquier
Research Associate

My research interests include mathematics, oceanography, and computer science.