Skip to content

Add .lower() methods to reduction and replication expressions#9123

Open
kroening wants to merge 1 commit into
developfrom
kroening/bitvector-expr-lower-methods
Open

Add .lower() methods to reduction and replication expressions#9123
kroening wants to merge 1 commit into
developfrom
kroening/bitvector-expr-lower-methods

Conversation

@kroening

Copy link
Copy Markdown
Collaborator

Add lower() methods to reduction_and_exprt, reduction_nand_exprt, reduction_or_exprt, reduction_nor_exprt, reduction_xor_exprt, reduction_xnor_exprt, and replication_exprt in bitvector_expr.h/bitvector_expr.cpp.

These methods lower high-level bitvector reduction and replication operators to simpler expression forms:

  • reduction_and(a)(a = all_ones)
  • reduction_nand(a)(a != all_ones)
  • reduction_or(a)(a != 0)
  • reduction_nor(a)(a = 0)
  • reduction_xor(a)a[0] ^ a[1] ^ ... ^ a[n-1]
  • reduction_xnor(a)!(a[0] ^ a[1] ^ ... ^ a[n-1])
  • replication(n, x)x :: x :: ... :: x (n times)

Use the new .lower() methods in smt2_conv.cpp to replace inline lowering code for reduction_and, reduction_nand, reduction_or, reduction_nor, and reduction_xnor. The reduction_xor case retains its native SMT-LIB encoding using extract + bvxor for efficiency.

The boolbv layer is not changed since it operates at the propositional literal level, and the SMT2 replication keeps its native repeat operator.

Companion to diffblue/hw-cbmc#2037 which will use these methods via .lower() instead of free functions.

@kroening
kroening force-pushed the kroening/bitvector-expr-lower-methods branch 3 times, most recently from acf1879 to 3961543 Compare July 21, 2026 12:18
Add lower() methods to reduction_and_exprt, reduction_nand_exprt,
reduction_or_exprt, reduction_nor_exprt, reduction_xor_exprt,
reduction_xnor_exprt, and replication_exprt in bitvector_expr.h/cpp.

These methods lower high-level bitvector reduction and replication
operators to simpler expression forms:
- reduction_and(a)  → (a = all_ones)
- reduction_nand(a) → (a != all_ones)
- reduction_or(a)   → (a != 0)
- reduction_nor(a)  → (a = 0)
- reduction_xor(a)  → a[0] ^ a[1] ^ ... ^ a[n-1]
- reduction_xnor(a) → !(a[0] ^ a[1] ^ ... ^ a[n-1])
- replication(n, x) → x :: x :: ... :: x (n times)

Use the new .lower() methods in smt2_conv.cpp to replace inline
lowering code for reduction_and, reduction_nand, reduction_or,
reduction_nor, and reduction_xnor. The reduction_xor case retains
its native SMT-LIB encoding using extract + bvxor for efficiency.
@kroening
kroening force-pushed the kroening/bitvector-expr-lower-methods branch from 3961543 to 67842c6 Compare July 21, 2026 12:22
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.82%. Comparing base (f71fdad) to head (67842c6).

Files with missing lines Patch % Lines
src/util/bitvector_expr.cpp 43.24% 21 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9123      +/-   ##
===========================================
- Coverage    80.83%   80.82%   -0.01%     
===========================================
  Files         1715     1715              
  Lines       189948   189979      +31     
  Branches        73       73              
===========================================
+ Hits        153540   153547       +7     
- Misses       36408    36432      +24     

☔ View full report in Codecov by Harness.
📢 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