Skip to content
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

Better optimization of intermediate polynomials #2532

Open
wants to merge 5 commits into
base: linear-constraint-remover
Choose a base branch
from

Conversation

Schaeff
Copy link
Collaborator

@Schaeff Schaeff commented Mar 10, 2025

Before this PR, we different optimizers for the cases:

  • col i = constant -> inline i
  • w_0 = w_1 for two witnesses, only keep w_0
  • w = lin, replace witness w with intermediate, only if lin is NOT a single witness, to avoid overlapping with the previous optimizer

After this PR, we have:

  • w = lin, replace witness w (without the edge case above)
  • col i = e if e is a number or a polynomial reference -> inline i

This reduces complexity in the optimizer, and also produces more optimized code, as seen in the tests.

One "breaking" change is that now when many witness are constrained to be equal, the kept on is not the first, but the last, as shown below:

col witness x;
col witness y;
x = y; 
// `y` is linear, therefore we replace the identity by
col x = y;
// `y` is a number of a polynomial reference, therefore we replace usages of x by y

x does disappear.

This works for larger sets of equal-constrained witnesses, as shown in the tests.

@Schaeff Schaeff mentioned this pull request Mar 10, 2025
1 task
AlgebraicExpression::Number(value) => {
let ((name, poly_id), value) = symbols_and_definitions.next().unwrap();
match value {
AlgebraicExpression::Number(_) | AlgebraicExpression::Reference(_) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you check for "no shift"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, non-shifted is not required. Changed.

Copy link
Collaborator

@gzanitti gzanitti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

less complexity and better results, nice! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants