Add quantifiers API example, fixes #879 (#1146)
[cvc5.git] / examples / SimpleVC.php
1 #! /usr/bin/php
2 ##! \file SimpleVC.php
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 PHP interface
15 ###
16 ### A simple demonstration of the PHP 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/php/.libs/CVC4.so CVC4.so
22 ### ln -s ../builds/src/bindings/php/CVC4.php CVC4.php
23 ### ./SimpleVC.php
24 ####
25
26 use strict;
27 use CVC4;
28
29 my $em = new CVC4::ExprManager();
30 my $smt = new CVC4::SmtEngine($em);
31
32 # Prove that for integers x and y:
33 # x > 0 AND y > 0 => 2x + y >= 3
34
35 my $integer = $em->integerType();
36
37 my $x = $em->mkVar("x", $integer);
38 my $y = $em->mkVar("y", $integer);
39 my $zero = $em->mkConst(new CVC4::Integer(0));
40
41 my $x_positive = $em->mkExpr($CVC4::GT, $x, $zero);
42 my $y_positive = $em->mkExpr($CVC4::GT, $y, $zero);
43
44 my $two = $em->mkConst(new CVC4::Integer(2));
45 my $twox = $em->mkExpr($CVC4::MULT, $two, $x);
46 my $twox_plus_y = $em->mkExpr($CVC4::PLUS, $twox, $y);
47
48 my $three = $em->mkConst(new CVC4::Integer(3));
49 my $twox_plus_y_geq_3 = $em->mkExpr($CVC4::GEQ, $twox_plus_y, $three);
50
51 my $formula = new CVC4::Expr($em->mkExpr($CVC4::AND, $x_positive, $y_positive))->impExpr(new CVC4::Expr($twox_plus_y_geq_3));
52
53 print "Checking validity of formula " . $formula->toString() . " with CVC4.\n";
54 print "CVC4 should report VALID.\n";
55 print "Result from CVC4 is: " . $smt->query($formula)->toString() . "\n";
56