-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Product
expression and normalising rules
#563
Merged
Merged
Conversation
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
niklasdewally
added
area::conjure-oxide/ast
Related to conjure_core and ast representation.
area::rules
Related to rewrite rules
labels
Dec 31, 2024
niklasdewally
force-pushed
the
nik/pr/add-mul/01
branch
3 times, most recently
from
December 31, 2024 16:33
b183e41
to
b69781b
Compare
ozgurakgun
reviewed
Jan 2, 2025
conjure_oxide/tests/integration/basic/product/01-simple/input-expected-rule-trace-human.txt
Outdated
Show resolved
Hide resolved
...ure_oxide/tests/integration/basic/weighted-sum/01-simple/input-expected-rule-trace-human.txt
Outdated
Show resolved
Hide resolved
...ests/integration/basic/weighted-sum/02-needs-normalising/input-expected-rule-trace-human.txt
Outdated
Show resolved
Hide resolved
niklasdewally
force-pushed
the
nik/pr/add-mul/01
branch
from
January 3, 2025 21:22
b69781b
to
bd3746d
Compare
niklasdewally
force-pushed
the
nik/pr/tester-add-run-solver-false/02
branch
from
January 3, 2025 21:23
76615b4
to
889cda9
Compare
Add `run_solver` config value to integration tests `config.toml` files. The main motivation for this change is to allow language feature implementation to be split into multiple PR's and still be testable.
niklasdewally
force-pushed
the
nik/pr/tester-add-run-solver-false/02
branch
from
January 3, 2025 21:24
889cda9
to
0ccef35
Compare
niklasdewally
force-pushed
the
nik/pr/add-mul/01
branch
2 times, most recently
from
January 3, 2025 21:34
eda3523
to
b2248a7
Compare
2 tasks
I've rebased this on top of the flat Minion constraints refactor (#566) |
Add `reorder_product` rule for products, giving them a (partial) canonical ordering. Having all products be constant*variable will be useful in detecting weighted sums, which are their own separate constraint in Minion.
A weighted sum is a sum of products `a*x + b*y + ...` where a,b are constants, and x,y variable references. This rule simplifies these sums by combining factors of the same variable together. For example, `a*x + ... + b*x ~> (a+b)*x`
Increase priority of `normalise_ac` to be above `reorder_product`. For example weighted-sum/02-needs-normalising does the following: ``` Product([Product([y, 3]), 1]), ~~> reorder_product ([("Base", 8800)]) Product([1, Product([y, 3])]) -- Product([y, 3]), ~~> reorder_product ([("Base", 8800)]) Product([3, y]) -- Product([y, -5]), ~~> reorder_product ([("Base", 8800)]) Product([-5, y]) -- Sum([Sum([Sum([Sum([Product([5, x]), Product([3, Product([1, Product([3, y])])])]), -(Product([3, x]))]), Product([-1, y])]), Product([-5, y])]), ~~> normalise_associative_commutative ([("Base", 8400)]) Sum([Product([5, x]), Product([3, Product([1, Product([3, y])])]), -(Product([3, x])), Product([-1, y]), Product([-5, y])]) ``` Instead of calling `reorder_product` for each nested product individually, we should flatten the product then call reorder_product once on the entire expression. Our other rules also implicitly assume a flat expression, as it is simpler, so having this ran at a higher priority makes sense.
niklasdewally
force-pushed
the
nik/pr/add-mul/01
branch
from
January 4, 2025 23:44
2138388
to
1aa0e2b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area::conjure-oxide/ast
Related to conjure_core and ast representation.
area::rules
Related to rewrite rules
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on: #561
Tracking issue: #505
This PR adds product expressions, and some normalising rules for them.
Changelog
ast: add Product expression
feat(rules): add canonical ordering for products
Add
reorder_product
rule for products, giving them a (partial) canonical ordering.Having all products be constant*variable will be useful in detecting weighted sums, which are their own separate constraint in Minion.
feat(rules): add collect_like_terms rule for weighted sums
A weighted sum is a sum of products
a*x + b*y + ...
where a,b are constants, and x,y variable references. This rule simplifies these sums by combining factors of the same variable together. For example,a*x + ... + b*x ~> (a+b)*x
test: add product normalising tests