-
Notifications
You must be signed in to change notification settings - Fork 100
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
Linear constraint remover #2425
base: main
Are you sure you want to change the base?
Conversation
ast/src/parsed/mod.rs
Outdated
@@ -738,6 +738,30 @@ impl<Ref> From<u32> for Expression<Ref> { | |||
BigUint::from(value).into() | |||
} | |||
} | |||
|
|||
impl<T: FieldElement> From<AlgebraicExpression<T>> for Expression<Reference> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is pil-analyzer/src/epressionizer.rs
that does this on a large scale. Maybe call that from pilopt instead of adding this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew we had this somewhere! Thanks! I added this just to make it compile
Depends on #2426. With this PR, we use the annotations added in #2412 and #2426 to find the columns being generated. This allows us to detect when the folded payload is not persisted as a witness column. The background is that @Schaeff is working on #2425, which would undo persisting the folded payloads in some cases, allowing us to spend fewer witness columns per bus interaction. With this PR, this should be fine: The column type will change from witness to intermediate, which means that the bus witgen will not output any folded columns. It can be tested by changing the `materialize_folded` bool to `false`, e.g. [here](https://github.com/powdr-labs/powdr/blob/e77d3801c1decff039fd0ec6bbeb55ed734357fb/std/protocols/bus.asm#L48) and running: ``` cargo run pil test_data/asm/block_to_block.asm \ -o output -f --linker-mode bus --prove-with mock --field gl ``` This used to fail before this PR.
what
Replace certain multilinear constraints* with intermediate polynomials in pilopt.
*with no next references, not touching public inputs
why
This comment highlights a use-case where materialising a column which is only constrained to a non-shifted multilinear polynomial is wasteful. Fixing this when we create the code is tricky, since we cannot know the degree of the constraint from pil. This is however something pilopt can do, which is what we attempt to do here
unknowns
col witness x; col witness y; x = 2 * y
gets completely optimized away. One argument for is that we already removex = y
entirely.- it's fine since we're doing only substitutions
- Witgen works!
x = 42
andx = y
which are both multilinear expressions. They do no yield intermediate polynomials, since in that case it is fine to "inline" them. This implementation currently makes sure all three optimizer apply to distinct cases, but maybe it would be better to have a single optimizer which handles all three cases, only introducing intermediate polynomials in the non trivial cases (42
andy
)