/** Copyright (c) 2012-2014 Microsoft Corporation Module Name: Context.java Abstract: Author: @author Christoph Wintersteiger (cwinter) 2012-03-15 Notes: **/ package com.microsoft.z3; import java.util.Map; import com.microsoft.z3.enumerations.Z3_ast_print_mode; /** * The main interaction with Z3 happens via the Context. **/ public class Context extends IDisposable { /** * Constructor. **/ public Context() throws Z3Exception { super(); m_ctx = Native.mkContextRc(0); initContext(); } /** * Constructor. * Remarks: * The following parameters can be set: * - proof (Boolean) Enable proof generation * - debug_ref_count (Boolean) Enable debug support for Z3_ast reference counting * - trace (Boolean) Tracing support for VCC * - trace_file_name (String) Trace out file for VCC traces * - timeout (unsigned) default timeout (in milliseconds) used for solvers * - well_sorted_check type checker * - auto_config use heuristics to automatically select solver and configure it * - model model generation for solvers, this parameter can be overwritten when creating a solver * - model_validate validate models produced by solvers * - unsat_core unsat-core generation for solvers, this parameter can be overwritten when creating a solver * Note that in previous versions of Z3, this constructor was also used to set global and * module parameters. For this purpose we should now use {@code Global.setParameter} **/ public Context(Map settings) throws Z3Exception { super(); long cfg = Native.mkConfig(); for (Map.Entry kv : settings.entrySet()) Native.setParamValue(cfg, kv.getKey(), kv.getValue()); m_ctx = Native.mkContextRc(cfg); Native.delConfig(cfg); initContext(); } /** * Creates a new symbol using an integer. * Remarks: Not all integers can be passed to this function. * The legal range of unsigned integers is 0 to 2^30-1. **/ public IntSymbol mkSymbol(int i) throws Z3Exception { return new IntSymbol(this, i); } /** * Create a symbol using a string. **/ public StringSymbol mkSymbol(String name) throws Z3Exception { return new StringSymbol(this, name); } /** * Create an array of symbols. **/ Symbol[] mkSymbols(String[] names) throws Z3Exception { if (names == null) return null; Symbol[] result = new Symbol[names.length]; for (int i = 0; i < names.length; ++i) result[i] = mkSymbol(names[i]); return result; } private BoolSort m_boolSort = null; private IntSort m_intSort = null; private RealSort m_realSort = null; /** * Retrieves the Boolean sort of the context. **/ public BoolSort getBoolSort() throws Z3Exception { if (m_boolSort == null) m_boolSort = new BoolSort(this); return m_boolSort; } /** * Retrieves the Integer sort of the context. **/ public IntSort getIntSort() throws Z3Exception { if (m_intSort == null) m_intSort = new IntSort(this); return m_intSort; } /** * Retrieves the Real sort of the context. **/ public RealSort getRealSort() throws Z3Exception { if (m_realSort == null) m_realSort = new RealSort(this); return m_realSort; } /** * Create a new Boolean sort. **/ public BoolSort mkBoolSort() throws Z3Exception { return new BoolSort(this); } /** * Create a new uninterpreted sort. **/ public UninterpretedSort mkUninterpretedSort(Symbol s) throws Z3Exception { checkContextMatch(s); return new UninterpretedSort(this, s); } /** * Create a new uninterpreted sort. **/ public UninterpretedSort mkUninterpretedSort(String str) throws Z3Exception { return mkUninterpretedSort(mkSymbol(str)); } /** * Create a new integer sort. **/ public IntSort mkIntSort() throws Z3Exception { return new IntSort(this); } /** * Create a real sort. **/ public RealSort mkRealSort() throws Z3Exception { return new RealSort(this); } /** * Create a new bit-vector sort. **/ public BitVecSort mkBitVecSort(int size) throws Z3Exception { return new BitVecSort(this, Native.mkBvSort(nCtx(), size)); } /** * Create a new array sort. **/ public ArraySort mkArraySort(Sort domain, Sort range) throws Z3Exception { checkContextMatch(domain); checkContextMatch(range); return new ArraySort(this, domain, range); } /** * Create a new tuple sort. **/ public TupleSort mkTupleSort(Symbol name, Symbol[] fieldNames, Sort[] fieldSorts) throws Z3Exception { checkContextMatch(name); checkContextMatch(fieldNames); checkContextMatch(fieldSorts); return new TupleSort(this, name, (int) fieldNames.length, fieldNames, fieldSorts); } /** * Create a new enumeration sort. **/ public EnumSort mkEnumSort(Symbol name, Symbol... enumNames) throws Z3Exception { checkContextMatch(name); checkContextMatch(enumNames); return new EnumSort(this, name, enumNames); } /** * Create a new enumeration sort. **/ public EnumSort mkEnumSort(String name, String... enumNames) throws Z3Exception { return new EnumSort(this, mkSymbol(name), mkSymbols(enumNames)); } /** * Create a new list sort. **/ public ListSort mkListSort(Symbol name, Sort elemSort) throws Z3Exception { checkContextMatch(name); checkContextMatch(elemSort); return new ListSort(this, name, elemSort); } /** * Create a new list sort. **/ public ListSort mkListSort(String name, Sort elemSort) throws Z3Exception { checkContextMatch(elemSort); return new ListSort(this, mkSymbol(name), elemSort); } /** * Create a new finite domain sort. **/ public FiniteDomainSort mkFiniteDomainSort(Symbol name, long size) throws Z3Exception { checkContextMatch(name); return new FiniteDomainSort(this, name, size); } /** * Create a new finite domain sort. **/ public FiniteDomainSort mkFiniteDomainSort(String name, long size) throws Z3Exception { return new FiniteDomainSort(this, mkSymbol(name), size); } /** * Create a datatype constructor. * @param name constructor name * @param recognizer name of recognizer function. * @param fieldNames names of the constructor fields. * @param sorts field sorts, 0 if the field sort refers to a recursive sort. * @param sortRefs reference to datatype sort that is an argument to the * constructor; if the corresponding sort reference is 0, then the value in sort_refs should be * an index referring to one of the recursive datatypes that is * declared. **/ public Constructor mkConstructor(Symbol name, Symbol recognizer, Symbol[] fieldNames, Sort[] sorts, int[] sortRefs) throws Z3Exception { return new Constructor(this, name, recognizer, fieldNames, sorts, sortRefs); } /** * Create a datatype constructor. * @param name * @param recognizer * @param fieldNames * @param sorts * @param sortRefs * * @return **/ public Constructor mkConstructor(String name, String recognizer, String[] fieldNames, Sort[] sorts, int[] sortRefs) throws Z3Exception { return new Constructor(this, mkSymbol(name), mkSymbol(recognizer), mkSymbols(fieldNames), sorts, sortRefs); } /** * Create a new datatype sort. **/ public DatatypeSort mkDatatypeSort(Symbol name, Constructor[] constructors) throws Z3Exception { checkContextMatch(name); checkContextMatch(constructors); return new DatatypeSort(this, name, constructors); } /** * Create a new datatype sort. **/ public DatatypeSort mkDatatypeSort(String name, Constructor[] constructors) throws Z3Exception { checkContextMatch(constructors); return new DatatypeSort(this, mkSymbol(name), constructors); } /** * Create mutually recursive datatypes. * @param names names of datatype sorts * @param c list of constructors, one list per sort. **/ public DatatypeSort[] mkDatatypeSorts(Symbol[] names, Constructor[][] c) throws Z3Exception { checkContextMatch(names); int n = (int) names.length; ConstructorList[] cla = new ConstructorList[n]; long[] n_constr = new long[n]; for (int i = 0; i < n; i++) { Constructor[] constructor = c[i]; checkContextMatch(constructor); cla[i] = new ConstructorList(this, constructor); n_constr[i] = cla[i].getNativeObject(); } long[] n_res = new long[n]; Native.mkDatatypes(nCtx(), n, Symbol.arrayToNative(names), n_res, n_constr); DatatypeSort[] res = new DatatypeSort[n]; for (int i = 0; i < n; i++) res[i] = new DatatypeSort(this, n_res[i]); return res; } /** * Create mutually recursive data-types. * @param names * @param c * * @return **/ public DatatypeSort[] mkDatatypeSorts(String[] names, Constructor[][] c) throws Z3Exception { return mkDatatypeSorts(mkSymbols(names), c); } /** * Creates a new function declaration. **/ public FuncDecl mkFuncDecl(Symbol name, Sort[] domain, Sort range) throws Z3Exception { checkContextMatch(name); checkContextMatch(domain); checkContextMatch(range); return new FuncDecl(this, name, domain, range); } /** * Creates a new function declaration. **/ public FuncDecl mkFuncDecl(Symbol name, Sort domain, Sort range) throws Z3Exception { checkContextMatch(name); checkContextMatch(domain); checkContextMatch(range); Sort[] q = new Sort[] { domain }; return new FuncDecl(this, name, q, range); } /** * Creates a new function declaration. **/ public FuncDecl mkFuncDecl(String name, Sort[] domain, Sort range) throws Z3Exception { checkContextMatch(domain); checkContextMatch(range); return new FuncDecl(this, mkSymbol(name), domain, range); } /** * Creates a new function declaration. **/ public FuncDecl mkFuncDecl(String name, Sort domain, Sort range) throws Z3Exception { checkContextMatch(domain); checkContextMatch(range); Sort[] q = new Sort[] { domain }; return new FuncDecl(this, mkSymbol(name), q, range); } /** * Creates a fresh function declaration with a name prefixed with * {@code prefix}. * @see mkFuncDecl(String,Sort,Sort) * @see mkFuncDecl(String,Sort[],Sort) **/ public FuncDecl mkFreshFuncDecl(String prefix, Sort[] domain, Sort range) throws Z3Exception { checkContextMatch(domain); checkContextMatch(range); return new FuncDecl(this, prefix, domain, range); } /** * Creates a new constant function declaration. **/ public FuncDecl mkConstDecl(Symbol name, Sort range) throws Z3Exception { checkContextMatch(name); checkContextMatch(range); return new FuncDecl(this, name, null, range); } /** * Creates a new constant function declaration. **/ public FuncDecl mkConstDecl(String name, Sort range) throws Z3Exception { checkContextMatch(range); return new FuncDecl(this, mkSymbol(name), null, range); } /** * Creates a fresh constant function declaration with a name prefixed with * {@code prefix"}. * @see mkFuncDecl(String,Sort,Sort) * @see mkFuncDecl(String,Sort[],Sort) **/ public FuncDecl mkFreshConstDecl(String prefix, Sort range) throws Z3Exception { checkContextMatch(range); return new FuncDecl(this, prefix, null, range); } /** * Creates a new bound variable. * @param index The de-Bruijn index of the variable * @param ty The sort of the variable **/ public Expr mkBound(int index, Sort ty) throws Z3Exception { return Expr.create(this, Native.mkBound(nCtx(), index, ty.getNativeObject())); } /** * Create a quantifier pattern. **/ public Pattern mkPattern(Expr... terms) throws Z3Exception { if (terms.length == 0) throw new Z3Exception("Cannot create a pattern from zero terms"); long[] termsNative = AST.arrayToNative(terms); return new Pattern(this, Native.mkPattern(nCtx(), (int) terms.length, termsNative)); } /** * Creates a new Constant of sort {@code range} and named * {@code name}. **/ public Expr mkConst(Symbol name, Sort range) throws Z3Exception { checkContextMatch(name); checkContextMatch(range); return Expr.create( this, Native.mkConst(nCtx(), name.getNativeObject(), range.getNativeObject())); } /** * Creates a new Constant of sort {@code range} and named * {@code name}. **/ public Expr mkConst(String name, Sort range) throws Z3Exception { return mkConst(mkSymbol(name), range); } /** * Creates a fresh Constant of sort {@code range} and a name * prefixed with {@code prefix}. **/ public Expr mkFreshConst(String prefix, Sort range) throws Z3Exception { checkContextMatch(range); return Expr.create(this, Native.mkFreshConst(nCtx(), prefix, range.getNativeObject())); } /** * Creates a fresh constant from the FuncDecl {@code f}. * @param f A decl of a 0-arity function **/ public Expr mkConst(FuncDecl f) throws Z3Exception { return mkApp(f, (Expr[]) null); } /** * Create a Boolean constant. **/ public BoolExpr mkBoolConst(Symbol name) throws Z3Exception { return (BoolExpr) mkConst(name, getBoolSort()); } /** * Create a Boolean constant. **/ public BoolExpr mkBoolConst(String name) throws Z3Exception { return (BoolExpr) mkConst(mkSymbol(name), getBoolSort()); } /** * Creates an integer constant. **/ public IntExpr mkIntConst(Symbol name) throws Z3Exception { return (IntExpr) mkConst(name, getIntSort()); } /** * Creates an integer constant. **/ public IntExpr mkIntConst(String name) throws Z3Exception { return (IntExpr) mkConst(name, getIntSort()); } /** * Creates a real constant. **/ public RealExpr mkRealConst(Symbol name) throws Z3Exception { return (RealExpr) mkConst(name, getRealSort()); } /** * Creates a real constant. **/ public RealExpr mkRealConst(String name) throws Z3Exception { return (RealExpr) mkConst(name, getRealSort()); } /** * Creates a bit-vector constant. **/ public BitVecExpr mkBVConst(Symbol name, int size) throws Z3Exception { return (BitVecExpr) mkConst(name, mkBitVecSort(size)); } /** * Creates a bit-vector constant. **/ public BitVecExpr mkBVConst(String name, int size) throws Z3Exception { return (BitVecExpr) mkConst(name, mkBitVecSort(size)); } /** * Create a new function application. **/ public Expr mkApp(FuncDecl f, Expr... args) throws Z3Exception { checkContextMatch(f); checkContextMatch(args); return Expr.create(this, f, args); } /** * The true Term. **/ public BoolExpr mkTrue() throws Z3Exception { return new BoolExpr(this, Native.mkTrue(nCtx())); } /** * The false Term. **/ public BoolExpr mkFalse() throws Z3Exception { return new BoolExpr(this, Native.mkFalse(nCtx())); } /** * Creates a Boolean value. **/ public BoolExpr mkBool(boolean value) throws Z3Exception { return value ? mkTrue() : mkFalse(); } /** * Creates the equality {@code x"/> = is the weight, to every subgoal produced by to every subgoal produced by evaluates to true and floating-point term * Remarks: * The result is round((t1 * t2) + t3) * @throws Z3Exception **/ public FPExpr mkFPFMA(FPRMExpr rm, FPExpr t1, FPExpr t2, FPExpr t3) throws Z3Exception { return new FPExpr(this, Native.mkFpaFma(nCtx(), rm.getNativeObject(), t1.getNativeObject(), t2.getNativeObject(), t3.getNativeObject())); } /** * Floating-point square root * @param rm rounding mode term * @param t floating-point term * @throws Z3Exception **/ public FPExpr mkFPSqrt(FPRMExpr rm, FPExpr t) throws Z3Exception { return new FPExpr(this, Native.mkFpaSqrt(nCtx(), rm.getNativeObject(), t.getNativeObject())); } /** * Floating-point remainder * @param t1 floating-point term * @param t2 floating-point term * @throws Z3Exception **/ public FPExpr mkFPRem(FPExpr t1, FPExpr t2) throws Z3Exception { return new FPExpr(this, Native.mkFpaRem(nCtx(), t1.getNativeObject(), t2.getNativeObject())); } /** * 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 t floating-point term * @throws Z3Exception **/ public FPExpr mkFPRoundToIntegral(FPRMExpr rm, FPExpr t) throws Z3Exception { return new FPExpr(this, Native.mkFpaRoundToIntegral(nCtx(), rm.getNativeObject(), t.getNativeObject())); } /** * Minimum of floating-point numbers. * @param t1 floating-point term * @param t2 floating-point term * @throws Z3Exception **/ public FPExpr mkFPMin(FPExpr t1, FPExpr t2) throws Z3Exception { return new FPExpr(this, Native.mkFpaMin(nCtx(), t1.getNativeObject(), t2.getNativeObject())); } /** * Maximum of floating-point numbers. * @param t1 floating-point term * @param t2 floating-point term * @throws Z3Exception **/ public FPExpr mkFPMax(FPExpr t1, FPExpr t2) throws Z3Exception { return new FPExpr(this, Native.mkFpaMax(nCtx(), t1.getNativeObject(), t2.getNativeObject())); } /** * Floating-point less than or equal. * @param t1 floating-point term * @param t2 floating-point term * @throws Z3Exception **/ public BoolExpr mkFPLEq(FPExpr t1, FPExpr t2) throws Z3Exception { return new BoolExpr(this, Native.mkFpaLeq(nCtx(), t1.getNativeObject(), t2.getNativeObject())); } /** * Floating-point less than. * @param t1 floating-point term * @param t2 floating-point term * @throws Z3Exception **/ public BoolExpr mkFPLt(FPExpr t1, FPExpr t2) throws Z3Exception { return new BoolExpr(this, Native.mkFpaLt(nCtx(), t1.getNativeObject(), t2.getNativeObject())); } /** * Floating-point greater than or equal. * @param t1 floating-point term * @param t2 floating-point term * @throws Z3Exception **/ public BoolExpr mkFPGEq(FPExpr t1, FPExpr t2) throws Z3Exception { return new BoolExpr(this, Native.mkFpaGeq(nCtx(), t1.getNativeObject(), t2.getNativeObject())); } /** * Floating-point greater than. * @param t1 floating-point term * @param t2 floating-point term * @throws Z3Exception **/ public BoolExpr mkFPGt(FPExpr t1, FPExpr t2) throws Z3Exception { return new BoolExpr(this, Native.mkFpaGt(nCtx(), t1.getNativeObject(), t2.getNativeObject())); } /** * Floating-point equality. * @param t1 floating-point term * @param t2 floating-point term * Remarks: * Note that this is IEEE 754 equality (as opposed to standard =). * @throws Z3Exception **/ public BoolExpr mkFPEq(FPExpr t1, FPExpr t2) throws Z3Exception { return new BoolExpr(this, Native.mkFpaEq(nCtx(), t1.getNativeObject(), t2.getNativeObject())); } /** * Predicate indicating whether t is a normal floating-point number.\ * @param t floating-point term * @throws Z3Exception **/ public BoolExpr mkFPIsNormal(FPExpr t) throws Z3Exception { return new BoolExpr(this, Native.mkFpaIsNormal(nCtx(), t.getNativeObject())); } /** * Predicate indicating whether t is a subnormal floating-point number.\ * @param t floating-point term * @throws Z3Exception **/ public BoolExpr mkFPIsSubnormal(FPExpr t) throws Z3Exception { return new BoolExpr(this, Native.mkFpaIsSubnormal(nCtx(), t.getNativeObject())); } /** * Predicate indicating whether t is a floating-point number with zero value, i.e., +0 or -0. * @param t floating-point term * @throws Z3Exception **/ public BoolExpr mkFPIsZero(FPExpr t) throws Z3Exception { return new BoolExpr(this, Native.mkFpaIsZero(nCtx(), t.getNativeObject())); } /** * Predicate indicating whether t is a floating-point number representing +oo or -oo. * @param t floating-point term * @throws Z3Exception **/ public BoolExpr mkFPIsInfinite(FPExpr t) throws Z3Exception { return new BoolExpr(this, Native.mkFpaIsInfinite(nCtx(), t.getNativeObject())); } /** * Predicate indicating whether t is a NaN. * @param t floating-point term * @throws Z3Exception **/ public BoolExpr mkFPIsNaN(FPExpr t) throws Z3Exception { return new BoolExpr(this, Native.mkFpaIsNan(nCtx(), t.getNativeObject())); } /** * Predicate indicating whether t is a negative floating-point number. * @param t floating-point term * @throws Z3Exception **/ public BoolExpr mkFPIsNegative(FPExpr t) throws Z3Exception { return new BoolExpr(this, Native.mkFpaIsNegative(nCtx(), t.getNativeObject())); } /** * Predicate indicating whether t is a positive floating-point number. * @param t floating-point term * @throws Z3Exception **/ public BoolExpr mkFPIsPositive(FPExpr t) throws Z3Exception { return new BoolExpr(this, Native.mkFpaIsPositive(nCtx(), t.getNativeObject())); } /** * Create an expression of FloatingPoint sort from three bit-vector expressions. * @param sgn bit-vector term (of size 1) representing the sign. * @param sig bit-vector term representing the significand. * @param exp bit-vector term representing the exponent. * Remarks: * This is the operator named `fp' in the SMT FP theory definition. * Note that sgn is required to be a bit-vector of size 1. Significand and exponent * are required to be greater than 1 and 2 respectively. The FloatingPoint sort * of the resulting expression is automatically determined from the bit-vector sizes * of the arguments. * @throws Z3Exception **/ public FPExpr mkFP(BitVecExpr sgn, BitVecExpr sig, BitVecExpr exp) throws Z3Exception { return new FPExpr(this, Native.mkFpaFp(nCtx(), sgn.getNativeObject(), sig.getNativeObject(), exp.getNativeObject())); } /** * Conversion of a single IEEE 754-2008 bit-vector into a floating-point number. * @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 * floating-point term of sort s. The bit-vector size of bv (m) must be equal * to ebits+sbits of s. The format of the bit-vector is as defined by the * IEEE 754-2008 interchange format. * @throws Z3Exception **/ public FPExpr mkFPToFP(BitVecExpr bv, FPSort s) throws Z3Exception { return new FPExpr(this, Native.mkFpaToFpBv(nCtx(), bv.getNativeObject(), s.getNativeObject())); } /** * Conversion of a FloatingPoint term into another term of different FloatingPoint sort. * @param rm RoundingMode term. * @param t FloatingPoint term. * @param s FloatingPoint sort. * Remarks: * Produces a term that represents the conversion of a floating-point term t to a * floating-point term of sort s. If necessary, the result will be rounded according * to rounding mode rm. * @throws Z3Exception **/ public FPExpr mkFPToFP(FPRMExpr rm, FPExpr t, FPSort s) throws Z3Exception { return new FPExpr(this, Native.mkFpaToFpFloat(nCtx(), rm.getNativeObject(), t.getNativeObject(), s.getNativeObject())); } /** * Conversion of a term of real sort into a term of FloatingPoint sort. * @param rm RoundingMode term. * @param t term of Real sort. * @param s FloatingPoint sort. * Remarks: * Produces a term that represents the conversion of term t of real sort into a * floating-point term of sort s. If necessary, the result will be rounded according * to rounding mode rm. * @throws Z3Exception **/ public FPExpr mkFPToFP(FPRMExpr rm, RealExpr t, FPSort s) throws Z3Exception { return new FPExpr(this, Native.mkFpaToFpReal(nCtx(), rm.getNativeObject(), t.getNativeObject(), s.getNativeObject())); } /** * Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort. * @param rm RoundingMode term. * @param t term of bit-vector sort. * @param s FloatingPoint sort. * @param signed flag indicating whether t is interpreted as signed or unsigned bit-vector. * Remarks: * Produces a term that represents the conversion of the bit-vector term t into a * floating-point term of sort s. The bit-vector t is taken to be in signed * 2's complement format (when signed==true, otherwise unsigned). If necessary, the * result will be rounded according to rounding mode rm. * @throws Z3Exception **/ public FPExpr mkFPToFP(FPRMExpr rm, BitVecExpr t, FPSort s, boolean signed) throws Z3Exception { if (signed) return new FPExpr(this, Native.mkFpaToFpSigned(nCtx(), rm.getNativeObject(), t.getNativeObject(), s.getNativeObject())); else return new FPExpr(this, Native.mkFpaToFpUnsigned(nCtx(), rm.getNativeObject(), t.getNativeObject(), s.getNativeObject())); } /** * Conversion of a floating-point number to another FloatingPoint sort s. * @param s FloatingPoint sort * @param rm floating-point rounding mode term * @param t floating-point term * Remarks: * Produces a term that represents the conversion of a floating-point term t to a different * FloatingPoint sort s. If necessary, rounding according to rm is applied. * @throws Z3Exception **/ public FPExpr mkFPToFP(FPSort s, FPRMExpr rm, FPExpr t) throws Z3Exception { return new FPExpr(this, Native.mkFpaToFpFloat(nCtx(), s.getNativeObject(), rm.getNativeObject(), t.getNativeObject())); } /** * Conversion of a floating-point term into a bit-vector. * @param rm RoundingMode term. * @param t FloatingPoint term * @param sz Size of the resulting bit-vector. * @param signed Indicates whether the result is a signed or unsigned bit-vector. * Remarks: * Produces a term that represents the conversion of the floating-poiunt term t into a * bit-vector term of size sz in 2's complement format (signed when signed==true). If necessary, * the result will be rounded according to rounding mode rm. * @throws Z3Exception **/ public BitVecExpr mkFPToBV(FPRMExpr rm, FPExpr t, int sz, boolean signed) throws Z3Exception { if (signed) return new BitVecExpr(this, Native.mkFpaToSbv(nCtx(), rm.getNativeObject(), t.getNativeObject(), sz)); else return new BitVecExpr(this, Native.mkFpaToUbv(nCtx(), rm.getNativeObject(), t.getNativeObject(), sz)); } /** * Conversion of a floating-point term into a real-numbered term. * @param t FloatingPoint term * Remarks: * Produces a term that represents the conversion of the floating-poiunt term t into a * real number. Note that this type of conversion will often result in non-linear * constraints over real terms. * @throws Z3Exception **/ public RealExpr mkFPToReal(FPExpr t) throws Z3Exception { return new RealExpr(this, Native.mkFpaToReal(nCtx(), t.getNativeObject())); } /** * Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format. * @param t FloatingPoint term. * Remarks: * 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. * @throws Z3Exception **/ public BitVecExpr mkFPToIEEEBV(FPExpr t) throws Z3Exception { return new BitVecExpr(this, Native.mkFpaToIeeeBv(nCtx(), t.getNativeObject())); } /** * Conversion of a real-sorted significand and an integer-sorted exponent into a term of FloatingPoint sort. * @param rm RoundingMode term. * @param exp Exponent term of Int sort. * @param sig Significand term of Real sort. * @param s FloatingPoint sort. * Remarks: * Produces a term that represents the conversion of sig * 2^exp into a * floating-point term of sort s. If necessary, the result will be rounded * according to rounding mode rm. * @throws Z3Exception **/ public BitVecExpr mkFPToFP(FPRMExpr rm, IntExpr exp, RealExpr sig, FPSort s) throws Z3Exception { return new BitVecExpr(this, Native.mkFpaToFpIntReal(nCtx(), rm.getNativeObject(), exp.getNativeObject(), sig.getNativeObject(), s.getNativeObject())); } /** * Wraps an AST. * Remarks: This function is used for transitions between * native and managed objects. Note that {@code nativeObject} * must be a native object obtained from Z3 (e.g., through * {@code UnwrapAST}) and that it must have a correct reference count. * @see Native#incRef * @see unwrapAST * @param nativeObject The native pointer to wrap. **/ public AST wrapAST(long nativeObject) throws Z3Exception { return AST.create(this, nativeObject); } /** * Unwraps an AST. * Remarks: This function is used for transitions between * native and managed objects. It returns the native pointer to the AST. * Note that AST objects are reference counted and unwrapping an AST * disables automatic reference counting, i.e., all references to the IntPtr * that is returned must be handled externally and through native calls (see * e.g., * @see Native#incRef * @see wrapAST * @param a The AST to unwrap. **/ public long unwrapAST(AST a) { return a.getNativeObject(); } /** * Return a string describing all available parameters to * {@code Expr.Simplify}. **/ public String SimplifyHelp() throws Z3Exception { return Native.simplifyGetHelp(nCtx()); } /** * Retrieves parameter descriptions for simplifier. **/ public ParamDescrs getSimplifyParameterDescriptions() throws Z3Exception { return new ParamDescrs(this, Native.simplifyGetParamDescrs(nCtx())); } /** * Enable/disable printing of warning messages to the console. * Remarks: Note * that this function is static and effects the behaviour of all contexts * globally. **/ public static void ToggleWarningMessages(boolean enabled) throws Z3Exception { Native.toggleWarningMessages((enabled) ? true : false); } /** * Update a mutable configuration parameter. * Remarks: The list of all * configuration parameters can be obtained using the Z3 executable: * {@code z3.exe -ini?} Only a few configuration parameters are mutable * once the context is created. An exception is thrown when trying to modify * an immutable parameter. **/ public void updateParamValue(String id, String value) throws Z3Exception { Native.updateParamValue(nCtx(), id, value); } long m_ctx = 0; long nCtx() { return m_ctx; } void initContext() throws Z3Exception { setPrintMode(Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT); Native.setInternalErrorHandler(nCtx()); } void checkContextMatch(Z3Object other) throws Z3Exception { if (this != other.getContext()) throw new Z3Exception("Context mismatch"); } void checkContextMatch(Z3Object[] arr) throws Z3Exception { if (arr != null) for (Z3Object a : arr) checkContextMatch(a); } private ASTDecRefQueue m_AST_DRQ = new ASTDecRefQueue(); private ASTMapDecRefQueue m_ASTMap_DRQ = new ASTMapDecRefQueue(10); private ASTVectorDecRefQueue m_ASTVector_DRQ = new ASTVectorDecRefQueue(10); private ApplyResultDecRefQueue m_ApplyResult_DRQ = new ApplyResultDecRefQueue(10); private FuncInterpEntryDecRefQueue m_FuncEntry_DRQ = new FuncInterpEntryDecRefQueue(10); private FuncInterpDecRefQueue m_FuncInterp_DRQ = new FuncInterpDecRefQueue(10); private GoalDecRefQueue m_Goal_DRQ = new GoalDecRefQueue(10); private ModelDecRefQueue m_Model_DRQ = new ModelDecRefQueue(10); private ParamsDecRefQueue m_Params_DRQ = new ParamsDecRefQueue(10); private ParamDescrsDecRefQueue m_ParamDescrs_DRQ = new ParamDescrsDecRefQueue(10); private ProbeDecRefQueue m_Probe_DRQ = new ProbeDecRefQueue(10); private SolverDecRefQueue m_Solver_DRQ = new SolverDecRefQueue(10); private StatisticsDecRefQueue m_Statistics_DRQ = new StatisticsDecRefQueue(10); private TacticDecRefQueue m_Tactic_DRQ = new TacticDecRefQueue(10); private FixedpointDecRefQueue m_Fixedpoint_DRQ = new FixedpointDecRefQueue(10); ASTDecRefQueue ast_DRQ() { return m_AST_DRQ; } ASTMapDecRefQueue astmap_DRQ() { return m_ASTMap_DRQ; } ASTVectorDecRefQueue astvector_DRQ() { return m_ASTVector_DRQ; } ApplyResultDecRefQueue applyResult_DRQ() { return m_ApplyResult_DRQ; } FuncInterpEntryDecRefQueue funcEntry_DRQ() { return m_FuncEntry_DRQ; } FuncInterpDecRefQueue funcInterp_DRQ() { return m_FuncInterp_DRQ; } GoalDecRefQueue goal_DRQ() { return m_Goal_DRQ; } ModelDecRefQueue model_DRQ() { return m_Model_DRQ; } ParamsDecRefQueue params_DRQ() { return m_Params_DRQ; } ParamDescrsDecRefQueue paramDescrs_DRQ() { return m_ParamDescrs_DRQ; } ProbeDecRefQueue probe_DRQ() { return m_Probe_DRQ; } SolverDecRefQueue solver_DRQ() { return m_Solver_DRQ; } StatisticsDecRefQueue statistics_DRQ() { return m_Statistics_DRQ; } TacticDecRefQueue tactic_DRQ() { return m_Tactic_DRQ; } FixedpointDecRefQueue fixedpoint_DRQ() { return m_Fixedpoint_DRQ; } protected long m_refCount = 0; /** * Finalizer. **/ protected void finalize() { dispose(); if (m_refCount == 0) { try { Native.delContext(m_ctx); } catch (Z3Exception e) { // OK. } m_ctx = 0; } /* else CMW: re-queue the finalizer? */ } /** * Disposes of the context. **/ public void dispose() { m_AST_DRQ.clear(this); m_ASTMap_DRQ.clear(this); m_ASTVector_DRQ.clear(this); m_ApplyResult_DRQ.clear(this); m_FuncEntry_DRQ.clear(this); m_FuncInterp_DRQ.clear(this); m_Goal_DRQ.clear(this); m_Model_DRQ.clear(this); m_Params_DRQ.clear(this); m_Probe_DRQ.clear(this); m_Solver_DRQ.clear(this); m_Statistics_DRQ.clear(this); m_Tactic_DRQ.clear(this); m_Fixedpoint_DRQ.clear(this); m_boolSort = null; m_intSort = null; m_realSort = null; } }