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

293 cvc5 interpolation #320

Merged
merged 62 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
773c760
Added CVC5 Interpolation Test in NativeAPITest
RSoegtrop May 11, 2023
dbf09ec
Working CVC5 Interpolation Example
RSoegtrop Jun 2, 2023
010b8a9
first prototype of cvc5 interpolation
RSoegtrop Jun 22, 2023
57c9eb8
added tree interpolation for cvc5. currently to slow to use
RSoegtrop Jun 27, 2023
937c3d6
finalizing sequential interpolation for cvc5
RSoegtrop Jun 28, 2023
ac7e609
fixed bug with unhandled cases
RSoegtrop Jul 10, 2023
26fdd27
test: added non terminating nativ cvc5 interpolation test
RSoegtrop Jul 11, 2023
ab8abc9
cleanup cvc5 interpolation and tests
RSoegtrop Jul 13, 2023
c5e096b
added documentation for cvc5 interpolation
RSoegtrop Jul 17, 2023
e368fcb
formatting
RSoegtrop Jul 18, 2023
99ace6d
fixed build issues
RSoegtrop Jul 18, 2023
750cecd
cvc5-interpolation: added separate solver instance for interpolation
RSoegtrop Jul 19, 2023
47f7b0a
removed separate assertion stack in CVC5 Interpolation
RSoegtrop Jul 24, 2023
747ec8f
fixed nullpointer exception
RSoegtrop Jul 24, 2023
b675a34
moved separate solver instance to exist only during interpolation
RSoegtrop Jul 27, 2023
5df8bd5
detailed cvc5 interpolation description
RSoegtrop Jul 27, 2023
953977b
cleanup. comment refinment.
RSoegtrop Aug 1, 2023
7cef68b
removed arrayLists
RSoegtrop Aug 2, 2023
6d244e6
fixed comments, buildissues, formatting
RSoegtrop Aug 2, 2023
46f7dfe
checkstyle suggestions
RSoegtrop Aug 2, 2023
9fc1499
refaster suggestions
RSoegtrop Aug 2, 2023
c2bfff8
removed recursion in formula building
RSoegtrop Aug 3, 2023
a85e32a
Merge branch 'master' into 293-cvc5-interpolation
RSoegtrop Aug 3, 2023
d021d30
debugging sequential Interpolation
RSoegtrop Aug 6, 2023
aee76aa
fixed conjunction building to be less expensive. fixed setting solver…
RSoegtrop Aug 6, 2023
5bd6c70
swapped most immutablelists with sets
RSoegtrop Aug 7, 2023
1438874
inserted Print
RSoegtrop Aug 7, 2023
7334751
changed implementation of CVC5 sequential Interpolation
RSoegtrop Aug 9, 2023
0164727
editorial
RSoegtrop Aug 10, 2023
27440c4
sequential interpolation working
RSoegtrop Aug 14, 2023
a2f30b1
refaster and checkstyle
RSoegtrop Aug 14, 2023
3a10f5a
format
RSoegtrop Aug 14, 2023
c57d776
added symbol check for interpolant
RSoegtrop Aug 15, 2023
49f1683
Ignored not terminating Tests
RSoegtrop Aug 15, 2023
7b14114
removed tree interpolation
RSoegtrop Aug 17, 2023
9b171fc
fixed build and checkstyle
RSoegtrop Aug 22, 2023
3240030
fixing build issue
RSoegtrop Aug 22, 2023
ce588fc
still fixing build issues
RSoegtrop Aug 22, 2023
eaf14d7
added interpolation check
RSoegtrop Aug 23, 2023
73d49a4
removed formula getter
RSoegtrop Aug 23, 2023
548e824
Merge branch 'master' into 293-cvc5-interpolation
RSoegtrop Aug 23, 2023
3b5f322
added test for trivial interpolation. updates access to assertedFormulas
RSoegtrop Aug 23, 2023
d4b2275
fix interpolation test
RSoegtrop Aug 28, 2023
cc09345
changed cvc5 to craig interpolation validation test to assertion
RSoegtrop Aug 31, 2023
8dddb6c
added documentation for interpolationCheck
RSoegtrop Aug 31, 2023
ef7e635
checkstyle
RSoegtrop Aug 31, 2023
b0f2d4c
Delete src/org/sosy_lab/java_smt/example/Interpolation2.java
RSoegtrop Sep 1, 2023
b7b345e
Fix CVC5 interpolation assertion for interpolants
Sep 1, 2023
afb52d6
Disable an internal assertion for interpolants for CVC5 interpolation…
Sep 1, 2023
a23e85e
do not ignore tests for all solvers, but only for CVC5.
kfriedberger Sep 2, 2023
470c192
some cleanup and simplification.
kfriedberger Sep 2, 2023
167b20c
rename for readability.
kfriedberger Sep 2, 2023
8e8f3ec
simplify and shorted some code.
kfriedberger Sep 2, 2023
c29bd55
simplify and shorten some code.
kfriedberger Sep 2, 2023
826a695
change code to satisfy the Eclipse-compiler and Refaster.
kfriedberger Sep 2, 2023
55a279d
disable slow test for CVC5 and interpolation.
kfriedberger Sep 2, 2023
6a56e82
Merge remote-tracking branch 'origin/master' into 293-cvc5-interpolation
kfriedberger Sep 3, 2023
7a1676e
adding test for counterexample with sequential interpolation vs repea…
kfriedberger Sep 10, 2023
fba562e
bugfix: FluentIterable::append does unwrap Iterables, including Terms…
kfriedberger Sep 10, 2023
acca076
add ConfigurationOption for validating interpolants from CVC5.
kfriedberger Oct 1, 2023
e9e9997
update documentation.
kfriedberger Oct 1, 2023
5e02942
fix JavaDoc format
kfriedberger Oct 1, 2023
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
230 changes: 230 additions & 0 deletions src/org/sosy_lab/java_smt/example/Interpolation2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
// This file is part of JavaSMT,
// an API wrapper for a collection of SMT solvers:
// https://github.com/sosy-lab/java-smt
//
// SPDX-FileCopyrightText: 2020 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Unlicense OR Apache-2.0 OR MIT

package org.sosy_lab.java_smt.example;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.sosy_lab.common.ShutdownNotifier;
import org.sosy_lab.common.configuration.Configuration;
import org.sosy_lab.common.configuration.InvalidConfigurationException;
import org.sosy_lab.common.log.BasicLogManager;
import org.sosy_lab.common.log.LogManager;
import org.sosy_lab.java_smt.SolverContextFactory;
import org.sosy_lab.java_smt.SolverContextFactory.Solvers;
import org.sosy_lab.java_smt.api.BooleanFormula;
import org.sosy_lab.java_smt.api.IntegerFormulaManager;
import org.sosy_lab.java_smt.api.InterpolatingProverEnvironment;
import org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula;
import org.sosy_lab.java_smt.api.SolverContext;
import org.sosy_lab.java_smt.api.SolverException;

/** Examples for Craig/sequential/tree interpolation. */
public class Interpolation2 {

private Interpolation2() {
// never called
}

public static void main(String... args)
throws InvalidConfigurationException, SolverException, InterruptedException {

// set up a basic environment
Configuration config = Configuration.defaultConfiguration();
LogManager logger = BasicLogManager.create(config);
ShutdownNotifier notifier = ShutdownNotifier.createDummy();

// choose solver
Solvers solver = Solvers.CVC5; // works for all interpolation strategies

// setup context
try (SolverContext context =
SolverContextFactory.createSolverContext(config, logger, notifier, solver);
InterpolatingProverEnvironment<?> prover =
context.newProverEnvironmentWithInterpolation()) {
logger.log(Level.WARNING, "Using solver " + solver + " in version " + context.getVersion());

IntegerFormulaManager imgr = context.getFormulaManager().getIntegerFormulaManager();

// example
prover.push();
interpolateExample(prover, imgr, logger);
prover.pop();

// and another example
prover.push();
interpolateProgramTrace(prover, imgr, logger);
prover.pop();

} catch (InvalidConfigurationException | UnsatisfiedLinkError e) {

// on some machines we support only some solvers,
// thus we can ignore these errors.
logger.logUserException(Level.INFO, e, "Solver " + solver + " is not available.");

} catch (UnsupportedOperationException e) {
logger.logUserException(Level.INFO, e, e.getMessage());
}
}

/**
* Example taken from SMTInterpol, <a
* href="http://ultimate.informatik.uni-freiburg.de/smtinterpol/interpolation.smt2">example as
* SMT-LIB</a>:
*
* <pre>
* (set-option :print-success false)
* (set-option :produce-proofs true)
* (set-logic QF_LIA)
* (declare-fun x () Int)
* (declare-fun y () Int)
* (assert (! (> x y) :named IP_0))
* (assert (! (= x 0) :named IP_1))
* (assert (! (> y 0) :named IP_2))
* (check-sat)
* (get-interpolants IP_0 IP_1 IP_2) // example 1 (1a and 1b)
* (get-interpolants IP_1 (and IP_0 IP_2)) // example 2 (2a and 2b)
* (exit)
* </pre>
*/
private static <T> void interpolateExample(
InterpolatingProverEnvironment<T> prover, IntegerFormulaManager imgr, LogManager logger)
throws InterruptedException, SolverException {

// create some variables.
IntegerFormula x = imgr.makeVariable("x");
IntegerFormula y = imgr.makeVariable("y");
IntegerFormula zero = imgr.makeNumber(0);

// create and assert some formulas.
// instead of 'named' formulas, we return a 'handle' (of generic type T)
T ip0 = prover.addConstraint(imgr.greaterThan(x, y));
T ip1 = prover.addConstraint(imgr.equal(x, zero));
T ip2 = prover.addConstraint(imgr.greaterThan(y, zero));

// check for satisfiability
boolean unsat = prover.isUnsat();
Preconditions.checkState(unsat, "the example for interpolation should be UNSAT");

List<BooleanFormula> itps;

{
// example 1a :
// get a sequence of interpolants for three formulas: (get-interpolants IP_0 IP_1 IP_2).
itps = prover.getSeqInterpolants0(ImmutableList.of(ip0, ip1, ip2));
logger.log(Level.INFO, "1a :: Interpolants for [{ip0},{ip1},{ip2}] are:", itps);
}

{
itps = prover.getSeqInterpolants0(ImmutableList.of(ip1, ip2));
logger.log(Level.INFO, "1a2 :: Interpolants for [{ip1},{ip2}] are:", itps);
}
{
itps = prover.getSeqInterpolants0(ImmutableList.of(ip0, ip1));
logger.log(Level.INFO, "1a3 :: Interpolants for [{ip0},{ip1}] are:", itps);
}
{
Set<T> partition3 = ImmutableSet.of(ip0, ip1);
Set<T> partition4 = ImmutableSet.of(ip2);
itps = prover.getSeqInterpolants(ImmutableList.of(partition3, partition4));
logger.log(Level.INFO, "1a4 :: Interpolants for [{ip0,ip1},{ip2}] are:", itps);
}

{
// example 1b :
// alternative solution ... with more code and partitioned formulas.
Set<T> partition0 = ImmutableSet.of(ip0);
Set<T> partition1 = ImmutableSet.of(ip1);
Set<T> partition2 = ImmutableSet.of(ip2);
itps = prover.getSeqInterpolants(ImmutableList.of(partition0, partition1, partition2));
logger.log(Level.INFO, "1b :: Interpolants for [{ip0},{ip1},{ip2}] are:", itps);
}

{
// example 2a :
// get a sequence of interpolants for two formulas: (get-interpolants IP_1 (and IP_0 IP_2)).
Set<T> partition3 = ImmutableSet.of(ip0);
Set<T> partition4 = ImmutableSet.of(ip1, ip2);
itps = prover.getSeqInterpolants(ImmutableList.of(partition3, partition4));
logger.log(Level.INFO, "2a :: Interpolants for [{ip0},{ip1,ip2}] are:", itps);
}

{
// example 2b :
// alternative solution, works when there are exactly two (!) groups of formulas.
// only one part is given as parameter, the rest is taken from the already asserted formulas.
BooleanFormula itp = prover.getInterpolant(ImmutableList.of(ip0));
logger.log(Level.INFO, "2b :: Interpolants for [{ip0},{ip1,ip2}] are:", itp);
}
}

/**
* Example for encoding a program path and computing interpolants along the path. Taken from <a
* href="http://satsmt2014.forsyte.at/files/2014/01/interpolation_philipp.pdf">slides</a> from
* Philipp Rümmer.
*
* <p>Example trace of a program:
*
* <pre>
* i=0
* k=j
* assume (i<50)
* i++
* k++
* assume (i>=50)
* assume (j==0)
* assume (k<50)
* </pre>
*/
private static <T> void interpolateProgramTrace(
InterpolatingProverEnvironment<T> prover, IntegerFormulaManager imgr, LogManager logger)
throws InterruptedException, SolverException {

// create some variables.
// primed variable needed for 'self-assignments', alternatively use SSA-indices.
IntegerFormula i = imgr.makeVariable("i");
IntegerFormula i1 = imgr.makeVariable("i'");
IntegerFormula j = imgr.makeVariable("j");
IntegerFormula k = imgr.makeVariable("k");
IntegerFormula k1 = imgr.makeVariable("k'");
IntegerFormula zero = imgr.makeNumber(0);
IntegerFormula one = imgr.makeNumber(1);
IntegerFormula fifty = imgr.makeNumber(50);

// create and assert some formulas.
List<BooleanFormula> programTrace =
ImmutableList.of(
imgr.equal(i, zero),
imgr.equal(k, j),
imgr.lessThan(i, fifty),
imgr.equal(i1, imgr.add(i, one)),
imgr.equal(k1, imgr.add(k, one)),
imgr.greaterOrEquals(i1, fifty),
imgr.equal(j, zero),
imgr.lessThan(k1, fifty));

// assert all formulas in the prover
List<T> handles = new ArrayList<>();
for (BooleanFormula step : programTrace) {
handles.add(prover.addConstraint(step));
}

// check for satisfiability
boolean unsat = prover.isUnsat();
Preconditions.checkState(unsat, "the example for interpolation should be UNSAT");

// get a sequence of interpolants for the program trace.
List<BooleanFormula> itps = prover.getSeqInterpolants0(handles);
logger.log(Level.INFO, "Interpolants for the program trace are:", itps);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private void setSolverOptions(int randomSeed, Set<ProverOptions> pOptions) {
solver.setOption("dump-models", "true");
solver.setOption("output-language", "smt2");
solver.setOption("seed", String.valueOf(randomSeed));
solver.setOption("produce-interpolants", "true");

// Set Strings option to enable all String features (such as lessOrEquals)
solver.setOption("strings-exp", "true");
Expand Down
Loading