1

This is an example in native CVC language:

isblue: STRING -> BOOLEAN;
ASSERT isblue("sky");
ASSERT isblue("water");
QUERY isblue("sky"); //valid
QUERY isblue("pig"); //invalid

How would I write it using the C++ API for CVC4? Couldn't find any documentation on how to do this.

ndb
  • 127
  • 1
  • 10
  • You would have to write your own theorem prover or use an existing one that's available from C++, I guess. C++ is not a first-order logic language. – user703016 Nov 29 '14 at 18:18
  • Sorry, should have made it clear: How do I write it using the C++ API for CVC4? – ndb Nov 29 '14 at 19:07

1 Answers1

3

There are some API examples in the source distribution that might help you. In particular, examples/api/combination.cpp creates some functions and predicates and makes some assertions:

https://github.com/CVC4/CVC4/blob/master/examples/api/combination.cpp

In your case, you'll create a predicate type with ExprManager::mkFunctionType(), then you construct an "isblue" predicate with ExprManager::mkVar() giving it that type. It will look something like this (assuming you've done "using namespace CVC4" and #included <cvc4/cvc4.h>):

  ExprManager em;
  SmtEngine smt(&em);

  Type predType = em.mkFunctionType(em.stringType(), em.booleanType());
  Expr isblue = em.mkVar(predType);

Then you can assert and query applications of your predicate:

  smt.assertFormula(em.mkExpr(kind::APPLY_UF, isblue, em.mkConst(String("sky"))));
  smt.assertFormula(em.mkExpr(kind::APPLY_UF, isblue, em.mkConst(String("water"))));
  smt.query(em.mkExpr(kind::APPLY_UF, isblue, em.mkConst(String("sky"))));
  smt.query(em.mkExpr(kind::APPLY_UF, isblue, em.mkConst(String("pig"))));