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

Improved bit constraint detection #1461

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aminlatifi
Copy link
Contributor

@aminlatifi aminlatifi marked this pull request as draft June 23, 2024 13:09
@aminlatifi aminlatifi requested a review from chriseth June 24, 2024 21:14
@aminlatifi aminlatifi marked this pull request as ready for review June 24, 2024 21:14
@@ -268,8 +266,67 @@ fn propagate_constraints<T: FieldElement>(
(known_constraints, remove)
}

/// Get simple expression roots for a given expression.
Copy link
Member

Choose a reason for hiding this comment

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

Please tell me if the following is correct:

Tries to return the set of roots of a given expression in one variable.

If Some(vec![r1, r2, ... ,rn]) is returned, then the expression is equivalent to (x - r1)*(x - r2) * ... * (x - rn).

Please also change this function to return a tuple of the variable an the vector of roots. Or do you think this return type is better suited in some way?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, the above is actually not true, it should be equivalent to a nonzero multiple of the product.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If Some(vec![r1, r2, ... ,rn]) is returned, then the expression is equivalent to (x - r1)*(x - r2) * ... * (x - rn).

This one is correct. If I understood correctly, you need to support (x-r1)(x-r2)...(y-r'1)(y-r'2)*...
and return [(x, [r1,r2,...]),(y,[r'1, r'2,...])]

Copy link
Member

Choose a reason for hiding this comment

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

No, we cannot support that, for the pattern to match, there can only even be one variable.

.and_then(|l| l.solve().ok())?;

match root.constraints[..] {
[] => Some(vec![]),
Copy link
Member

Choose a reason for hiding this comment

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

I think in this case, the expression evaluates to zero and this is a very important specila case: While the numbers returned are all roots in that case, the list is not complete (all numbers are roots).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you mean we must return None and don't make any constraint?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

assert!(known_constraints
.insert(p, RangeConstraint::from_max_bit(0))
.is_none());
if let Some((p, constraint)) = is_binary_constraint(identity.expression_for_poly_id()) {
Copy link
Member

Choose a reason for hiding this comment

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

Now to use the root-finding function in the most general case (that includes the binary one), you should do the following:

Set the constraint to from_range(min, max) and set remove to true if all values from min to max occur in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't get the it well, can you give more details? You mean I don't use from_mask and use from_range instead? and don't try to make a binary mask which covers all numbers?

Copy link
Member

Choose a reason for hiding this comment

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

exactly

@chriseth chriseth changed the title Improved bit constraint detaction Improved bit constraint detection Jul 8, 2024
pub fn get_roots<T: FieldElement>(
/// Get simple expression roots for a given expression.
///
/// This function recursively evaluates an algebraic expression and attempts
Copy link
Member

Choose a reason for hiding this comment

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

This function is very complex, so its description has to be water-tight. It has to define what a root is and so on. I think a wording in the from of "if X is returned, it means the expression is equivalent to ..." would be helpful since it leaves little room for misunderstanding. Also, I don't think we need to explain how the function works, just what it returns.

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.

2 participants