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

perf: api.IsZero generate less constraints #356

Merged
merged 5 commits into from
Aug 19, 2022
Merged

perf: api.IsZero generate less constraints #356

merged 5 commits into from
Aug 19, 2022

Conversation

gbotrel
Copy link
Collaborator

@gbotrel gbotrel commented Aug 11, 2022

used to have 3 constraints for api.IsZero

// m * (1 - m) = 0       // constrain m to be 0 or 1
// a * m = 0            // constrain m to be 0 if a != 0
// _ = inverse(m + a) 	// constrain m to be 1 if a == 0
// m is computed by the solver such that m = 1 - a^(modulus - 1)

can be done in 2:

// x = 1/a 		// in a hint (x == 0 if a == 0)
// m = -a*x + 1         // constrain m to be 1 if a == 0
// a * m = 0            // constrain m to be 0 if a != 0

@gbotrel gbotrel added the perf label Aug 11, 2022
@gbotrel gbotrel added this to the v0.8.0 milestone Aug 11, 2022
@gbotrel gbotrel requested a review from ThomasPiellard August 11, 2022 15:51
@gbotrel gbotrel marked this pull request as draft August 16, 2022 15:44
@gbotrel gbotrel marked this pull request as ready for review August 19, 2022 15:09
@gbotrel gbotrel merged commit b308ebb into develop Aug 19, 2022
@gbotrel gbotrel deleted the perf/iszero branch August 19, 2022 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant