MutableArithmetics: An API for mutable operations
2021-07-29, 20:10–20:20 (UTC), Purple

The definition of the arithmetic operations defined in Julia assume that the arguments are not modified.
However, in many situations, a variable represents an accumulator that can be modified to contain the result, e.g., when summing the elements of an array.
Moreover, many types can be mutated and mutating the element may have significant performance benefit.
This talk presents an interface that allows algorithms to exploit a possible mutability while still being completely generic.


Julia allows to write generic algorithms that work with arbitrary number types as long as they implement the needed operation such as +, *, ...
The definition of the arithmetic operations defined in Julia assume that the arguments are not modified.
However, in many situations, a variable represents an accumulator that can be modified to contain the result, e.g., when summing the elements of an array.
Moreover, many types can be mutated, e.g., multiple precision numbers, JuMP expressions, MOI functions, polynomials, arrays, ...
and mutating the element may have significant performance benefit.

This talk presents an interface called MutableArithmetics.
It allows for mutable types to implement an arithmetics exploiting their mutability and for algorithms to exploit mutability while still being completely generic.
Moreover, it provides the following additional features:
1. it re-implements part of the Julia standard library on top of the API to allow mutable type to use a more efficient version than the default one.
2. it defines a @rewrite macro that rewrites an expression using the standard operations (e.g +, *, ...) into a code that exploits the mutability of the intermediate values created when evalutation the expression.

JuMP used to have its own API for mutable operations on JuMP expressions and its own JuMP-specific implementation of 1. and 2..
This was refactored into the package MutableArithmetics generalizing this to arbitrary mutable types.
Starting from JuMP v0.21, JuMP expression and MOI functions implement the MutableArithmetics API and the JuMP-specific implementation of 1. and 2. was removed in favor of the generic versions implemented in MutableArithmetics on top of the MutableArithmetics API.

While MutableArithmetics is already used in the released versions of numerous packages (such as JuMP, MathOptInterface, SumOfSquares, Polyhedra, SDDP and MultivariatePolynomials)
and seems to be working well and cover the use cases of many different types and algorithms on these types,
we may still need to modify the API to cover all possible use cases.
During this presentation, we hope to argue our design decision in a clear and detailed manner so that the Julia community can help us figure out whether there are situations that the API does not cover and how it could be further improved.

Benoît Legat is a postdoctoral associate at MIT with Prof. Pablo Parrilo
in the Laboratory for Information and Decision Systems (LIDS).
He received his Ph.D. degree in applied mathematics from the UCLouvain, Belgium, in 2020.
His research interests include mathematical optimization, invariant set computation and
optimal control.

This speaker also appears in: