summaryrefslogtreecommitdiff
path: root/examples/SimpleVC.tcl
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2011-11-22 05:17:55 +0000
committerMorgan Deters <mdeters@gmail.com>2011-11-22 05:17:55 +0000
commit38bfb8f76514b154c9d6cc370c5cdbdb8118e66c (patch)
tree34113c0cbde85ba3a987db81922f97ec6fa15fea /examples/SimpleVC.tcl
parentebba5e92588a500a7384f7337968758386db7888 (diff)
More language bindings work:
* with a patched SWIG, the ocaml bindings build correctly. ** I will provide my patch to the SWIG dev team. * fixed some class interfaces to play more nicely with SWIG. * php, perl, tcl now work; examples added. * improved binding module building and installation. Also: Stop #defining NULL ((void*) 0). This has been in cvc4_public.h for a long, long time, I forget why I added it in the first place, and it's a very, very bad idea. In C++, certain things are permitted for NULL that aren't permitted for ((void*) 0), like for instance implicit conversion to any pointer type. We didn't see an issue here (until now, when interfacing with SWIG), because GCC is usually pretty smart at working around such a broken #definition of NULL. But that's fragile. New exception-free Command architecture. Previously, some command invocations were wrapped in a try {} catch() {} and printed out an error. This is much more consistent now. Each Command invocation results in a CommandStatus. The status can be "unsupported", "error", or "success" (these are each derived classes, though, not strings, so that they can be easily printed in a language-specific way... e.g., in SMT-LIBv2, they are printed in a manner consistent with the spec, and "success" is not printed if the print-success option is off.) All Command functionality are now no-throw functions, which @cconway reports is a Good Thing for Google (where all C++ exceptions are suspect), and also I think is much cleaner than the old way in this instance. Added an --smtlib2 option that enables an "SMT-LIBv2 compliance mode"---really it just sets a few other options like strictParsing, inputLanguage, and printSuccess. In the future we might put other options into a compliance mode, or we might choose to make it the default.
Diffstat (limited to 'examples/SimpleVC.tcl')
-rwxr-xr-xexamples/SimpleVC.tcl54
1 files changed, 54 insertions, 0 deletions
diff --git a/examples/SimpleVC.tcl b/examples/SimpleVC.tcl
new file mode 100755
index 000000000..d2030f044
--- /dev/null
+++ b/examples/SimpleVC.tcl
@@ -0,0 +1,54 @@
+#! /usr/bin/tclsh
+##! \file SimpleVC.tcl
+### \verbatim
+### Original author: mdeters
+### Major contributors: none
+### Minor contributors (to current version): none
+### This file is part of the CVC4 prototype.
+### Copyright (c) 2009, 2010, 2011 The Analysis of Computer Systems Group (ACSys)
+### Courant Institute of Mathematical Sciences
+### New York University
+### See the file COPYING in the top-level source directory for licensing
+### information.\endverbatim
+###
+### \brief A simple demonstration of the Tcl interface
+###
+### A simple demonstration of the Tcl interface. Compare to the
+### C++ interface in simple_vc_cxx.cpp; they are quite similar.
+###
+### To run, use something like:
+###
+### ln -s ../builds/src/bindings/tcl/.libs/CVC4.so CVC4.so
+### ./SimpleVC.tcl
+####
+
+load CVC4.so CVC4
+
+ExprManager em
+SmtEngine smt em
+
+# Prove that for integers x and y:
+# x > 0 AND y > 0 => 2x + y >= 3
+
+set integer [ExprManager_integerType em]
+
+set x [ExprManager_mkVar em "x" $integer]
+set y [ExprManager_mkVar em "y" $integer]
+set zero [ExprManager_mkConst em [Integer _ 0]]
+
+set x_positive [ExprManager_mkExpr em $GT $x $zero]
+set y_positive [ExprManager_mkExpr em $GT $y $zero]
+
+set two [ExprManager_mkConst em [Integer _ 2]]
+set twox [ExprManager_mkExpr em $MULT $two $x]
+set twox_plus_y [ExprManager_mkExpr em $PLUS $twox $y]
+
+set three [ExprManager_mkConst em [Integer _ 3]]
+set twox_plus_y_geq_3 [ExprManager_mkExpr em $GEQ $twox_plus_y $three]
+
+set formula [BoolExpr_impExpr [BoolExpr _1 [ExprManager_mkExpr em $AND $x_positive $y_positive]] [BoolExpr _2 $twox_plus_y_geq_3]]
+
+puts "Checking validity of formula [Expr_toString $formula] with CVC4."
+puts "CVC4 should report VALID."
+puts "Result from CVC4 is: [Result_toString [SmtEngine_query smt $formula]]"
+
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback