PolyPoNe: bitvector inequality relation support - #808
Draft
the-mr-dave wants to merge 5 commits into
Draft
the-mr-dave wants to merge 5 commits into
the-mr-dave wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Lower-bound solving and signed negation are unsound, while context-aware PolyPoNe paths can throw at runtime.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds bitvector inequality simplification to PolyPoNe while preserving two-sided bitvector semantics.
Changes:
- Introduces two-sided bitvector inequality representation and normalization.
- Extends PolyPoNe redundancy elimination, equality fusion, and equality cross-checking.
- Extracts the existing single-term implementation and adds tests.
File summaries
| File | Description |
|---|---|
SingleTermPolynomialRelation.java |
Houses the existing single-term relation implementation. |
PolyPoNe.java |
Integrates bitvector inequality simplification. |
PolynomialRelation.java |
Becomes the shared relation interface. |
BitvectorInequalityRelation.java |
Implements two-sided bitvector inequalities. |
BitvectorInequalityRelationTest.java |
Tests representation and boundary behavior. |
PolyPoNeTwoSidedTest.java |
Tests PolyPoNe bitvector simplification. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 4
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if (!isBareVariableVsBareConstant() || !subject.equals(getBareVariableTerm(script))) { | ||
| return null; // wrong shape or wrong variable | ||
| } | ||
| return new SolvedBinaryRelation(subject, getBareConstantTerm(script), mRelationSymbol); |
Comment on lines
+397
to
+402
| // negate both sides and swap them - same relation symbol, order reversed | ||
| final AbstractGeneralizedAffineTerm<?> negatedLhs = | ||
| (AbstractGeneralizedAffineTerm<?>) PolynomialTermOperations.mul(mRhs, Rational.MONE); | ||
| final AbstractGeneralizedAffineTerm<?> negatedRhs = | ||
| (AbstractGeneralizedAffineTerm<?>) PolynomialTermOperations.mul(mLhs, Rational.MONE); | ||
| return new BitvectorInequalityRelation(mRelationSymbol, negatedLhs, negatedRhs); |
| // PolyPoNe tries it here instead, only for itself, now that Phase B has made this class safe to | ||
| // use. The "real" fix would be moving this into PolynomialRelation.of once those other callers are | ||
| // checked too, and deleting this second attempt. | ||
| polyPolyRel = BitvectorInequalityRelation.of(mScript, param); |
Comment on lines
+430
to
+436
| final AbstractGeneralizedAffineTerm<?> variableSide = | ||
| polyRel.isVariableOnLhs() ? polyRel.getLhs() : polyRel.getRhs(); | ||
| for (final PolynomialRelation existing : mPolyRels.getImage(variableSide.getAbstractVariable2Coefficient())) { | ||
| if (existing.getRelationSymbol() == RelationSymbol.EQ) { | ||
| // existing's ψ is "variable - value", so its constant is -value | ||
| final Rational value = existing.getPolynomialTerm().getConstant().negate(); | ||
| return BitvectorUtils.constructBitvectorConstant(value.numerator(), variableSide.getSort()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
BitvectorInequalityRelation, a bitvector-inequality analogue ofPolynomialRelation, and wires it intoPolyPoNeso that bitvector comparisons (bvult,bvule,bvugt,bvuge,bvslt,bvsle,bvsgt,bvsge) participate in the same redundancy elimination thatPolyPoNealready does for arithmetic relations when combining AND/OR chains.What it does
x <=u 5 AND x <=u 3→x <=u 3).<uvs<=u) by normalizing to an equivalent inclusive boundary, so e.g.x <=u 7 AND x <u 8collapses tox <=u 7.x <=u 5 AND x >=u 5→x = 5).x + y) untouched rather than attempting a comparison for them.New/changed files
BitvectorInequalityRelation(new) — the bitvector-inequality data structure itself.PolyPoNe— extended to build, compare, and fuseBitvectorInequalityRelations alongside the existingPolynomialRelationhandling.SingleTermPolynomialRelation(new) — extracted fromPolynomialRelationto share representation logic between the numeric and bitvector-inequality cases.PolyPoNeTwoSidedTest,BitvectorInequalityRelationTest(new) — test coverage for the above.