Skip to content

Commit 48bf708

Browse files
authored
Make Counterexample Filtering Order Insensitive (#204)
1 parent 19ebba1 commit 48bf708

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

liquidjava-verifier/src/main/java/liquidjava/diagnostics/errors/RefinementError.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import liquidjava.api.CommandLineLauncher;
88
import liquidjava.diagnostics.TranslationTable;
9-
import liquidjava.rj_language.ast.Var;
9+
import liquidjava.rj_language.ast.Expression;
1010
import liquidjava.rj_language.ast.formatter.VariableFormatter;
1111
import liquidjava.rj_language.opt.derivation_node.ValDerivationNode;
1212
import liquidjava.smt.Counterexample;
@@ -46,16 +46,17 @@ public String getCounterExampleString() {
4646

4747
List<String> foundVarNames = new ArrayList<>();
4848
found.getValue().getVariableNames(foundVarNames);
49+
List<String> foundAssignments = found.getValue().getConjuncts().stream().map(Expression::toString).toList();
4950
String counterexampleString = counterexample.assignments().stream()
50-
// only include variables that appear in the found value
51-
.filter(a -> CommandLineLauncher.cmdArgs.debugMode || foundVarNames.contains(a.first()))
51+
// only include variables that appear in the found value and are not already fixed there
52+
.filter(a -> CommandLineLauncher.cmdArgs.debugMode || (foundVarNames.contains(a.first())
53+
&& !foundAssignments.contains(a.first() + " == " + a.second())))
5254
// format as "var == value"
5355
.map(a -> VariableFormatter.format(a.first()) + " == " + a.second())
5456
// join with "&&"
5557
.collect(Collectors.joining(" && "));
5658

57-
String foundString = found.getValue().toDisplayString();
58-
if (counterexampleString.isEmpty() || counterexampleString.equals(foundString))
59+
if (counterexampleString.isEmpty())
5960
return null;
6061

6162
return counterexampleString;

liquidjava-verifier/src/main/java/liquidjava/rj_language/ast/Expression.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ public boolean isBooleanExpression() {
8686
return false;
8787
}
8888

89+
public List<Expression> getConjuncts() {
90+
if (this instanceof BinaryExpression binaryExpression && "&&".equals(binaryExpression.getOperator())) {
91+
List<Expression> conjuncts = new ArrayList<>();
92+
conjuncts.addAll(binaryExpression.getFirstOperand().getConjuncts());
93+
conjuncts.addAll(binaryExpression.getSecondOperand().getConjuncts());
94+
return conjuncts;
95+
}
96+
return List.of(this);
97+
}
98+
8999
/**
90100
* Substitutes the expression first given expression by the second
91101
*

0 commit comments

Comments
 (0)