docs: def _partial_diff(var, *params):
      """
      Sympy does not handle repeated partial derivation correctly, e.g.
      D(D(y, a), a) = D(y, a, a) but D(D(y, a), b) = 0.
      Use this function instead to prevent evaluation to zero.
      """
      if isinstance(var, sympy.Derivative):
          return sympy.Derivative(var.expr, *(var.variables + params))
      else:
          return D(var, *params)