3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-07 14:43:23 +00:00

merge with master

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2016-01-03 14:08:29 -08:00
commit 0c03a87c82
10 changed files with 231 additions and 174 deletions

View file

@ -643,7 +643,7 @@ def display_help(exit_code):
def parse_options():
global VERBOSE, DEBUG_MODE, IS_WINDOWS, VS_X64, ONLY_MAKEFILES, SHOW_CPPS, VS_PROJ, TRACE, VS_PAR, VS_PAR_NUM
global DOTNET_ENABLED, JAVA_ENABLED, ML_ENABLED, STATIC_LIB, PREFIX, GMP, FOCI2, FOCI2LIB, PYTHON_PACKAGE_DIR, GPROF, GIT_HASH
global LINUX_X64, SLOW_OPTIMIZE, USE_OMP, PYTHON_INSTALL_ENABLED
global LINUX_X64, SLOW_OPTIMIZE, USE_OMP
try:
options, remainder = getopt.gnu_getopt(sys.argv[1:],
'b:df:sxhmcvtnp:gj',
@ -711,29 +711,7 @@ def parse_options():
else:
print("ERROR: Invalid command line option '%s'" % opt)
display_help(1)
# Handle the Python package directory
if IS_WINDOWS:
# Installing under Windows doesn't make sense as the install prefix is used
# but that doesn't make sense under Windows
# CMW: It makes perfectly good sense; the prefix is Python's sys.prefix,
# i.e., something along the lines of C:\Python\... At the moment we are not
# sure whether we would want to install libz3.dll into that directory though.
PYTHON_INSTALL_ENABLED = False
else:
if not PYTHON_PACKAGE_DIR.startswith(PREFIX):
print(("Warning: The detected Python package directory (%s)"
" does not live under the installation prefix (%s)"
". This would lead to a broken Python installation. "
"Use --pypkgdir= to change the Python package directory") %
(PYTHON_PACKAGE_DIR, PREFIX))
if IS_OSX and PYTHON_PACKAGE_DIR.startswith('/Library/'):
print("Using hack to install Python bindings, this might lead to a broken system")
PYTHON_INSTALL_ENABLED = True
else:
print("Disabling install of Python bindings")
PYTHON_INSTALL_ENABLED = False
else:
PYTHON_INSTALL_ENABLED = True
# Return a list containing a file names included using '#include' in
# the given C/C++ file named fname.
@ -1039,6 +1017,11 @@ class Component:
def mk_unix_dist(self, build_path, dist_path):
return
# Used to print warnings or errors after mk_make.py is done, so that they
# are not quite as easy to miss.
def final_info(self):
pass
class LibComponent(Component):
def __init__(self, name, path, deps, includes2install):
Component.__init__(self, name, path, deps)
@ -1065,8 +1048,8 @@ class LibComponent(Component):
out.write('\n')
out.write('%s: %s\n\n' % (self.name, libfile))
def mk_install_dep(self, out):
out.write('%s' % libfile)
def mk_install_deps(self, out):
return
def mk_install(self, out):
for include in self.includes2install:
@ -1154,7 +1137,9 @@ class ExeComponent(Component):
def main_component(self):
return self.install
def mk_install_dep(self, out):
def mk_install_deps(self, out):
if self.install:
exefile = '%s$(EXE_EXT)' % self.exe_name
out.write('%s' % exefile)
def mk_install(self, out):
@ -1311,7 +1296,7 @@ class DLLComponent(Component):
def require_def_file(self):
return IS_WINDOWS and self.export_files
def mk_install_dep(self, out):
def mk_install_deps(self, out):
out.write('%s$(SO_EXT)' % self.dll_name)
if self.static:
out.write(' %s$(LIB_EXT)' % self.dll_name)
@ -1353,21 +1338,38 @@ class PythonInstallComponent(Component):
self.pythonPkgDir = None
self.in_prefix_install = True
self.libz3Component = libz3Component
if not PYTHON_INSTALL_ENABLED:
if IS_WINDOWS:
# Installing under Windows doesn't make sense as the install prefix is used
# but that doesn't make sense under Windows
# CMW: It makes perfectly good sense; the prefix is Python's sys.prefix,
# i.e., something along the lines of C:\Python\... At the moment we are not
# sure whether we would want to install libz3.dll into that directory though.
PYTHON_INSTALL_ENABLED = False
return
else:
PYTHON_INSTALL_ENABLED = True
if IS_WINDOWS or IS_OSX:
# Use full path that is possibly outside of install prefix
self.pythonPkgDir = PYTHON_PACKAGE_DIR
self.in_prefix_install = PYTHON_PACKAGE_DIR.startswith(PREFIX)
assert os.path.isabs(self.pythonPkgDir)
self.pythonPkgDir = strip_path_prefix(PYTHON_PACKAGE_DIR, PREFIX)
else:
# Use path inside the prefix (should be the normal case on Linux)
# CMW: Also normal on *BSD?
assert PYTHON_PACKAGE_DIR.startswith(PREFIX)
self.pythonPkgDir = strip_path_prefix(PYTHON_PACKAGE_DIR, PREFIX)
self.in_prefix_install = True
if self.in_prefix_install:
assert not os.path.isabs(self.pythonPkgDir)
assert self.in_prefix_install
def final_info(self):
if not PYTHON_PACKAGE_DIR.startswith(PREFIX):
print("Warning: The detected Python package directory (%s) is not "
"in the installation prefix (%s). This can lead to a broken "
"Python API installation. Use --pypkgdir= to change the "
"Python package directory." % (PYTHON_PACKAGE_DIR, PREFIX))
def main_component(self):
return False
@ -2339,12 +2341,12 @@ def mk_makefile():
out.write(' %s' % c.name)
out.write('\n\t@echo Z3 was successfully built.\n')
out.write("\t@echo \"Z3Py scripts can already be executed in the \'%s\' directory.\"\n" % BUILD_DIR)
out.write("\t@echo \"Z3Py scripts stored in arbitrary directories can be also executed if \'%s\' directory is added to the PYTHONPATH environment variable.\"\n" % BUILD_DIR)
out.write("\t@echo \"Z3Py scripts stored in arbitrary directories can be executed if the \'%s\' directory is added to the PYTHONPATH environment variable.\"\n" % BUILD_DIR)
if not IS_WINDOWS:
out.write("\t@echo Use the following command to install Z3 at prefix $(PREFIX).\n")
out.write('\t@echo " sudo make install"\n\n')
out.write("\t@echo If you are doing a staged install you can use DESTDIR.\n")
out.write('\t@echo " make DESTDIR=/some/temp/directory install"\n')
# out.write("\t@echo If you are doing a staged install you can use DESTDIR.\n")
# out.write('\t@echo " make DESTDIR=/some/temp/directory install"\n')
# Generate :examples rule
out.write('examples:')
for c in get_components():
@ -2358,6 +2360,8 @@ def mk_makefile():
if not IS_WINDOWS:
mk_install(out)
mk_uninstall(out)
for c in get_components():
c.final_info()
out.close()
# Finalize
if VERBOSE:
@ -3473,22 +3477,17 @@ class MakeRuleCmd(object):
@classmethod
def _install_root(cls, path, in_prefix, out, is_install=True):
if in_prefix:
assert not os.path.isabs(path)
install_root = cls.install_root()
else:
# This hack only exists for the Python bindings on OSX
# which are sometimes not installed inside the prefix.
# In all other cases installing outside the prefix is
# misleading and dangerous!
assert IS_OSX
assert os.path.isabs(path)
if not in_prefix:
# The Python bindings on OSX are sometimes not installed inside the prefix.
install_root = "$(DESTDIR)"
action_string = 'install' if is_install else 'uninstall'
cls.write_cmd(out, 'echo "WARNING: {}ing files/directories ({}) that are not in the install prefix ($(PREFIX))."'.format(
action_string, path))
print("WARNING: Generating makefile rule that {}s {} '{}' which is outside the installation prefix '{}'.".format(
action_string, 'to' if is_install else 'from', path, PREFIX))
#print("WARNING: Generating makefile rule that {}s {} '{}' which is outside the installation prefix '{}'.".format(
# action_string, 'to' if is_install else 'from', path, PREFIX))
else:
assert not os.path.isabs(path)
install_root = cls.install_root()
return install_root
@classmethod
@ -3608,14 +3607,15 @@ class MakeRuleCmd(object):
out.write("\t@{}\n".format(line))
def strip_path_prefix(path, prefix):
assert path.startswith(prefix)
if path.startswith(prefix):
stripped_path = path[len(prefix):]
stripped_path.replace('//','/')
if stripped_path[0] == '/':
stripped_path = stripped_path[1:]
assert not os.path.isabs(stripped_path)
return stripped_path
else:
return path
def configure_file(template_file_path, output_file_path, substitutions):
"""

View file

@ -931,13 +931,21 @@ extern "C" {
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
unsynch_mpz_manager & mpzm = mpfm.mpz_manager();
unsynch_mpq_manager & mpqm = mpfm.mpq_manager();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(mk_c(c)->get_fpa_fid());
scoped_mpf val(mpfm);
if (!plugin->is_numeral(to_expr(t), val)) {
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(fid);
SASSERT(plugin != 0);
expr * e = to_expr(t);
if (!is_app(e) ||
is_app_of(e, fid, OP_FPA_NAN) ||
is_app_of(e, fid, OP_FPA_PLUS_INF) ||
is_app_of(e, fid, OP_FPA_MINUS_INF)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return "";
}
else if (!mpfm.is_regular(val)) {
scoped_mpf val(mpfm);
app * a = to_app(e);
bool r = plugin->is_numeral(e, val);
if (!r || !mpfm.is_regular(val)) {
SET_ERROR_CODE(Z3_INVALID_ARG)
return "";
}
@ -960,16 +968,25 @@ extern "C" {
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
unsynch_mpz_manager & mpzm = mpfm.mpz_manager();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(mk_c(c)->get_fpa_fid());
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(to_expr(t), val);
if (!r) {
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(fid);
SASSERT(plugin != 0);
expr * e = to_expr(t);
if (!is_app(e) ||
is_app_of(e, fid, OP_FPA_NAN) ||
is_app_of(e, fid, OP_FPA_PLUS_INF) ||
is_app_of(e, fid, OP_FPA_MINUS_INF)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
*n = 0;
return 0;
}
scoped_mpf val(mpfm);
app * a = to_app(e);
bool r = plugin->is_numeral(e, val);
const mpz & z = mpfm.sig(val);
if (!mpzm.is_uint64(z)) {
if (!r || mpfm.is_regular(val)|| !mpzm.is_uint64(z)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
*n = 0;
return 0;
}
*n = mpzm.get_uint64(z);
@ -983,15 +1000,22 @@ extern "C" {
RESET_ERROR_CODE();
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(mk_c(c)->get_fpa_fid());
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(to_expr(t), val);
if (!r) {
SASSERT(plugin != 0);
expr * e = to_expr(t);
if (!is_app(e) ||
is_app_of(e, fid, OP_FPA_NAN) ||
is_app_of(e, fid, OP_FPA_PLUS_INF) ||
is_app_of(e, fid, OP_FPA_MINUS_INF)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return "";
}
else if (!mpfm.is_normal(val) && !mpfm.is_denormal(val)) {
SET_ERROR_CODE(Z3_INVALID_ARG)
scoped_mpf val(mpfm);
app * a = to_app(e);
bool r = plugin->is_numeral(e, val);
if (!r || !mpfm.is_regular(val)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return "";
}
mpf_exp_t exp = mpfm.exp_normalized(val);
@ -1007,11 +1031,24 @@ extern "C" {
RESET_ERROR_CODE();
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(mk_c(c)->get_fpa_fid());
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(to_expr(t), val);
if (!r) {
SASSERT(plugin != 0);
expr * e = to_expr(t);
if (!is_app(e) ||
is_app_of(e, fid, OP_FPA_NAN) ||
is_app_of(e, fid, OP_FPA_PLUS_INF) ||
is_app_of(e, fid, OP_FPA_MINUS_INF)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
*n = 0;
return 0;
}
scoped_mpf val(mpfm);
app * a = to_app(e);
bool r = plugin->is_numeral(e, val);
if (!r || !mpfm.is_regular(val)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
*n = 0;
return 0;
}
*n = mpfm.exp(val);

View file

@ -8352,20 +8352,36 @@ def FPSort(ebits, sbits, ctx=None):
ctx = z3._get_ctx(ctx)
return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
def _to_float_str(val):
def _to_float_str(val, exp=0):
if isinstance(val, float):
return str(val)
v = val.as_integer_ratio()
num = v[0]
den = v[1]
rvs = str(num) + '/' + str(den)
res = rvs + 'p' + _to_int_str(exp)
elif isinstance(val, bool):
if val:
return "1.0"
res = "1.0"
else:
return "0.0"
res = "0.0"
elif _is_int(val):
return str(val)
res = str(val)
elif isinstance(val, str):
return val
if __debug__:
_z3_assert(False, "Python value cannot be used as a double")
inx = val.find('*(2**')
if inx == -1:
res = val
elif val[-1] == ')':
res = val[0:inx]
exp = str(int(val[inx+5:-1]) + int(exp))
else:
_z3_assert(False, "String does not have floating-point numeral form.")
elif __debug__:
_z3_assert(False, "Python value cannot be used to create floating-point numerals.")
if exp == 0:
return res
else:
return res + 'p' + exp
def fpNaN(s):
_z3_assert(isinstance(s, FPSortRef), "sort mismatch")
@ -8422,8 +8438,6 @@ def FPVal(sig, exp=None, fps=None, ctx=None):
if exp == None:
exp = 0
val = _to_float_str(sig)
val = val + 'p'
val = val + _to_int_str(exp)
return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
def FP(name, fpsort, ctx=None):

View file

@ -49,6 +49,7 @@ void expr_abstractor::operator()(unsigned base, unsigned num_bound, expr* const*
case AST_APP: {
app* a = to_app(curr);
bool all_visited = true;
bool changed = false;
m_args.reset();
for (unsigned i = 0; i < a->get_num_args(); ++i) {
if (!m_map.find(a->get_arg(i), b)) {
@ -56,12 +57,17 @@ void expr_abstractor::operator()(unsigned base, unsigned num_bound, expr* const*
all_visited = false;
}
else {
changed |= b != a->get_arg(i);
m_args.push_back(b);
}
}
if (all_visited) {
if (changed) {
b = m.mk_app(a->get_decl(), m_args.size(), m_args.c_ptr());
m_pinned.push_back(b);
} else {
b = curr;
}
m_map.insert(curr, b);
m_stack.pop_back();
}

View file

@ -69,28 +69,30 @@ void fpa_decl_plugin::recycled_id(unsigned id) {
}
func_decl * fpa_decl_plugin::mk_numeral_decl(mpf const & v) {
sort * s = mk_float_sort(v.get_ebits(), v.get_sbits());
func_decl * r = 0;
if (m_fm.is_nan(v))
r = m_manager->mk_const_decl(symbol("NaN"), s, func_decl_info(m_family_id, OP_FPA_NAN));
else if (m_fm.is_pinf(v))
r = m_manager->mk_const_decl(symbol("+oo"), s, func_decl_info(m_family_id, OP_FPA_PLUS_INF));
else if (m_fm.is_ninf(v))
r = m_manager->mk_const_decl(symbol("-oo"), s, func_decl_info(m_family_id, OP_FPA_MINUS_INF));
else if (m_fm.is_pzero(v))
r = m_manager->mk_const_decl(symbol("+zero"), s, func_decl_info(m_family_id, OP_FPA_PLUS_ZERO));
else if (m_fm.is_nzero(v))
r = m_manager->mk_const_decl(symbol("-zero"), s, func_decl_info(m_family_id, OP_FPA_MINUS_ZERO));
else {
SASSERT(m_fm.is_regular(v));
parameter p(mk_id(v), true);
SASSERT(p.is_external());
sort * s = mk_float_sort(v.get_ebits(), v.get_sbits());
return m_manager->mk_const_decl(symbol("fp.numeral"), s, func_decl_info(m_family_id, OP_FPA_NUM, 1, &p));
r = m_manager->mk_const_decl(symbol("fp.numeral"), s, func_decl_info(m_family_id, OP_FPA_NUM, 1, &p));
}
return r;
}
app * fpa_decl_plugin::mk_numeral(mpf const & v) {
sort * s = mk_float_sort(v.get_ebits(), v.get_sbits());
func_decl * d;
if (m_fm.is_nan(v))
d = m_manager->mk_const_decl(symbol("NaN"), s, func_decl_info(m_family_id, OP_FPA_NAN));
else if (m_fm.is_pinf(v))
d = m_manager->mk_const_decl(symbol("+oo"), s, func_decl_info(m_family_id, OP_FPA_PLUS_INF));
else if (m_fm.is_ninf(v))
d = m_manager->mk_const_decl(symbol("-oo"), s, func_decl_info(m_family_id, OP_FPA_MINUS_INF));
else if (m_fm.is_pzero(v))
d = m_manager->mk_const_decl(symbol("+zero"), s, func_decl_info(m_family_id, OP_FPA_PLUS_ZERO));
else if (m_fm.is_nzero(v))
d = m_manager->mk_const_decl(symbol("-zero"), s, func_decl_info(m_family_id, OP_FPA_MINUS_ZERO));
else
d = mk_numeral_decl(v);
return m_manager->mk_const(d);
return m_manager->mk_const(mk_numeral_decl(v));
}
bool fpa_decl_plugin::is_numeral(expr * n, mpf & val) {

View file

@ -764,7 +764,6 @@ br_status fpa_rewriter::mk_fp(expr * arg1, expr * arg2, expr * arg3, expr_ref &
bu.is_numeral(arg3, r3, bvs3)) {
SASSERT(mpzm.is_one(r2.to_mpq().denominator()));
SASSERT(mpzm.is_one(r3.to_mpq().denominator()));
SASSERT(mpzm.is_int64(r3.to_mpq().numerator()));
scoped_mpf v(m_fm);
mpf_exp_t biased_exp = mpzm.get_int64(r2.to_mpq().numerator());
m_fm.set(v, bvs2, bvs3 + 1,

View file

@ -26,7 +26,6 @@
#pragma warning(disable:4101)
#endif
#include <assert.h>
#include <algorithm>
#include <stdio.h>
#include <fstream>

View file

@ -2024,7 +2024,7 @@ public:
}
default:
pfgoto(proof);
assert(0 && "translate_main: unsupported proof rule");
SASSERT(0 && "translate_main: unsupported proof rule");
throw unsupported();
}
}

View file

@ -11,7 +11,7 @@ Abstract:
Author:
Leonardo de Moura (leonardo) 2010-05-20.
Krystof Hoder 2010-05-20.
Revision History:
@ -302,14 +302,10 @@ namespace datalog {
}
pair_info & get_pair(app_pair key) const {
return *m_costs.find(key);
}
void remove_rule_from_pair(app_pair key, rule * r, unsigned original_len) {
std::cout << "remove: " << mk_pp(key.first, m) << " - " << mk_pp(key.second, m) << "\n";
pair_info * ptr = &get_pair(key);
if (ptr->remove_rule(r, original_len)) {
pair_info * ptr = 0;
if (m_costs.find(key, ptr) && ptr &&
ptr->remove_rule(r, original_len)) {
SASSERT(ptr->m_rules.empty());
m_costs.remove(key);
dealloc(ptr);
@ -364,7 +360,12 @@ namespace datalog {
void join_pair(app_pair pair_key) {
app * t1 = pair_key.first;
app * t2 = pair_key.second;
pair_info & inf = get_pair(pair_key);
pair_info* infp = 0;
if (!m_costs.find(pair_key, infp) || !infp) {
UNREACHABLE();
return;
}
pair_info & inf = *infp;
SASSERT(!inf.m_rules.empty());
var_idx_set & output_vars = inf.m_all_nonlocal_vars;
expr_ref_vector args(m);

View file

@ -33,7 +33,6 @@ Revision History:
#include"smt_solver.h"
extern bool g_display_statistics;
extern void display_config();
static clock_t g_start_time;
static smtlib::solver* g_solver = 0;
static cmd_context * g_cmd_context = 0;