-
Notifications
You must be signed in to change notification settings - Fork 16
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. * 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. 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 inequalites. 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)). To fix this, this commit makes `sum_eq_to_inequalities` a higher priority than the flattening rules. A consequence of this is that more auxiliary variables are introduced than before, because non-flat expressions are being duplicated. For example: ``` $ before (a/b) + c = d ~> __1 + c = d [flatten_vecop] ~> __1 + c <= d /\ __1 + c >= d [sum_eq_to_inequalities] $ this commit (a/b) + c = d ~> (a/b) + c <= d /\ (a/b) + c >= d [sum_eq_to_inequalities] ~> __1 + c <= d /\ __1 + c >= d [flatten_vecop] ``` I don't think this is a problem, however: because these are syntactically identical, CSE should easily merge them (once we implement it). * Do not flatten sums inside leqs/geqs 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) ``` To fix this, this commit adds a special case to `flatten_binop` to ignore any Sum children of Leq and Geq.
- Loading branch information
1 parent
6236876
commit bb65323
Showing
31 changed files
with
2,750 additions
and
692 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.