18 if (!is_relational(formula))
return formula;
24 const Expression& lhs = get_lhs_expression(formula);
25 const Expression& rhs = get_rhs_expression(formula);
26 const Expression expr{needs_expansion_ ? (lhs - rhs).Expand() : lhs - rhs};
27 DLINEAR_ASSERT_FMT(expr.EqualTo(expr.Expand()),
"Expression {} must be expanded to {}", expr, expr.Expand());
28 DLINEAR_ASSERT_FMT(is_addition(expr) || is_multiplication(expr) || is_variable(expr),
29 "Expression must be an addition, multiplication or a variable. Instead found {}", expr);
31 const mpq_class constant{is_addition(expr) ? get_constant_in_addition(expr) : 0};
38 FormulaKind kind)
const {
40 if (is_multiplication(lhs) && get_base_to_exponent_map_in_multiplication(lhs).size() == 1 &&
41 is_variable(get_base_to_exponent_map_in_multiplication(lhs).begin()->first)) {
42 const mpq_class& constant{get_constant_in_multiplication(lhs)};
45 return BuildFlatteredFormula(get_base_to_exponent_map_in_multiplication(lhs).begin()->first, rhs, kind);
46 DLINEAR_ASSERT(constant != 0,
"Multiplication constant must be non-zero");
52 if (is_addition(lhs) && !get_expr_to_coeff_map_in_addition(lhs).empty() &&
53 is_variable(get_expr_to_coeff_map_in_addition(lhs).begin()->first) &&
54 get_expr_to_coeff_map_in_addition(lhs).begin()->second < 0) {
58 DLINEAR_ASSERT_FMT(!is_multiplication(lhs) || get_base_to_exponent_map_in_multiplication(lhs).size() != 1 ||
59 !is_variable(get_base_to_exponent_map_in_multiplication(lhs).begin()->first),
60 "lhs {} should have been modified by a previous call as a mult", lhs);
61 DLINEAR_ASSERT_FMT(!is_addition(lhs) || get_expr_to_coeff_map_in_addition(lhs).empty() ||
62 !is_variable(get_expr_to_coeff_map_in_addition(lhs).begin()->first) ||
63 get_expr_to_coeff_map_in_addition(lhs).begin()->second >= 0,
64 "lhs {} should have been modified by a previous call as an addition", lhs);
69 case FormulaKind::Neq:
71 case FormulaKind::Leq:
75 case FormulaKind::Geq:
80 DLINEAR_UNREACHABLE();