1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/********************* */
/*! \file SimpleVC.java
** \verbatim
** Original author: mdeters
** Major contributors: none
** Minor contributors (to current version): none
** This file is part of the CVC4 prototype.
** Copyright (c) 2009, 2010, 2011 The Analysis of Computer Systems Group (ACSys)
** Courant Institute of Mathematical Sciences
** New York University
** See the file COPYING in the top-level source directory for licensing
** information.\endverbatim
**
** \brief A simple demonstration of the Java interface
**
** A simple demonstration of the Java interface.
**
** To run the resulting class file, you need to do something like the
** following:
**
** java \
** -classpath path/to/CVC4.jar \
** -Djava.library.path=/dir/containing/java/CVC4.so \
** SimpleVC
**
** For example, if you are building CVC4 without specifying your own
** build directory, the build process puts everything in builds/, and
** you can run this example (after building it with "make") like this:
**
** java \
** -classpath builds/examples:builds/src/bindings/CVC4.jar \
** -Djava.library.path=builds/src/bindings/java/.libs \
** SimpleVC
**/
import edu.nyu.acsys.CVC4.*;
import edu.nyu.acsys.CVC4.Integer;// to override java.lang.Integer name lookup
public class SimpleVC {
public static void main(String[] args) {
System.loadLibrary("CVC4");
ExprManager em = new ExprManager();
SmtEngine smt = new SmtEngine(em);
// Prove that for integers x and y:
// x > 0 AND y > 0 => 2x + y >= 3
Type integer = em.integerType();
Expr x = em.mkVar("x", integer);
Expr y = em.mkVar("y", integer);
Expr zero = em.mkConst(new Integer(0));
Expr x_positive = em.mkExpr(Kind.GT, x, zero);
Expr y_positive = em.mkExpr(Kind.GT, y, zero);
Expr two = em.mkConst(new Integer(2));
Expr twox = em.mkExpr(Kind.MULT, two, x);
Expr twox_plus_y = em.mkExpr(Kind.PLUS, twox, y);
Expr three = em.mkConst(new Integer(3));
Expr twox_plus_y_geq_3 = em.mkExpr(Kind.GEQ, twox_plus_y, three);
BoolExpr formula =
new BoolExpr(em.mkExpr(Kind.AND, x_positive, y_positive)).
impExpr(new BoolExpr(twox_plus_y_geq_3));
System.out.println("Checking validity of formula " + formula + " with CVC4.");
System.out.println("CVC4 should report VALID.");
System.out.println("Result from CVC4 is: " + smt.query(formula));
}
}
|