Skip to content

PolyPoNe: bitvector inequality relation support - #808

Draft
the-mr-dave wants to merge 5 commits into
devfrom
wip/rvde/polypone-bitvector-inequality
Draft

the-mr-dave wants to merge 5 commits into
devfrom
wip/rvde/polypone-bitvector-inequality

Conversation

@the-mr-dave

Copy link
Copy Markdown
Contributor

Adds BitvectorInequalityRelation, a bitvector-inequality analogue of PolynomialRelation, and wires it into PolyPoNe so that bitvector comparisons (bvult, bvule, bvugt, bvuge, bvslt, bvsle, bvsgt, bvsge) participate in the same redundancy elimination that PolyPoNe already does for arithmetic relations when combining AND/OR chains.

What it does

  • Detects and drops a looser bound when a tighter one on the same variable is already present (e.g. x <=u 5 AND x <=u 3x <=u 3).
  • Compares bounds across strictness (<u vs <=u) by normalizing to an equivalent inclusive boundary, so e.g. x <=u 7 AND x <u 8 collapses to x <=u 7.
  • Fuses an upper and a lower bound with the same constant into an equality (x <=u 5 AND x >=u 5x = 5).
  • Cross-checks new bitvector inequalities against an already-known equality on the same variable, marking them redundant or inconsistent accordingly.
  • Leaves relations outside the simple "bare variable vs. bare constant" shape (e.g. both sides variables, or a compound expression like 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 fuse BitvectorInequalityRelations alongside the existing PolynomialRelation handling.
  • SingleTermPolynomialRelation (new) — extracted from PolynomialRelation to share representation logic between the numeric and bitvector-inequality cases.
  • PolyPoNeTwoSidedTest, BitvectorInequalityRelationTest (new) — test coverage for the above.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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());
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