Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rules/minion: apply weighted sum more often (negatives, equality)
These changes were motivated by the `basic/abs/03-flatten` test: it should be a weighted sum, but is not. With this commit, this becomes a weighted sum. * Remove sumleq / sumgeq rules, and merge these into the weighted sum rule. The weighted sum rule returns not applicable near the end if a normal sum should be used. Instead of this, this commit builds the normal sum here and returns it. * Add more cases to weighted sum, allowing negated expressions to be put inside the weighted sum. + -x ~> (-1,x) where x is an atom + -e ~> (-1,__1), with new constraint` __1=aux e` An alternative approach would be to add a normalisation rule `-e ~> -1 * e`; however, I don't think this should only happen inside sums, not in general. * Turn non-flat weighted sum equals expressions into weighted sums. * Remove `sum_eq_to_inequalities` and handle `x + y = z` and `2*x + 3*y =z` cases directly inside `introduce_weightedsumleq_sumgeq`. Expressions of the form `c*e1 + d*e2 + .. = t`, (where e1,e2 are non-flat) were not being turned into weighted sums. `sum_eq_to_inequalities` needs to run before a sumeq can be turned into a weighted sum, as `introduce_weighted_sumleq_sumgeq` only works on inequalities. However, flattening has a higher priority than this rule, which makes `introduce_weighted_sumleq_sumgeq` unapplicable to these expressions. (see 2833c5f (Convert weighted sums to Minion, 2025-01-07)). Furthermore, the priority change above causes an infinite cycle to occur between `flatten_binop` and `sum_eq_to_inequalities`: ``` sum([|a|, |b|]) = c ~~> sum_eq_to_inequalities (sum([|a|, |b|]) <= c /\ sum([|a|, |b|]) <= c) -- sum([|a|, |b|]) <= c ~~> flatten_binop __1 <= c with new top level constraints: __1 =aux sum([|a| , |b|]) -- sum([|a|, |b|]) =aux __1 ~~> sum_eq_to_inequalities (sum([|a|, |b|]) <= __1 /\ sum([|a|, |b|]) <= __1) ``` Both of these issues are fixed in this commit by removing `sum_eq_to_inequalities` and handling sum equals inside this rule.
- Loading branch information