Fix cached free variable identifiers in sygus term database (#4394)
[cvc5.git] / examples / SimpleVC.py
1 #! /usr/bin/python
2 ##! \file SimpleVC.py
3 ### \verbatim
4 ### Original author: mdeters
5 ### Major contributors: none
6 ### Minor contributors (to current version): none
7 ### This file is part of the CVC4 prototype.
8 ### Copyright (c) 2009, 2010, 2011 The Analysis of Computer Systems Group (ACSys)
9 ### Courant Institute of Mathematical Sciences
10 ### New York University
11 ### See the file COPYING in the top-level source directory for licensing
12 ### information.\endverbatim
13 ###
14 ### \brief A simple demonstration of the Python interface
15 ###
16 ### A simple demonstration of the Python interface. Compare to the
17 ### C++ interface in simple_vc_cxx.cpp; they are quite similar.
18 ###
19 ### To run, use something like:
20 ###
21 ### ln -s ../builds/src/bindings/python/CVC4.py CVC4.py
22 ### ln -s ../builds/src/bindings/python/.libs/CVC4.so _CVC4.so
23 ### ./SimpleVC.py
24 ####
25
26 import CVC4
27 from CVC4 import ExprManager, SmtEngine, Rational, Expr
28
29 import sys
30
31 def main():
32 em = ExprManager()
33 smt = SmtEngine(em)
34
35 # Prove that for integers x and y:
36 # x > 0 AND y > 0 => 2x + y >= 3
37
38 integer = em.integerType()
39
40 x = em.mkVar("x", integer)
41 y = em.mkVar("y", integer)
42 zero = em.mkConst(Rational(0))
43
44 x_positive = em.mkExpr(CVC4.GT, x, zero)
45 y_positive = em.mkExpr(CVC4.GT, y, zero)
46
47 two = em.mkConst(Rational(2))
48 twox = em.mkExpr(CVC4.MULT, two, x)
49 twox_plus_y = em.mkExpr(CVC4.PLUS, twox, y)
50
51 three = em.mkConst(Rational(3))
52 twox_plus_y_geq_3 = em.mkExpr(CVC4.GEQ, twox_plus_y, three)
53
54 formula = Expr(em.mkExpr(CVC4.AND, x_positive, y_positive)).impExpr(Expr(twox_plus_y_geq_3))
55
56 print("Checking entailment of formula " + formula.toString() + " with CVC4.")
57 print("CVC4 should report ENTAILED .")
58 print("Result from CVC4 is: " + smt.checkEntailed(formula).toString())
59
60 return 0
61
62 if __name__ == '__main__':
63 sys.exit(main())
64