2021-04-12 12:31:43 -07:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2022-04-05 13:38:57 -07:00
|
|
|
* Mudathir Mohamed, Morgan Deters, Andres Noetzli
|
2021-04-12 12:31:43 -07:00
|
|
|
*
|
|
|
|
|
* This file is part of the cvc5 project.
|
|
|
|
|
*
|
2022-04-05 13:38:57 -07:00
|
|
|
* Copyright (c) 2009-2022 by the authors listed in the file AUTHORS
|
2021-04-12 12:31:43 -07:00
|
|
|
* in the top-level source directory and their institutional affiliations.
|
|
|
|
|
* All rights reserved. See the file COPYING in the top-level source
|
|
|
|
|
* directory for licensing information.
|
|
|
|
|
* ****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* A simple demonstration of the Java interface.
|
|
|
|
|
*
|
|
|
|
|
* To run the resulting class file, you need to do something like the
|
|
|
|
|
* following:
|
2021-11-16 12:13:19 -06:00
|
|
|
* javac "-cp" "../build/src/api/java/cvc5.jar" SimpleVC.java
|
2021-04-12 12:31:43 -07:00
|
|
|
* java \
|
2021-11-16 12:13:19 -06:00
|
|
|
* "-Djava.library.path=../build/src/api/java" "-cp" "../build/src/api/java/cvc5.jar:." \
|
2021-04-12 12:31:43 -07:00
|
|
|
* SimpleVC
|
|
|
|
|
*/
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2022-03-30 21:09:03 -07:00
|
|
|
import static io.github.cvc5.Kind.*;
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2022-03-30 21:09:03 -07:00
|
|
|
import io.github.cvc5.*;
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2021-11-16 12:13:19 -06:00
|
|
|
public class SimpleVC
|
|
|
|
|
{
|
|
|
|
|
public static void main(String[] args)
|
|
|
|
|
{
|
2022-10-04 12:06:02 -05:00
|
|
|
Solver slv = new Solver();
|
2021-11-16 19:01:13 -06:00
|
|
|
{
|
|
|
|
|
// Prove that for integers x and y:
|
|
|
|
|
// x > 0 AND y > 0 => 2x + y >= 3
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2021-11-16 19:01:13 -06:00
|
|
|
Sort integer = slv.getIntegerSort();
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2021-11-16 19:01:13 -06:00
|
|
|
Term x = slv.mkConst(integer, "x");
|
|
|
|
|
Term y = slv.mkConst(integer, "y");
|
|
|
|
|
Term zero = slv.mkInteger(0);
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2021-11-16 19:01:13 -06:00
|
|
|
Term x_positive = slv.mkTerm(Kind.GT, x, zero);
|
|
|
|
|
Term y_positive = slv.mkTerm(Kind.GT, y, zero);
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2021-11-16 19:01:13 -06:00
|
|
|
Term two = slv.mkInteger(2);
|
|
|
|
|
Term twox = slv.mkTerm(Kind.MULT, two, x);
|
2022-02-02 20:25:14 -08:00
|
|
|
Term twox_plus_y = slv.mkTerm(Kind.ADD, twox, y);
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2021-11-16 19:01:13 -06:00
|
|
|
Term three = slv.mkInteger(3);
|
|
|
|
|
Term twox_plus_y_geq_3 = slv.mkTerm(Kind.GEQ, twox_plus_y, three);
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2021-11-16 19:01:13 -06:00
|
|
|
Term formula = slv.mkTerm(Kind.AND, x_positive, y_positive).impTerm(twox_plus_y_geq_3);
|
2011-09-30 23:01:58 +00:00
|
|
|
|
2021-11-16 19:01:13 -06:00
|
|
|
System.out.println("Checking entailment of formula " + formula + " with cvc5.");
|
2022-03-14 13:29:30 -05:00
|
|
|
System.out.println("cvc5 should report UNSAT.");
|
|
|
|
|
System.out.println(
|
|
|
|
|
"Result from cvc5 is: " + slv.checkSatAssuming(formula.notTerm()));
|
2021-11-16 19:01:13 -06:00
|
|
|
}
|
2011-09-30 23:01:58 +00:00
|
|
|
}
|
|
|
|
|
}
|