diff --git a/lib/core.cpp b/lib/core.cpp index 6ff5453..7fcf99e 100644 --- a/lib/core.cpp +++ b/lib/core.cpp @@ -1034,8 +1034,8 @@ auto operator*(const ScalarAffineFunction &a, const ScalarAffineFunction &b) auto d0 = b.constant.value(); for (int i = 0; i < a.coefficients.size(); i++) { - auto ci = b.coefficients[i]; - auto xi = b.variables[i]; + auto ci = a.coefficients[i]; + auto xi = a.variables[i]; t._add_affine_term(xi, ci * d0); } } diff --git a/tests/test_operator.py b/tests/test_operator.py index e58be4a..0d5fbb0 100644 --- a/tests/test_operator.py +++ b/tests/test_operator.py @@ -96,7 +96,10 @@ def test_operator(): vars[4], 3 * vars[2], 2 * vars[1] + vars[3], + 2 * vars[2] + vars[3] + 5.0, 13 * vars[4] * vars[4], + 17 * vars[3] * vars[3] + 1.0, + 17 * vars[3] * vars[5] + 3 * vars[1], 11 * vars[5] * vars[5] + 7 * vars[1] + 3.0, ] exprs += [ExprBuilder(e) for e in exprs] @@ -118,6 +121,9 @@ def test_operator(): continue expr = op(ei, ej) value = evaluate(expr, var_value_map) + flag = value == approx(op(expr_values[i], expr_values[j])) + if not flag: + k = 1 assert value == approx(op(expr_values[i], expr_values[j])) op = truediv