Skip to content
Open
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
67 changes: 48 additions & 19 deletions src/org/sosy_lab/java_smt/solvers/cvc5/CVC5InterpolatingProver.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
package org.sosy_lab.java_smt.solvers.cvc5;

import static com.google.common.base.Preconditions.checkState;
import static org.sosy_lab.common.collect.Collections3.transformedImmutableListCopy;
import static org.sosy_lab.common.collect.Collections3.transformedImmutableSetCopy;

import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
Expand All @@ -20,7 +21,6 @@
import io.github.cvc5.Solver;
import io.github.cvc5.Term;
import io.github.cvc5.TermManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -86,24 +86,53 @@ public BooleanFormula getInterpolant(Collection<String> pFormulasOfA)
@Override
public List<BooleanFormula> getSeqInterpolants(List<? extends Collection<String>> partitions)
throws SolverException, InterruptedException {
final int n = partitions.size();
final List<BooleanFormula> itps = new ArrayList<>();
Term previousItp = termManager.mkTrue();
for (int i = 1; i < n; i++) {
Collection<Term> formulasA =
FluentIterable.from(partitions.get(i - 1))
.transform(assertedTerms.peek()::get)
.append(new Term[] {previousItp}) // class Term is Iterable<Term>, be careful here
.toSet();
Collection<Term> formulasB =
FluentIterable.concat(partitions.subList(i, n))
.transform(assertedTerms.peek()::get)
.toSet();
Term itp = getCVC5Interpolation(formulasA, formulasB);
itps.add(creator.encapsulateBoolean(itp));
previousItp = itp;
List<Term> groups =
transformedImmutableListCopy(
partitions,
partition ->
bmgr.andImpl(transformedImmutableSetCopy(partition, assertedTerms.peek()::get)));

// Uses a separate Solver instance to leave the original solver-context unmodified
Solver itpSolver = getNewSolver();

// We build the interpolant sequence in reverse:
// A & B & C -> (D -> false)
// (C1) A & B -> (C -> K)
// (B1) A -> (B -> J)
// (A1) A -> I
// (A2) I & B -> J
// (B2) J & C -> K
// (C2) K & D -> false
//
// By collecting the formulas, we get the sequence:
// (A1) A -> I
// (A2) I & B -> J
// (B2) J & C -> K
// (C2) K & D -> false
//
// Building the interpolants in reverse works better with the CVC5 API as it allows us to keep
// the "A"s on the solver stack
try {
for (int i = 0; i < groups.size() - 1; i++) {
itpSolver.push();
itpSolver.assertFormula(groups.get(i));
}

ImmutableList.Builder<BooleanFormula> builder = ImmutableList.builder();

Term lastItp = termManager.mkFalse();
for (int i = groups.size() - 1; i > 0; i--) {
lastItp =
itpSolver.simplify(itpSolver.getInterpolant(bmgr.implication(groups.get(i), lastItp)));
builder.add(creator.encapsulateBoolean(lastItp));

itpSolver.pop();
}
return builder.build().reverse();

} finally {
itpSolver.deletePointer();
}
return itps;
}

@Override
Expand Down
Loading