summaryrefslogtreecommitdiff
path: root/examples/SimpleVCCompat.java
blob: 5719b75cee18a2c8e277c89e50bb48465c7d7506 (plain)
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
/*********************                                                        */
/*! \file SimpleVCCompat.java
 ** \verbatim
 ** Original author: Morgan Deters <mdeters@cs.nyu.edu>
 ** Major contributors: none
 ** Minor contributors (to current version): none
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2013  New York University and The University of Iowa
 ** See the file COPYING in the top-level source directory for licensing
 ** information.\endverbatim
 **
 ** \brief A simple demonstration of the Java compatibility interface
 ** (quite similar to the old CVC3 Java interface)
 **
 ** A simple demonstration of the Java compatibility interface
 ** (quite similar to the old CVC3 Java interface).
 **
 ** To run the resulting class file, you need to do something like the
 ** following:
 **
 **   java \
 **     -classpath path/to/CVC4compat.jar \
 **     -Djava.library.path=/dir/containing/libcvc4bindings_java_compat.so \
 **     SimpleVCCompat
 **
 ** 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/compat/java/CVC4compat.jar \
 **     -Djava.library.path=builds/src/bindings/compat/java/.libs \
 **     SimpleVCCompat
 **/

import cvc3.*;

public class SimpleVCCompat {
  public static void main(String[] args) {
    ValidityChecker vc = ValidityChecker.create();

    // Prove that for integers x and y:
    //   x > 0 AND y > 0  =>  2x + y >= 3

    Type integer = vc.intType();

    Expr x = vc.varExpr("x", integer);
    Expr y = vc.varExpr("y", integer);
    Expr zero = vc.ratExpr(0);

    Expr x_positive = vc.gtExpr(x, zero);
    Expr y_positive = vc.gtExpr(y, zero);

    Expr two = vc.ratExpr(2);
    Expr twox = vc.multExpr(two, x);
    Expr twox_plus_y = vc.plusExpr(twox, y);

    Expr three = vc.ratExpr(3);
    Expr twox_plus_y_geq_3 = vc.geExpr(twox_plus_y, three);

    Expr formula = vc.impliesExpr(vc.andExpr(x_positive, y_positive),
                                  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: " + vc.query(formula));
  }
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback