Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions autoprecompiles/src/optimizer_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,63 @@ TODO Continue with the abstraction using Range Constraints.
## Combining Range Constraints


## Grouped Expressions

The main data structure used for algebraic expressions the _Grouped Expression_.
A Grouped Expression consists of a constant term, a list of linear terms (a list of pairs of a non-zero coefficient
and a variable) and a list of quadratic terms (a list of pairs of Grouped Expressions).

For affine Algebraic Expressions, the Grouped Expression provides a normal form (if sorted by variable).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
For affine Algebraic Expressions, the Grouped Expression provides a normal form (if sorted by variable).
For affine algebraic expressions, the Grouped Expression provides a normal form (if sorted by variable).

Now sure Algebraic Expressions were defined as a type?

Copy link
Member Author

Choose a reason for hiding this comment

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

It even provides a normal form for affine Algebraic Constraints if multiplied by a factor such that
Copy link
Member

Choose a reason for hiding this comment

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

Why Algebraic Constraints in capital initials?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm writing all properly defined concepts in capitals, and in italics (using _..._) at the place where they are defined.

the constant term is zero or one.
Copy link
Collaborator

Choose a reason for hiding this comment

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

How can this become zero?
It sounds like there would have to be some factor such that (const * factor) mod P = 0, which would mean that either const or factor is zero.

Copy link
Member

Choose a reason for hiding this comment

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

ping @chriseth

Copy link
Member Author

@chriseth chriseth Nov 3, 2025

Choose a reason for hiding this comment

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

Ah this is actually more complicated than I thought and also written in a bad way. What about the following:

It even provides a normal form for affine Algebraic Constraints if we require 
the coefficient of the first variable (according to some fixed order on the 
variables) to be one. Note that an Algebraic Constraint can be multiplied 
by a nonzero factor without changing the semantics.


This normal fom makes it easy to compare affine Algebraic Expressions for equality,
check if they have a constant difference, etc.

If a map data structure is used for the linear terms, substitution of variables is also quick.
Copy link
Member

Choose a reason for hiding this comment

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

Why

Copy link
Member Author

Choose a reason for hiding this comment

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

At least you do not need to search for the variable.


Addition and subtraction of Grouped Expressions is implemented to remove linear terms that cancel each other out,
and it performs some checks also in the quadratic terms, but this part is not complete for performance reasons.

## Equivalence Notion

TODO define the property of a Constraint System the optimizer preserves

We call two Constraint Systems _equivalent_ if every satisfying assignment for one system
can be extended to a satisfying assignment for the other system and every such extension
leads to the same payloads and multiplicities for all _stateful_ bus interactions in both systems.
Copy link
Member

Choose a reason for hiding this comment

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

And every non-satisfying assignment of the first system must also not satisfy the second

Copy link
Member Author

Choose a reason for hiding this comment

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

I meant "if for both of the two systems, every satisfying assignment can be extended to a satisfying system for the other", so it's symmetric. Is that the misunderstanding? If not:

Written like this, we could have a non-satisfying assignment for one system that is non-satisfying since it assigns an invalid value to a variable that does not occur in the other system, then that assignment could still be satisfying for the other system.

But even in the case we have the same variables, I think what you mean is already included:
Suppose we have an assignment A that does not satisfy system 1 but it does satisfy system 2. Then because of equivalence, it must be extensible to a satisfying assignment for system 1, which is a contradiction since the variables are the same but A does not satisfy system 1.

Copy link
Member

Choose a reason for hiding this comment

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

Right yea, I missed the "one system or the other" being generic, I think it's fine as is


As an example, consider the two systems

System A:
```
x = 8
x + y + z = 12
2 1 [x, y, z]
Copy link
Member

Choose a reason for hiding this comment

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

I assume this is a bus interaction, maybe write as a tuple to look more organized?

w * (w - 1) = 0
```

System B:
```
y + z = 4
2 1 [8, y, z]
```

Let us assume that the bus with ID 2 is stateful and allows all combinations of values between 0 and 100 (inclusive).
Note that the variables `y` and `z` are not uniquely determined in either system, so the stateful bus
acts both as input and output for the system. TODO can that be or do we need one send and one receive?
Copy link
Member

Choose a reason for hiding this comment

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

Currently for openvm every stateful interaction has a receive and a send


Note that System B is obtained from System A by substituting `x = 8` and removing `w`.

All satisfying assignments of System A must have `x = 8` and either `w = 0` or `w = 1`.
Such an assignment also satisfies System B and it produces the same values for the stateful bus interaction.

The converse is a bit more complicated: Satisfying assignments of system B only assign the variables
`y` and `z`. So we need to extend the assignment for System A into a satisfying one. For `x`, the only
choice we have is `x = 8`, but there are two ways to extend the assignment with regards to `w` such that
it is still satisfying, `w = 0` or `w = 1`. Since both ways to extend the assignment
produce the same values in the stateful bus interaction, the systems are equivalent.

## Optimization Steps

The called functions are
Expand Down
Loading