Skip to content

Comments

Skip Ackermann constraints for derived arrays (weak equivalence)#8841

Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:arrays/weak-eq
Open

Skip Ackermann constraints for derived arrays (weak equivalence)#8841
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:arrays/weak-eq

Conversation

@tautschnig
Copy link
Collaborator

@tautschnig tautschnig commented Feb 24, 2026

Skip generating Ackermann constraints for arrays that are derived from other arrays via with (store), if, array_of, array constants, array_comprehension, typecast, or let expressions.

For a derived array such as x = y with [k := v], the Ackermann constraint i1 = i2 => x[i1] = x[i2] is already implied by:
(1) the with constraint: k != j => x[j] = y[j], and
(2) the Ackermann constraint on the base array y.
This is the read-over-weakeq optimisation from the theory of weakly equivalent arrays (Christ & Hoenicke, 2014).

The same reasoning applies to if, array_of, and other derived array expressions, all of which already have constraints connecting them element-wise to their constituent arrays.

With 5 stores to the same unbounded array the Ackermann constraint count drops from 110 to 60; with 40 stores it drops from 63180 to 31980 (approximately 50% reduction in all cases).

Co-authored-by: Kiro

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copilot AI review requested due to automatic review settings February 24, 2026 14:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements the "weak equivalence" optimization for array constraints in the SMT solver, specifically reducing redundant Ackermann constraints for derived arrays. The optimization recognizes that arrays created through operations like with (store), if, array_of, and similar expressions don't need separate Ackermann constraints because these are already implied by the combination of the operation's own constraints and the Ackermann constraints on the base arrays.

Changes:

  • Modified add_array_Ackermann_constraints() to skip generating constraints for derived array expressions
  • Added regression test demonstrating ~50% reduction in Ackermann constraints (from 110 to 60 for 5 stores)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/solvers/flattening/arrays.cpp Added logic to skip Ackermann constraint generation for derived arrays (with, if, array_of, etc.)
regression/cbmc/Array_UF23/test.desc Test configuration verifying the constraint count reduction from 110 to 60
regression/cbmc/Array_UF23/main.c Test case with 5 array stores to demonstrate the optimization
Comments suppressed due to low confidence (1)

src/solvers/flattening/arrays.cpp:355

  • The let_exprt check is separated from the other ID checks. Consider adding ID_let to the compound condition above (lines 347-350) for consistency and to avoid the need for a dynamic cast.
    if(expr_try_dynamic_cast<let_exprt>(arr))
      continue;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Skip generating Ackermann constraints for arrays that are derived from
other arrays via with (store), if, array_of, array constants,
array_comprehension, typecast, or let expressions.

For a derived array such as x = y with [k := v], the Ackermann
constraint i1 = i2 => x[i1] = x[i2] is already implied by:
  (1) the with constraint: k != j => x[j] = y[j], and
  (2) the Ackermann constraint on the base array y.
This is the read-over-weakeq optimisation from the theory of weakly
equivalent arrays (Christ & Hoenicke, 2014).

The same reasoning applies to if, array_of, and other derived array
expressions, all of which already have constraints connecting them
element-wise to their constituent arrays.

With 5 stores to the same unbounded array the Ackermann constraint
count drops from 110 to 60; with 40 stores it drops from 63180 to
31980 (approximately 50% reduction in all cases).

Co-authored-by: Kiro
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.02%. Comparing base (708e3fe) to head (a082485).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8841      +/-   ##
===========================================
+ Coverage    80.00%   80.02%   +0.01%     
===========================================
  Files         1700     1700              
  Lines       188252   188261       +9     
  Branches        73       73              
===========================================
+ Hits        150613   150650      +37     
+ Misses       37639    37611      -28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants