File: simple_vc_quant_cxx.cpp

package info (click to toggle)
cvc4 1.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 69,876 kB
  • sloc: cpp: 274,686; sh: 5,833; python: 1,893; java: 929; lisp: 763; ansic: 275; perl: 214; makefile: 22; awk: 2
file content (77 lines) | stat: -rw-r--r-- 2,555 bytes parent folder | download | duplicates (2)
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
74
75
76
77
/*********************                                                        */
/*! \file simple_vc_quant_cxx.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Andrew Reynolds
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
 ** 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.\endverbatim
 **
 ** \brief A simple demonstration of the C++ interface for quantifiers
 **
 ** A simple demonstration of the C++ interface for quantifiers. 
 **/

#include <iostream>

#include <cvc4/cvc4.h>

using namespace std;
using namespace CVC4;

int main() {
  ExprManager em;
  SmtEngine smt(&em);

  // Prove that the following is unsatisfiable:
  //   forall x. P( x ) ^ ~P( 5 )

  Type integer = em.integerType();
  Type boolean = em.booleanType();
  Type integerPredicate = em.mkFunctionType(integer, boolean);
  
  Expr p = em.mkVar("P", integerPredicate);
  Expr x = em.mkBoundVar("x", integer);
  
  // make forall x. P( x )
  Expr var_list = em.mkExpr(kind::BOUND_VAR_LIST, x);
  Expr px = em.mkExpr(kind::APPLY_UF, p, x);
  Expr quantpospx = em.mkExpr(kind::FORALL, var_list, px);
  cout << "Made expression : " << quantpospx << endl;
  
  //make ~P( 5 )
  Expr five = em.mkConst(Rational(5));
  Expr pfive = em.mkExpr(kind::APPLY_UF, p, five);
  Expr negpfive = em.mkExpr(kind::NOT, pfive);
  cout << "Made expression : " << negpfive << endl;
  
  Expr formula = em.mkExpr(kind::AND, quantpospx, negpfive);

  smt.assertFormula(formula);

  cout << "Checking SAT after asserting " << formula << " to CVC4." << endl;
  cout << "CVC4 should report unsat." << endl;
  cout << "Result from CVC4 is: " << smt.checkSat() << endl;


  SmtEngine smtp(&em);
  
  // this version has a pattern e.g. in smt2 syntax (forall ((x Int)) (! (P x ) :pattern ((P x))))
  Expr pattern = em.mkExpr(kind::INST_PATTERN, px);
  Expr pattern_list = em.mkExpr(kind::INST_PATTERN_LIST, pattern);
  Expr quantpospx_pattern = em.mkExpr(kind::FORALL, var_list, px, pattern_list);
  cout << "Made expression : " << quantpospx_pattern << endl;

  Expr formula_pattern = em.mkExpr(kind::AND, quantpospx_pattern, negpfive);

  smtp.assertFormula(formula_pattern);

  cout << "Checking SAT after asserting " << formula_pattern << " to CVC4." << endl;
  cout << "CVC4 should report unsat." << endl;
  cout << "Result from CVC4 is: " << smtp.checkSat() << endl;


  return 0;
}