mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
merged with unstable
This commit is contained in:
commit
3a0947b3ba
413 changed files with 31618 additions and 17204 deletions
|
@ -906,6 +906,72 @@ void enum_sort_example() {
|
|||
std::cout << "2: " << result_goal.as_expr() << std::endl;
|
||||
}
|
||||
|
||||
void expr_vector_example() {
|
||||
std::cout << "expr_vector example\n";
|
||||
context c;
|
||||
const unsigned N = 10;
|
||||
|
||||
expr_vector x(c);
|
||||
|
||||
for (unsigned i = 0; i < N; i++) {
|
||||
std::stringstream x_name;
|
||||
x_name << "x_" << i;
|
||||
x.push_back(c.int_const(x_name.str().c_str()));
|
||||
}
|
||||
|
||||
solver s(c);
|
||||
for (unsigned i = 0; i < N; i++) {
|
||||
s.add(x[i] >= 1);
|
||||
}
|
||||
|
||||
std::cout << s << "\n" << "solving...\n" << s.check() << "\n";
|
||||
model m = s.get_model();
|
||||
std::cout << "solution\n" << m;
|
||||
}
|
||||
|
||||
void exists_expr_vector_example() {
|
||||
std::cout << "exists expr_vector example\n";
|
||||
context c;
|
||||
const unsigned N = 10;
|
||||
|
||||
expr_vector xs(c);
|
||||
expr x(c);
|
||||
expr b(c);
|
||||
b = c.bool_val(true);
|
||||
|
||||
for (unsigned i = 0; i < N; i++) {
|
||||
std::stringstream x_name;
|
||||
x_name << "x_" << i;
|
||||
x = c.int_const(x_name.str().c_str());
|
||||
xs.push_back(x);
|
||||
b = b && x >= 0;
|
||||
}
|
||||
|
||||
expr ex(c);
|
||||
ex = exists(xs, b);
|
||||
std::cout << ex << std::endl;
|
||||
}
|
||||
|
||||
void substitute_example() {
|
||||
std::cout << "substitute example\n";
|
||||
context c;
|
||||
expr x(c);
|
||||
x = c.int_const("x");
|
||||
expr f(c);
|
||||
f = (x == 2) || (x == 1);
|
||||
std::cout << f << std::endl;
|
||||
|
||||
expr two(c), three(c);
|
||||
two = c.int_val(2);
|
||||
three = c.int_val(3);
|
||||
Z3_ast from[] = { two };
|
||||
Z3_ast to[] = { three };
|
||||
expr new_f(c);
|
||||
new_f = to_expr(c, Z3_substitute(c, f, 1, from, to));
|
||||
|
||||
std::cout << new_f << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
demorgan(); std::cout << "\n";
|
||||
|
@ -937,10 +1003,13 @@ int main() {
|
|||
tactic_example9(); std::cout << "\n";
|
||||
tactic_qe(); std::cout << "\n";
|
||||
tst_visit(); std::cout << "\n";
|
||||
incremental_example1(); std::cout << "\n";
|
||||
incremental_example2(); std::cout << "\n";
|
||||
incremental_example3(); std::cout << "\n";
|
||||
incremental_example1(); std::cout << "\n";
|
||||
incremental_example2(); std::cout << "\n";
|
||||
incremental_example3(); std::cout << "\n";
|
||||
enum_sort_example(); std::cout << "\n";
|
||||
expr_vector_example(); std::cout << "\n";
|
||||
exists_expr_vector_example(); std::cout << "\n";
|
||||
substitute_example(); std::cout << "\n";
|
||||
std::cout << "done\n";
|
||||
}
|
||||
catch (exception & ex) {
|
||||
|
|
|
@ -474,7 +474,7 @@ namespace test_mapi
|
|||
cells_c[i] = new BoolExpr[9];
|
||||
for (uint j = 0; j < 9; j++)
|
||||
cells_c[i][j] = ctx.MkAnd(ctx.MkLe(ctx.MkInt(1), X[i][j]),
|
||||
ctx.MkLe(X[i][j], ctx.MkInt(9)));
|
||||
ctx.MkLe(X[i][j], ctx.MkInt(9)));
|
||||
}
|
||||
|
||||
// each row contains a digit at most once
|
||||
|
@ -485,7 +485,13 @@ namespace test_mapi
|
|||
// each column contains a digit at most once
|
||||
BoolExpr[] cols_c = new BoolExpr[9];
|
||||
for (uint j = 0; j < 9; j++)
|
||||
cols_c[j] = ctx.MkDistinct(X[j]);
|
||||
{
|
||||
IntExpr[] column = new IntExpr[9];
|
||||
for (uint i = 0; i < 9; i++)
|
||||
column[i] = X[i][j];
|
||||
|
||||
cols_c[j] = ctx.MkDistinct(column);
|
||||
}
|
||||
|
||||
// each 3x3 square contains a digit at most once
|
||||
BoolExpr[][] sq_c = new BoolExpr[3][];
|
||||
|
@ -2087,7 +2093,7 @@ namespace test_mapi
|
|||
{
|
||||
QuantifierExample3(ctx);
|
||||
QuantifierExample4(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
Log.Close();
|
||||
if (Log.isOpen())
|
||||
|
|
18
examples/tptp/README
Normal file
18
examples/tptp/README
Normal file
|
@ -0,0 +1,18 @@
|
|||
TPTP front-end and utilities as a sample using the C++ bindings.
|
||||
To build the example execute
|
||||
make examples
|
||||
in the build directory.
|
||||
|
||||
This command will create the executable tptp.
|
||||
On Windows, you can just execute it.
|
||||
On OSX and Linux, you must install z3 first using
|
||||
sudo make install
|
||||
OR update LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX)
|
||||
with the build directory. You need that to be able to
|
||||
find the Z3 shared library.
|
||||
|
||||
The sample illustrates using Z3 from the TPTP language.
|
||||
The TPTP language is documented on http://tptp.org
|
||||
It also exposes utilities for converting between SMT-LIB
|
||||
and TPTP format.
|
||||
|
2480
examples/tptp/tptp5.cpp
Normal file
2480
examples/tptp/tptp5.cpp
Normal file
File diff suppressed because it is too large
Load diff
38
examples/tptp/tptp5.h
Normal file
38
examples/tptp/tptp5.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef TPTP5_H_
|
||||
#define TPTP5_H_
|
||||
|
||||
|
||||
class TreeNode;
|
||||
|
||||
#if 0
|
||||
class named_formulas {
|
||||
expr_ref_vector m_fmls;
|
||||
svector<symbol> m_names;
|
||||
bool m_has_conjecture;
|
||||
unsigned m_conjecture_index;
|
||||
public:
|
||||
named_formulas(ast_manager& m) :
|
||||
m_fmls(m),
|
||||
m_has_conjecture(false),
|
||||
m_conjecture_index(0)
|
||||
{}
|
||||
void push_back(expr* fml, char const* name) {
|
||||
m_fmls.push_back(fml);
|
||||
m_names.push_back(symbol(name));
|
||||
}
|
||||
unsigned size() const { return m_fmls.size(); }
|
||||
expr*const* c_ptr() const { return m_fmls.c_ptr(); }
|
||||
expr* operator[](unsigned i) { return m_fmls[i].get(); }
|
||||
symbol const& name(unsigned i) { return m_names[i]; }
|
||||
void set_has_conjecture() {
|
||||
m_has_conjecture = true;
|
||||
m_conjecture_index = m_fmls.size();
|
||||
}
|
||||
bool has_conjecture() const { return m_has_conjecture; }
|
||||
unsigned conjecture_index() const { return m_conjecture_index; }
|
||||
};
|
||||
|
||||
bool tptp5_parse(ast_manager& m, char const* filename, named_formulas& fmls);
|
||||
#endif
|
||||
|
||||
#endif
|
2672
examples/tptp/tptp5.lex.cpp
Normal file
2672
examples/tptp/tptp5.lex.cpp
Normal file
File diff suppressed because it is too large
Load diff
4475
examples/tptp/tptp5.tab.c
Normal file
4475
examples/tptp/tptp5.tab.c
Normal file
File diff suppressed because it is too large
Load diff
138
examples/tptp/tptp5.tab.h
Normal file
138
examples/tptp/tptp5.tab.h
Normal file
|
@ -0,0 +1,138 @@
|
|||
/* A Bison parser, made by GNU Bison 2.4.2. */
|
||||
|
||||
/* Skeleton interface for Bison's Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
under terms of your choice, so long as that work isn't itself a
|
||||
parser generator using the skeleton or a modified version thereof
|
||||
as a parser skeleton. Alternatively, if you modify or redistribute
|
||||
the parser skeleton itself, you may (at your option) remove this
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
know about them. */
|
||||
enum yytokentype {
|
||||
AMPERSAND = 258,
|
||||
AT_SIGN = 259,
|
||||
AT_SIGN_MINUS = 260,
|
||||
AT_SIGN_PLUS = 261,
|
||||
CARET = 262,
|
||||
COLON = 263,
|
||||
COLON_EQUALS = 264,
|
||||
COMMA = 265,
|
||||
EQUALS = 266,
|
||||
EQUALS_GREATER = 267,
|
||||
EXCLAMATION = 268,
|
||||
EXCLAMATION_EQUALS = 269,
|
||||
EXCLAMATION_EXCLAMATION = 270,
|
||||
EXCLAMATION_GREATER = 271,
|
||||
LBRKT = 272,
|
||||
LESS_EQUALS = 273,
|
||||
LESS_EQUALS_GREATER = 274,
|
||||
LESS_TILDE_GREATER = 275,
|
||||
LPAREN = 276,
|
||||
MINUS = 277,
|
||||
MINUS_MINUS_GREATER = 278,
|
||||
PERIOD = 279,
|
||||
QUESTION = 280,
|
||||
QUESTION_QUESTION = 281,
|
||||
QUESTION_STAR = 282,
|
||||
RBRKT = 283,
|
||||
RPAREN = 284,
|
||||
STAR = 285,
|
||||
TILDE = 286,
|
||||
TILDE_AMPERSAND = 287,
|
||||
TILDE_VLINE = 288,
|
||||
VLINE = 289,
|
||||
_DLR_cnf = 290,
|
||||
_DLR_fof = 291,
|
||||
_DLR_fot = 292,
|
||||
_DLR_itef = 293,
|
||||
_DLR_itetf = 294,
|
||||
_DLR_itett = 295,
|
||||
_DLR_tff = 296,
|
||||
_DLR_thf = 297,
|
||||
_LIT_cnf = 298,
|
||||
_LIT_fof = 299,
|
||||
_LIT_include = 300,
|
||||
_LIT_tff = 301,
|
||||
_LIT_thf = 302,
|
||||
arrow = 303,
|
||||
comment = 304,
|
||||
comment_line = 305,
|
||||
decimal = 306,
|
||||
decimal_exponent = 307,
|
||||
decimal_fraction = 308,
|
||||
distinct_object = 309,
|
||||
dollar_dollar_word = 310,
|
||||
dollar_word = 311,
|
||||
dot_decimal = 312,
|
||||
integer = 313,
|
||||
less_sign = 314,
|
||||
lower_word = 315,
|
||||
plus = 316,
|
||||
positive_decimal = 317,
|
||||
rational = 318,
|
||||
real = 319,
|
||||
signed_integer = 320,
|
||||
signed_rational = 321,
|
||||
signed_real = 322,
|
||||
single_quoted = 323,
|
||||
star = 324,
|
||||
unrecognized = 325,
|
||||
unsigned_integer = 326,
|
||||
unsigned_rational = 327,
|
||||
unsigned_real = 328,
|
||||
upper_word = 329,
|
||||
vline = 330
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
{
|
||||
|
||||
/* Line 1685 of yacc.c */
|
||||
#line 148 "tptp5.y"
|
||||
int ival; double dval; char* sval; TreeNode* pval;
|
||||
|
||||
|
||||
/* Line 1685 of yacc.c */
|
||||
#line 130 "tptp5.tab.h"
|
||||
} YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue