# Automatic differentiation

While the forward mode is straightforward and easier to implement, the reverse mode is computationally superior for scalar functions, as its complexity is independent of the number of intermediate variables. More generally, if $LaTeX: f : \mathbb{R}^n \rightarrow \mathbb{R}^m$, the forward mode has complexity of O(n), and the backward mode has complexity of O(m).