Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty sums in Z3 #464

Merged
merged 1 commit into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ protected Long add(Long pNumber1, Long pNumber2) {

@Override
protected Long sumImpl(List<Long> operands) {
return Native.mkAdd(z3context, operands.size(), Longs.toArray(operands));
if (operands.isEmpty()) {
return makeNumberImpl(0);
} else {
return Native.mkAdd(z3context, operands.size(), Longs.toArray(operands));
}
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/org/sosy_lab/java_smt/test/NumeralFormulaManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public void distinctTest3() throws SolverException, InterruptedException {
assertThatFormula(bmgr.and(imgr.distinct(symbols), bmgr.and(constraints))).isUnsatisfiable();
}

@Test
public void trivialSumTest() throws SolverException, InterruptedException {
requireIntegers();
assertThatFormula(imgr.equal(imgr.sum(ImmutableList.of()), imgr.makeNumber(0)))
.isTautological();
assertThatFormula(
imgr.equal(imgr.sum(ImmutableList.of(imgr.makeVariable("a"))), imgr.makeVariable("a")))
.isTautological();
}

@SuppressWarnings("CheckReturnValue")
@Test
public void failOnInvalidStringInteger() {
Expand Down