Skip to content

Conversation

@chriseth
Copy link
Member

No description provided.

for v in env.single_occurrence_variables().cloned(),
AlgebraicConstraint(e),
ContainsVariable(e, v2),
(v == v2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this be simplified by replacing ContainsVariable(e, v2), (v == v2)
with just ContainsVariable(e, v)?

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 somehow does not work when you do this, I think it's related to the "for".

HasProductSummand(e, x2, v2_),
(x2 != v1_),
(x1 != v2_),
AffineExpression(v2_, coeff2, v2, offset2),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does this rule only check the coefficients of v1_ and v2_, but not the
coefficients of x1 and x2? Since x1 and x2 are expressions, they could
also contain affine parts. Is the idea that this rule will be applied
iteratively to catch those cases?why here only consider the coefficients of v1_ and v2_, but not the coefficients of x1, x2, they are expressions and can have coefficients, or is this intend to do it iteratively?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is applied iteratively, I don't see a way how to do an arbitrary number of variables with such rules (all items predicates need to be Copy)


// Algebraic constraints:
cmp_result_0 * (cmp_result_0 - 1) = 0
(1 - cmp_result_0) * a__0_0 = 0
Copy link
Member Author

Choose a reason for hiding this comment

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

Why does it not remove these?

(1 - cmp_result_2) * (a__0_2 - b__0_2) = 0
(1 - cmp_result_2) * (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1) = 0
((opcode_loadb_flag0_1 - 1) * shifted_read_data__1_1 + opcode_loadb_flag0_0 * shifted_read_data__0_0 + (1 - opcode_loadb_flag0_0) * shifted_read_data__1_0 - opcode_loadb_flag0_1 * shifted_read_data__0_1) * diff_inv_marker__0_2 + (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1) * diff_inv_marker__1_2 + (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1) * diff_inv_marker__2_2 + (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1) * diff_inv_marker__3_2 - cmp_result_2 = 0
free_var_103 * ((a__0_2 - b__0_2) * (a__0_2 - b__0_2) + (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1) * (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1) + (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1) * (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1) + (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1) * (255 * data_most_sig_bit_0 - 255 * data_most_sig_bit_1)) - cmp_result_2 = 0
Copy link
Member Author

Choose a reason for hiding this comment

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

Since this rule increases the degree, we should maybe only run it after inlining.

// Here, we have e = coeff1 * v1 * x1 + coeff2 * v2 * x2 + ...
RangeConstraintOnExpression(x1, rc1),
RangeConstraintOnExpression(x2, rc2),
let Some(replacement) = (|| {
Copy link
Member Author

Choose a reason for hiding this comment

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

This code should be simplified

@chriseth chriseth mentioned this pull request Dec 1, 2025
@chriseth
Copy link
Member Author

chriseth commented Dec 2, 2025

After we get a basic version of this merged (that potentially already replaces some functionality in the solver), a next goal would be to reduce the number of variables before constructing the solver, to reduce its runtime.
Since the worst part of the solver is the exhaustive search, it would be good to catch some cases of exhaustive serach by patterns. Looking at the solver, I came across this example:

opcode_sub_flag_21 + 2 * opcode_xor_flag_21 + 3 * opcode_or_flag_21 + 4 * opcode_and_flag_21 = 0

All flags are boolean, so they must all be zero. I think the general case here could be something like

If the RC of an affine expression is not the default and its lower bound matches the constant, then all components have to be "minimal".

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