mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 01:25:31 +00:00
merge with unstable
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
commit
9377779e58
54 changed files with 20581 additions and 20354 deletions
|
@ -1,20 +1,20 @@
|
|||
/*++
|
||||
Copyright (c) 2011 Microsoft Corporation
|
||||
Copyright (c) 2011 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
Module Name:
|
||||
|
||||
api_interp.cpp
|
||||
api_interp.cpp
|
||||
|
||||
Abstract:
|
||||
API for interpolation
|
||||
Abstract:
|
||||
API for interpolation
|
||||
|
||||
Author:
|
||||
Author:
|
||||
|
||||
Ken McMillan
|
||||
Ken McMillan
|
||||
|
||||
Revision History:
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
--*/
|
||||
#include<iostream>
|
||||
#include<sstream>
|
||||
#include<vector>
|
||||
|
@ -191,19 +191,19 @@ extern "C" {
|
|||
|
||||
|
||||
Z3_interpolation_options
|
||||
Z3_mk_interpolation_options(){
|
||||
Z3_mk_interpolation_options(){
|
||||
return (Z3_interpolation_options) new interpolation_options_struct;
|
||||
}
|
||||
|
||||
void
|
||||
Z3_del_interpolation_options(Z3_interpolation_options opts){
|
||||
Z3_del_interpolation_options(Z3_interpolation_options opts){
|
||||
delete opts;
|
||||
}
|
||||
|
||||
void
|
||||
Z3_set_interpolation_option(Z3_interpolation_options opts,
|
||||
Z3_string name,
|
||||
Z3_string value){
|
||||
Z3_set_interpolation_option(Z3_interpolation_options opts,
|
||||
Z3_string name,
|
||||
Z3_string value){
|
||||
opts->map[name] = value;
|
||||
}
|
||||
|
||||
|
@ -412,11 +412,11 @@ extern "C" {
|
|||
Z3_ast foo = Z3_mk_interpolant(ctx, and_vec(ctx, c));
|
||||
chs[parents[i]].push_back(foo);
|
||||
}
|
||||
{
|
||||
svector<Z3_ast> &c = chs[num - 1];
|
||||
c.push_back(cnsts[num - 1]);
|
||||
res = and_vec(ctx, c);
|
||||
}
|
||||
{
|
||||
svector<Z3_ast> &c = chs[num - 1];
|
||||
c.push_back(cnsts[num - 1]);
|
||||
res = and_vec(ctx, c);
|
||||
}
|
||||
}
|
||||
Z3_inc_ref(ctx, res);
|
||||
return res;
|
||||
|
@ -620,8 +620,8 @@ extern "C" {
|
|||
|
||||
for (unsigned j = 0; j < num - 1; j++)
|
||||
if (read_parents[j] == SHRT_MAX){
|
||||
read_error << "formula " << j + 1 << ": unreferenced";
|
||||
goto fail;
|
||||
read_error << "formula " << j + 1 << ": unreferenced";
|
||||
goto fail;
|
||||
}
|
||||
|
||||
*_num = num;
|
||||
|
@ -643,69 +643,69 @@ extern "C" {
|
|||
#define IZ3_ROOT SHRT_MAX
|
||||
|
||||
/** This function uses Z3 to determine satisfiability of a set of
|
||||
constraints. If UNSAT, an interpolant is returned, based on the
|
||||
refutation generated by Z3. If SAT, a model is returned.
|
||||
constraints. If UNSAT, an interpolant is returned, based on the
|
||||
refutation generated by Z3. If SAT, a model is returned.
|
||||
|
||||
If "parents" is non-null, computes a tree interpolant. The tree is
|
||||
defined by the array "parents". This array maps each formula in
|
||||
the tree to its parent, where formulas are indicated by their
|
||||
integer index in "cnsts". The parent of formula n must have index
|
||||
greater than n. The last formula is the root of the tree. Its
|
||||
parent entry should be the constant IZ3_ROOT.
|
||||
If "parents" is non-null, computes a tree interpolant. The tree is
|
||||
defined by the array "parents". This array maps each formula in
|
||||
the tree to its parent, where formulas are indicated by their
|
||||
integer index in "cnsts". The parent of formula n must have index
|
||||
greater than n. The last formula is the root of the tree. Its
|
||||
parent entry should be the constant IZ3_ROOT.
|
||||
|
||||
If "parents" is null, computes a sequence interpolant.
|
||||
If "parents" is null, computes a sequence interpolant.
|
||||
|
||||
\param ctx The Z3 context. Must be generated by iz3_mk_context
|
||||
\param num The number of constraints in the sequence
|
||||
\param cnsts Array of constraints (AST's in context ctx)
|
||||
\param parents The parents vector defining the tree structure
|
||||
\param options Interpolation options (may be NULL)
|
||||
\param interps Array to return interpolants (size at least num-1, may be NULL)
|
||||
\param model Returns a Z3 model if constraints SAT (may be NULL)
|
||||
\param labels Returns relevant labels if SAT (may be NULL)
|
||||
\param incremental
|
||||
\param ctx The Z3 context. Must be generated by iz3_mk_context
|
||||
\param num The number of constraints in the sequence
|
||||
\param cnsts Array of constraints (AST's in context ctx)
|
||||
\param parents The parents vector defining the tree structure
|
||||
\param options Interpolation options (may be NULL)
|
||||
\param interps Array to return interpolants (size at least num-1, may be NULL)
|
||||
\param model Returns a Z3 model if constraints SAT (may be NULL)
|
||||
\param labels Returns relevant labels if SAT (may be NULL)
|
||||
\param incremental
|
||||
|
||||
VERY IMPORTANT: All the Z3 formulas in cnsts must be in Z3
|
||||
context ctx. The model and interpolants returned are also
|
||||
in this context.
|
||||
VERY IMPORTANT: All the Z3 formulas in cnsts must be in Z3
|
||||
context ctx. The model and interpolants returned are also
|
||||
in this context.
|
||||
|
||||
The return code is as in Z3_check_assumptions, that is,
|
||||
The return code is as in Z3_check_assumptions, that is,
|
||||
|
||||
Z3_L_FALSE = constraints UNSAT (interpolants returned)
|
||||
Z3_L_TRUE = constraints SAT (model returned)
|
||||
Z3_L_UNDEF = Z3 produced no result, or interpolation not possible
|
||||
Z3_L_FALSE = constraints UNSAT (interpolants returned)
|
||||
Z3_L_TRUE = constraints SAT (model returned)
|
||||
Z3_L_UNDEF = Z3 produced no result, or interpolation not possible
|
||||
|
||||
Currently, this function supports integer and boolean variables,
|
||||
as well as arrays over these types, with linear arithmetic,
|
||||
uninterpreted functions and quantifiers over integers (that is
|
||||
AUFLIA). Interpolants are produced in AULIA. However, some
|
||||
uses of array operations may cause quantifiers to appear in the
|
||||
interpolants even when there are no quantifiers in the input formulas.
|
||||
Although quantifiers may appear in the input formulas, Z3 may give up in
|
||||
this case, returning Z3_L_UNDEF.
|
||||
Currently, this function supports integer and boolean variables,
|
||||
as well as arrays over these types, with linear arithmetic,
|
||||
uninterpreted functions and quantifiers over integers (that is
|
||||
AUFLIA). Interpolants are produced in AULIA. However, some
|
||||
uses of array operations may cause quantifiers to appear in the
|
||||
interpolants even when there are no quantifiers in the input formulas.
|
||||
Although quantifiers may appear in the input formulas, Z3 may give up in
|
||||
this case, returning Z3_L_UNDEF.
|
||||
|
||||
If "incremental" is true, cnsts must contain exactly the set of
|
||||
formulas that are currently asserted in the context. If false,
|
||||
there must be no formulas currently asserted in the context.
|
||||
Setting "incremental" to true makes it posisble to incrementally
|
||||
add and remove constraints from the context until the context
|
||||
becomes UNSAT, at which point an interpolant is computed. Caution
|
||||
must be used, however. Before popping the context, if you wish to
|
||||
keep the interolant formulas, you *must* preserve them by using
|
||||
Z3_persist_ast. Also, if you want to simplify the interpolant
|
||||
formulas using Z3_simplify, you must first pop all of the
|
||||
assertions in the context (or use a different context). Otherwise,
|
||||
the formulas will be simplified *relative* to these constraints,
|
||||
which is almost certainly not what you want.
|
||||
If "incremental" is true, cnsts must contain exactly the set of
|
||||
formulas that are currently asserted in the context. If false,
|
||||
there must be no formulas currently asserted in the context.
|
||||
Setting "incremental" to true makes it posisble to incrementally
|
||||
add and remove constraints from the context until the context
|
||||
becomes UNSAT, at which point an interpolant is computed. Caution
|
||||
must be used, however. Before popping the context, if you wish to
|
||||
keep the interolant formulas, you *must* preserve them by using
|
||||
Z3_persist_ast. Also, if you want to simplify the interpolant
|
||||
formulas using Z3_simplify, you must first pop all of the
|
||||
assertions in the context (or use a different context). Otherwise,
|
||||
the formulas will be simplified *relative* to these constraints,
|
||||
which is almost certainly not what you want.
|
||||
|
||||
|
||||
Current limitations on tree interpolants. In a tree interpolation
|
||||
problem, each constant (0-ary function symbol) must occur only
|
||||
along one path from root to leaf. Function symbols (of arity > 0)
|
||||
are considered to have global scope (i.e., may appear in any
|
||||
interpolant formula).
|
||||
Current limitations on tree interpolants. In a tree interpolation
|
||||
problem, each constant (0-ary function symbol) must occur only
|
||||
along one path from root to leaf. Function symbols (of arity > 0)
|
||||
are considered to have global scope (i.e., may appear in any
|
||||
interpolant formula).
|
||||
|
||||
def_API('Z3_interpolate', BOOL, (_in(CONTEXT), _in(UINT), _in_array(1, AST), _in_array(1, UINT), _in(PARAMS), _out_array(1, AST), _out(MODEL), _out(LITERALS), _in(UINT), _in(UINT), _in_array(9, AST)))
|
||||
def_API('Z3_interpolate', BOOL, (_in(CONTEXT), _in(UINT), _in_array(1, AST), _in_array(1, UINT), _in(PARAMS), _out_array(1, AST), _out(MODEL), _out(LITERALS), _in(UINT), _in(UINT), _in_array(9, AST)))
|
||||
*/
|
||||
|
||||
Z3_lbool Z3_API Z3_interpolate(__in Z3_context ctx,
|
||||
|
|
|
@ -2559,7 +2559,7 @@ namespace Microsoft.Z3
|
|||
/// Create a bit-vector numeral.
|
||||
/// </summary>
|
||||
/// <param name="v">value of the numeral.</param>
|
||||
/// /// <param name="size">the size of the bit-vector</param>
|
||||
/// <param name="size">the size of the bit-vector</param>
|
||||
public BitVecNum MkBV(long v, uint size)
|
||||
{
|
||||
Contract.Ensures(Contract.Result<BitVecNum>() != null);
|
||||
|
|
|
@ -3212,7 +3212,7 @@ public class Context extends IDisposable
|
|||
* @param rm rounding mode term
|
||||
* @param t1 floating-point term
|
||||
* @param t2 floating-point term
|
||||
* @param t3">floating-point term
|
||||
* @param t3 floating-point term
|
||||
* Remarks:
|
||||
* The result is round((t1 * t2) + t3)
|
||||
* @throws Z3Exception
|
||||
|
@ -3247,7 +3247,7 @@ public class Context extends IDisposable
|
|||
/**
|
||||
* Floating-point roundToIntegral. Rounds a floating-point number to
|
||||
* the closest integer, again represented as a floating-point number.
|
||||
* @param rm">term of RoundingMode sort
|
||||
* @param rm term of RoundingMode sort
|
||||
* @param t floating-point term
|
||||
* @throws Z3Exception
|
||||
**/
|
||||
|
@ -3425,7 +3425,7 @@ public class Context extends IDisposable
|
|||
|
||||
/**
|
||||
* Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
|
||||
* @param bv">bit-vector value (of size m).
|
||||
* @param bv bit-vector value (of size m).
|
||||
* @param s FloatingPoint sort (ebits+sbits == m)
|
||||
* Remarks:
|
||||
* Produces a term that represents the conversion of a bit-vector term bv to a
|
||||
|
|
|
@ -8580,29 +8580,83 @@ def fpToFPUnsigned(rm, x, s):
|
|||
return FPRef(Z3_mk_fpa_to_fp_unsigned(rm.ctx_ref(), rm.ast, x.ast, s.ast), rm.ctx)
|
||||
|
||||
def fpToSBV(rm, x, s):
|
||||
"""Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector."""
|
||||
"""Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
|
||||
|
||||
>>> x = FP('x', FPSort(8, 24))
|
||||
>>> y = fpToSBV(RTZ(), x, BitVecSort(32))
|
||||
>>> print is_fp(x)
|
||||
True
|
||||
>>> print is_bv(y)
|
||||
True
|
||||
>>> print is_fp(y)
|
||||
False
|
||||
>>> print is_bv(x)
|
||||
False
|
||||
"""
|
||||
if __debug__:
|
||||
_z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
|
||||
_z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
|
||||
_z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
|
||||
return FPRef(Z3_mk_fpa_to_sbv(rm.ctx_ref(), rm.ast, x.ast, s.size()), rm.ctx)
|
||||
return BitVecRef(Z3_mk_fpa_to_sbv(rm.ctx_ref(), rm.ast, x.ast, s.size()), rm.ctx)
|
||||
|
||||
def fpToUBV(rm, x, s):
|
||||
"""Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector."""
|
||||
"""Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
|
||||
|
||||
>>> x = FP('x', FPSort(8, 24))
|
||||
>>> y = fpToUBV(RTZ(), x, BitVecSort(32))
|
||||
>>> print is_fp(x)
|
||||
True
|
||||
>>> print is_bv(y)
|
||||
True
|
||||
>>> print is_fp(y)
|
||||
False
|
||||
>>> print is_bv(x)
|
||||
False
|
||||
"""
|
||||
if __debug__:
|
||||
_z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
|
||||
_z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
|
||||
_z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
|
||||
return FPRef(Z3_mk_fpa_to_ubv(rm.ctx_ref(), rm.ast, x.ast, s.size()), rm.ctx)
|
||||
return BitVecRef(Z3_mk_fpa_to_ubv(rm.ctx_ref(), rm.ast, x.ast, s.size()), rm.ctx)
|
||||
|
||||
def fpToReal(x):
|
||||
"""Create a Z3 floating-point conversion expression, from floating-point expression to real."""
|
||||
"""Create a Z3 floating-point conversion expression, from floating-point expression to real.
|
||||
|
||||
>>> x = FP('x', FPSort(8, 24))
|
||||
>>> y = fpToReal(x)
|
||||
>>> print is_fp(x)
|
||||
True
|
||||
>>> print is_real(y)
|
||||
True
|
||||
>>> print is_fp(y)
|
||||
False
|
||||
>>> print is_real(x)
|
||||
False
|
||||
"""
|
||||
if __debug__:
|
||||
_z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
|
||||
return FPRef(Z3_mk_fpa_to_real(x.ctx_ref(), x.ast), x.ctx)
|
||||
return ArithRef(Z3_mk_fpa_to_real(x.ctx_ref(), x.ast), x.ctx)
|
||||
|
||||
def fpToIEEEBV(x):
|
||||
"""Create a Z3 floating-point conversion expression, from floating-point expression to IEEE bit-vector."""
|
||||
"""\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
|
||||
|
||||
The size of the resulting bit-vector is automatically determined.
|
||||
|
||||
Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
|
||||
knows only one NaN and it will always produce the same bit-vector represenatation of
|
||||
that NaN.
|
||||
|
||||
>>> x = FP('x', FPSort(8, 24))
|
||||
>>> y = fpToIEEEBV(x)
|
||||
>>> print is_fp(x)
|
||||
True
|
||||
>>> print is_bv(y)
|
||||
True
|
||||
>>> print is_fp(y)
|
||||
False
|
||||
>>> print is_bv(x)
|
||||
False
|
||||
"""
|
||||
if __debug__:
|
||||
_z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
|
||||
return FPRef(Z3_mk_fpa_to_ieee_bv(x.ctx_ref(), x.ast), x.ctx)
|
||||
return BitVecRef(Z3_mk_fpa_to_ieee_bv(x.ctx_ref(), x.ast), x.ctx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue