docs: def substitute(expr, var_map):
      """Substitute symbols or (sub-)expressions with the given replacements and
      re-evalute the result
  
      Args:
          expr: The expression in which to perform the substitution
          var_map (dict): The substitution dictionary.
      """
      try:
          if isinstance(expr, SympyBasic):
              sympy_var_map = {
                  k: v for (k, v) in var_map.items()
                  if isinstance(k, SympyBasic)}
              return expr.subs(sympy_var_map)
          else:
              return expr.substitute(var_map)
      except AttributeError:
          if expr in var_map:
              return var_map[expr]
          return expr