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

Optimising Zero Checks #381

Open
DavePearce opened this issue Nov 11, 2024 · 1 comment
Open

Optimising Zero Checks #381

DavePearce opened this issue Nov 11, 2024 · 1 comment

Comments

@DavePearce
Copy link
Collaborator

Optimising zero checks is important, because these often result in an entirely new column being created. Example:

(if-zero X Y Z)

Gets broken down into:

(1 - (~ X)) * Y
X * Z

Here, (~ X) results in a new column. However, suppose X is known to be binary (i.e. either X=0 or X=1). Then we can avoid the normalisation step.

@DavePearce
Copy link
Collaborator Author

In addition, there are other situations when we can also avoid the normalisation step. Consider this variation:

(defcolumns (X :binary@prove) (Y :binary@prove) Z)
(defconstraint test () (if-zero (+ X Y) Z))

Again, this would compile down to the constraint:

(1 - ~(X+Y)) * Z

This might seem more problematic, since X+Y can have any of three values: 0, 1 or 2. We can still encode this:

(1 - (X+Y) - (X*Y)) * Z

This works for two columns without needed an additional inverse.

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

No branches or pull requests

1 participant