docs: def _parse_linear_expression(expression, expanded=False, **kwargs):
      """
      Parse the coefficients of a linear expression (linearity is assumed).
  
      Returns a dictionary of variable: coefficient pairs.
      """
      offset = 0
      constant = None
  
      if expression.is_Add:
          coefficients = expression.as_coefficients_dict()
      elif expression.is_Mul:
          coefficients = {expression.args[1]: expression.args[0]}
      elif expression.is_Symbol:
          coefficients = {expression: 1}
      elif expression.is_Number:
          coefficients = {}
      else:
          raise ValueError("Expression {} seems to be invalid".format(expression))
  
      for var in coefficients:
          if not (var.is_Symbol):
              if var == one:
                  constant = var
                  offset = float(coefficients[var])
              elif expanded:
                  raise ValueError("Expression {} seems to be invalid".format(expression))
              else:
                  coefficients = _parse_linear_expression(expression, expanded=True, **kwargs)
      if constant is not None:
          del coefficients[constant]
      return offset, coefficients