/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
Context.cs
Abstract:
Z3 Managed API: Context
Author:
Christoph Wintersteiger (cwinter) 2012-03-15
Notes:
--*/
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Diagnostics.Contracts;
using System.Linq;
namespace Microsoft.Z3
{
///
/// The main interaction with Z3 happens via the Context.
///
[ContractVerification(true)]
public class Context : IDisposable
{
#region Constructors
///
/// Constructor.
///
public Context()
: base()
{
lock (creation_lock)
{
m_ctx = Native.Z3_mk_context_rc(IntPtr.Zero);
InitContext();
}
}
///
/// Constructor.
///
///
/// 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
///
public Context(Dictionary settings)
: base()
{
Contract.Requires(settings != null);
lock (creation_lock)
{
IntPtr cfg = Native.Z3_mk_config();
foreach (KeyValuePair kv in settings)
Native.Z3_set_param_value(cfg, kv.Key, kv.Value);
m_ctx = Native.Z3_mk_context_rc(cfg);
Native.Z3_del_config(cfg);
InitContext();
}
}
#endregion
#region Symbols
///
/// Creates a new symbol using an integer.
///
///
/// 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)
{
Contract.Ensures(Contract.Result() != null);
return new IntSymbol(this, i);
}
///
/// Create a symbol using a string.
///
public StringSymbol MkSymbol(string name)
{
Contract.Ensures(Contract.Result() != null);
return new StringSymbol(this, name);
}
///
/// Create an array of symbols.
///
internal Symbol[] MkSymbols(string[] names)
{
Contract.Ensures(names == null || Contract.Result() != null);
Contract.Ensures(names != null || Contract.Result() == null);
Contract.Ensures(Contract.Result() == null || Contract.Result().Length == names.Length);
Contract.Ensures(Contract.Result() == null || Contract.ForAll(Contract.Result(), s => s != null));
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;
}
#endregion
#region Sorts
private BoolSort m_boolSort = null;
private IntSort m_intSort = null;
private RealSort m_realSort = null;
private SeqSort m_stringSort = null;
///
/// Retrieves the Boolean sort of the context.
///
public BoolSort BoolSort
{
get
{
Contract.Ensures(Contract.Result() != null);
if (m_boolSort == null) m_boolSort = new BoolSort(this); return m_boolSort;
}
}
///
/// Retrieves the Integer sort of the context.
///
public IntSort IntSort
{
get
{
Contract.Ensures(Contract.Result() != null);
if (m_intSort == null) m_intSort = new IntSort(this); return m_intSort;
}
}
///
/// Retrieves the Real sort of the context.
///
public RealSort RealSort
{
get
{
Contract.Ensures(Contract.Result() != null);
if (m_realSort == null) m_realSort = new RealSort(this); return m_realSort;
}
}
///
/// Retrieves the String sort of the context.
///
public SeqSort StringSort
{
get
{
Contract.Ensures(Contract.Result() != null);
if (m_stringSort == null) m_stringSort = new SeqSort(this, Native.Z3_mk_string_sort(nCtx));
return m_stringSort;
}
}
///
/// Create a new Boolean sort.
///
public BoolSort MkBoolSort()
{
Contract.Ensures(Contract.Result() != null);
return new BoolSort(this);
}
///
/// Create a new uninterpreted sort.
///
public UninterpretedSort MkUninterpretedSort(Symbol s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(s);
return new UninterpretedSort(this, s);
}
///
/// Create a new uninterpreted sort.
///
public UninterpretedSort MkUninterpretedSort(string str)
{
Contract.Ensures(Contract.Result() != null);
return MkUninterpretedSort(MkSymbol(str));
}
///
/// Create a new integer sort.
///
public IntSort MkIntSort()
{
Contract.Ensures(Contract.Result() != null);
return new IntSort(this);
}
///
/// Create a real sort.
///
public RealSort MkRealSort()
{
Contract.Ensures(Contract.Result() != null);
return new RealSort(this);
}
///
/// Create a new bit-vector sort.
///
public BitVecSort MkBitVecSort(uint size)
{
Contract.Ensures(Contract.Result() != null);
return new BitVecSort(this, Native.Z3_mk_bv_sort(nCtx, size));
}
///
/// Create a new sequence sort.
///
public SeqSort MkSeqSort(Sort s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result() != null);
return new SeqSort(this, Native.Z3_mk_seq_sort(nCtx, s.NativeObject));
}
///
/// Create a new regular expression sort.
///
public ReSort MkReSort(SeqSort s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result() != null);
return new ReSort(this, Native.Z3_mk_re_sort(nCtx, s.NativeObject));
}
///
/// Create a new array sort.
///
public ArraySort MkArraySort(Sort domain, Sort range)
{
Contract.Requires(domain != null);
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(domain);
CheckContextMatch(range);
return new ArraySort(this, domain, range);
}
///
/// Create a new n-ary array sort.
///
public ArraySort MkArraySort(Sort[] domain, Sort range)
{
Contract.Requires(domain != null);
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(domain);
CheckContextMatch(range);
return new ArraySort(this, domain, range);
}
///
/// Create a new tuple sort.
///
public TupleSort MkTupleSort(Symbol name, Symbol[] fieldNames, Sort[] fieldSorts)
{
Contract.Requires(name != null);
Contract.Requires(fieldNames != null);
Contract.Requires(Contract.ForAll(fieldNames, fn => fn != null));
Contract.Requires(fieldSorts == null || Contract.ForAll(fieldSorts, fs => fs != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(name);
CheckContextMatch(fieldNames);
CheckContextMatch(fieldSorts);
return new TupleSort(this, name, (uint)fieldNames.Length, fieldNames, fieldSorts);
}
///
/// Create a new enumeration sort.
///
public EnumSort MkEnumSort(Symbol name, params Symbol[] enumNames)
{
Contract.Requires(name != null);
Contract.Requires(enumNames != null);
Contract.Requires(Contract.ForAll(enumNames, f => f != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(name);
CheckContextMatch(enumNames);
return new EnumSort(this, name, enumNames);
}
///
/// Create a new enumeration sort.
///
public EnumSort MkEnumSort(string name, params string[] enumNames)
{
Contract.Requires(enumNames != null);
Contract.Ensures(Contract.Result() != null);
return new EnumSort(this, MkSymbol(name), MkSymbols(enumNames));
}
///
/// Create a new list sort.
///
public ListSort MkListSort(Symbol name, Sort elemSort)
{
Contract.Requires(name != null);
Contract.Requires(elemSort != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(name);
CheckContextMatch(elemSort);
return new ListSort(this, name, elemSort);
}
///
/// Create a new list sort.
///
public ListSort MkListSort(string name, Sort elemSort)
{
Contract.Requires(elemSort != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(elemSort);
return new ListSort(this, MkSymbol(name), elemSort);
}
///
/// Create a new finite domain sort.
/// The result is a sort
///
/// The name used to identify the sort
/// The size of the sort
public FiniteDomainSort MkFiniteDomainSort(Symbol name, ulong size)
{
Contract.Requires(name != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(name);
return new FiniteDomainSort(this, name, size);
}
///
/// Create a new finite domain sort.
/// The result is a sort
/// Elements of the sort are created using ,
/// and the elements range from 0 to size-1.
///
/// The name used to identify the sort
/// The size of the sort
public FiniteDomainSort MkFiniteDomainSort(string name, ulong size)
{
Contract.Ensures(Contract.Result() != null);
return new FiniteDomainSort(this, MkSymbol(name), size);
}
#region Datatypes
///
/// Create a datatype constructor.
///
/// constructor name
/// name of recognizer function.
/// names of the constructor fields.
/// field sorts, 0 if the field sort refers to a recursive sort.
/// 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 = null, Sort[] sorts = null, uint[] sortRefs = null)
{
Contract.Requires(name != null);
Contract.Requires(recognizer != null);
Contract.Ensures(Contract.Result() != null);
return new Constructor(this, name, recognizer, fieldNames, sorts, sortRefs);
}
///
/// Create a datatype constructor.
///
///
///
///
///
///
///
public Constructor MkConstructor(string name, string recognizer, string[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null)
{
Contract.Ensures(Contract.Result() != null);
return new Constructor(this, MkSymbol(name), MkSymbol(recognizer), MkSymbols(fieldNames), sorts, sortRefs);
}
///
/// Create a new datatype sort.
///
public DatatypeSort MkDatatypeSort(Symbol name, Constructor[] constructors)
{
Contract.Requires(name != null);
Contract.Requires(constructors != null);
Contract.Requires(Contract.ForAll(constructors, c => c != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(name);
CheckContextMatch(constructors);
return new DatatypeSort(this, name, constructors);
}
///
/// Create a new datatype sort.
///
public DatatypeSort MkDatatypeSort(string name, Constructor[] constructors)
{
Contract.Requires(constructors != null);
Contract.Requires(Contract.ForAll(constructors, c => c != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(constructors);
return new DatatypeSort(this, MkSymbol(name), constructors);
}
///
/// Create mutually recursive datatypes.
///
/// names of datatype sorts
/// list of constructors, one list per sort.
public DatatypeSort[] MkDatatypeSorts(Symbol[] names, Constructor[][] c)
{
Contract.Requires(names != null);
Contract.Requires(c != null);
Contract.Requires(names.Length == c.Length);
Contract.Requires(Contract.ForAll(0, c.Length, j => c[j] != null));
Contract.Requires(Contract.ForAll(names, name => name != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(names);
uint n = (uint)names.Length;
ConstructorList[] cla = new ConstructorList[n];
IntPtr[] n_constr = new IntPtr[n];
for (uint i = 0; i < n; i++)
{
Constructor[] constructor = c[i];
Contract.Assume(Contract.ForAll(constructor, arr => arr != null), "Clousot does not support yet quantified formula on multidimensional arrays");
CheckContextMatch(constructor);
cla[i] = new ConstructorList(this, constructor);
n_constr[i] = cla[i].NativeObject;
}
IntPtr[] n_res = new IntPtr[n];
Native.Z3_mk_datatypes(nCtx, n, Symbol.ArrayToNative(names), n_res, n_constr);
DatatypeSort[] res = new DatatypeSort[n];
for (uint i = 0; i < n; i++)
res[i] = new DatatypeSort(this, n_res[i]);
return res;
}
///
/// Create mutually recursive data-types.
///
///
///
///
public DatatypeSort[] MkDatatypeSorts(string[] names, Constructor[][] c)
{
Contract.Requires(names != null);
Contract.Requires(c != null);
Contract.Requires(names.Length == c.Length);
Contract.Requires(Contract.ForAll(0, c.Length, j => c[j] != null));
Contract.Requires(Contract.ForAll(names, name => name != null));
Contract.Ensures(Contract.Result() != null);
return MkDatatypeSorts(MkSymbols(names), c);
}
///
/// Update a datatype field at expression t with value v.
/// The function performs a record update at t. The field
/// that is passed in as argument is updated with value v,
/// the remainig fields of t are unchanged.
///
public Expr MkUpdateField(FuncDecl field, Expr t, Expr v)
{
return Expr.Create(this, Native.Z3_datatype_update_field(
nCtx, field.NativeObject,
t.NativeObject, v.NativeObject));
}
#endregion
#endregion
#region Function Declarations
///
/// Creates a new function declaration.
///
public FuncDecl MkFuncDecl(Symbol name, Sort[] domain, Sort range)
{
Contract.Requires(name != null);
Contract.Requires(range != null);
Contract.Requires(Contract.ForAll(domain, d => d != null));
Contract.Ensures(Contract.Result() != null);
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)
{
Contract.Requires(name != null);
Contract.Requires(domain != null);
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
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)
{
Contract.Requires(range != null);
Contract.Requires(Contract.ForAll(domain, d => d != null));
Contract.Ensures(Contract.Result() != null);
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)
{
Contract.Requires(range != null);
Contract.Requires(domain != null);
Contract.Ensures(Contract.Result() != null);
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 .
///
///
///
public FuncDecl MkFreshFuncDecl(string prefix, Sort[] domain, Sort range)
{
Contract.Requires(range != null);
Contract.Requires(Contract.ForAll(domain, d => d != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(domain);
CheckContextMatch(range);
return new FuncDecl(this, prefix, domain, range);
}
///
/// Creates a new constant function declaration.
///
public FuncDecl MkConstDecl(Symbol name, Sort range)
{
Contract.Requires(name != null);
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(name);
CheckContextMatch(range);
return new FuncDecl(this, name, null, range);
}
///
/// Creates a new constant function declaration.
///
public FuncDecl MkConstDecl(string name, Sort range)
{
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(range);
return new FuncDecl(this, MkSymbol(name), null, range);
}
///
/// Creates a fresh constant function declaration with a name prefixed with .
///
///
///
public FuncDecl MkFreshConstDecl(string prefix, Sort range)
{
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(range);
return new FuncDecl(this, prefix, null, range);
}
#endregion
#region Bound Variables
///
/// Creates a new bound variable.
///
/// The de-Bruijn index of the variable
/// The sort of the variable
public Expr MkBound(uint index, Sort ty)
{
Contract.Requires(ty != null);
Contract.Ensures(Contract.Result() != null);
return Expr.Create(this, Native.Z3_mk_bound(nCtx, index, ty.NativeObject));
}
#endregion
#region Quantifier Patterns
///
/// Create a quantifier pattern.
///
public Pattern MkPattern(params Expr[] terms)
{
Contract.Requires(terms != null);
if (terms.Length == 0)
throw new Z3Exception("Cannot create a pattern from zero terms");
Contract.Ensures(Contract.Result() != null);
Contract.EndContractBlock();
IntPtr[] termsNative = AST.ArrayToNative(terms);
return new Pattern(this, Native.Z3_mk_pattern(nCtx, (uint)terms.Length, termsNative));
}
#endregion
#region Constants
///
/// Creates a new Constant of sort and named .
///
public Expr MkConst(Symbol name, Sort range)
{
Contract.Requires(name != null);
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(name);
CheckContextMatch(range);
return Expr.Create(this, Native.Z3_mk_const(nCtx, name.NativeObject, range.NativeObject));
}
///
/// Creates a new Constant of sort and named .
///
public Expr MkConst(string name, Sort range)
{
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
return MkConst(MkSymbol(name), range);
}
///
/// Creates a fresh Constant of sort and a
/// name prefixed with .
///
public Expr MkFreshConst(string prefix, Sort range)
{
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(range);
return Expr.Create(this, Native.Z3_mk_fresh_const(nCtx, prefix, range.NativeObject));
}
///
/// Creates a fresh constant from the FuncDecl .
///
/// A decl of a 0-arity function
public Expr MkConst(FuncDecl f)
{
Contract.Requires(f != null);
Contract.Ensures(Contract.Result() != null);
return MkApp(f);
}
///
/// Create a Boolean constant.
///
public BoolExpr MkBoolConst(Symbol name)
{
Contract.Requires(name != null);
Contract.Ensures(Contract.Result() != null);
return (BoolExpr)MkConst(name, BoolSort);
}
///
/// Create a Boolean constant.
///
public BoolExpr MkBoolConst(string name)
{
Contract.Ensures(Contract.Result() != null);
return (BoolExpr)MkConst(MkSymbol(name), BoolSort);
}
///
/// Creates an integer constant.
///
public IntExpr MkIntConst(Symbol name)
{
Contract.Requires(name != null);
Contract.Ensures(Contract.Result() != null);
return (IntExpr)MkConst(name, IntSort);
}
///
/// Creates an integer constant.
///
public IntExpr MkIntConst(string name)
{
Contract.Requires(name != null);
Contract.Ensures(Contract.Result() != null);
return (IntExpr)MkConst(name, IntSort);
}
///
/// Creates a real constant.
///
public RealExpr MkRealConst(Symbol name)
{
Contract.Requires(name != null);
Contract.Ensures(Contract.Result() != null);
return (RealExpr)MkConst(name, RealSort);
}
///
/// Creates a real constant.
///
public RealExpr MkRealConst(string name)
{
Contract.Ensures(Contract.Result() != null);
return (RealExpr)MkConst(name, RealSort);
}
///
/// Creates a bit-vector constant.
///
public BitVecExpr MkBVConst(Symbol name, uint size)
{
Contract.Requires(name != null);
Contract.Ensures(Contract.Result() != null);
return (BitVecExpr)MkConst(name, MkBitVecSort(size));
}
///
/// Creates a bit-vector constant.
///
public BitVecExpr MkBVConst(string name, uint size)
{
Contract.Ensures(Contract.Result() != null);
return (BitVecExpr)MkConst(name, MkBitVecSort(size));
}
#endregion
#region Terms
///
/// Create a new function application.
///
public Expr MkApp(FuncDecl f, params Expr[] args)
{
Contract.Requires(f != null);
Contract.Requires(args == null || Contract.ForAll(args, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(f);
CheckContextMatch(args);
return Expr.Create(this, f, args);
}
///
/// Create a new function application.
///
public Expr MkApp(FuncDecl f, IEnumerable args)
{
Contract.Requires(f != null);
Contract.Requires(args == null || Contract.ForAll(args, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(f);
CheckContextMatch(args);
return Expr.Create(this, f, args.ToArray());
}
#region Propositional
///
/// The true Term.
///
public BoolExpr MkTrue()
{
Contract.Ensures(Contract.Result() != null);
return new BoolExpr(this, Native.Z3_mk_true(nCtx));
}
///
/// The false Term.
///
public BoolExpr MkFalse()
{
Contract.Ensures(Contract.Result() != null);
return new BoolExpr(this, Native.Z3_mk_false(nCtx));
}
///
/// Creates a Boolean value.
///
public BoolExpr MkBool(bool value)
{
Contract.Ensures(Contract.Result() != null);
return value ? MkTrue() : MkFalse();
}
///
/// Creates the equality = .
///
public BoolExpr MkEq(Expr x, Expr y)
{
Contract.Requires(x != null);
Contract.Requires(y != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(x);
CheckContextMatch(y);
return new BoolExpr(this, Native.Z3_mk_eq(nCtx, x.NativeObject, y.NativeObject));
}
///
/// Creates a distinct term.
///
public BoolExpr MkDistinct(params Expr[] args)
{
Contract.Requires(args != null);
Contract.Requires(Contract.ForAll(args, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(args);
return new BoolExpr(this, Native.Z3_mk_distinct(nCtx, (uint)args.Length, AST.ArrayToNative(args)));
}
///
/// Mk an expression representing not(a).
///
public BoolExpr MkNot(BoolExpr a)
{
Contract.Requires(a != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(a);
return new BoolExpr(this, Native.Z3_mk_not(nCtx, a.NativeObject));
}
///
/// Create an expression representing an if-then-else: ite(t1, t2, t3).
///
/// An expression with Boolean sort
/// An expression
/// An expression with the same sort as
public Expr MkITE(BoolExpr t1, Expr t2, Expr t3)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Requires(t3 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
CheckContextMatch(t3);
return Expr.Create(this, Native.Z3_mk_ite(nCtx, t1.NativeObject, t2.NativeObject, t3.NativeObject));
}
///
/// Create an expression representing t1 iff t2.
///
public BoolExpr MkIff(BoolExpr t1, BoolExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_iff(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t1 -> t2.
///
public BoolExpr MkImplies(BoolExpr t1, BoolExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_implies(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t1 xor t2.
///
public BoolExpr MkXor(BoolExpr t1, BoolExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_xor(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t[0] and t[1] and ....
///
public BoolExpr MkAnd(params BoolExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BoolExpr(this, Native.Z3_mk_and(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
///
/// Create an expression representing t[0] and t[1] and ....
///
public BoolExpr MkAnd(IEnumerable t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BoolExpr(this, Native.Z3_mk_and(nCtx, (uint)t.Count(), AST.EnumToNative(t)));
}
///
/// Create an expression representing t[0] or t[1] or ....
///
public BoolExpr MkOr(params BoolExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BoolExpr(this, Native.Z3_mk_or(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
///
/// Create an expression representing t[0] or t[1] or ....
///
public BoolExpr MkOr(IEnumerable t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BoolExpr(this, Native.Z3_mk_or(nCtx, (uint)t.Count(), AST.EnumToNative(t)));
}
#endregion
#region Arithmetic
///
/// Create an expression representing t[0] + t[1] + ....
///
public ArithExpr MkAdd(params ArithExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_add(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
///
/// Create an expression representing t[0] + t[1] + ....
///
public ArithExpr MkAdd(IEnumerable t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_add(nCtx, (uint)t.Count(), AST.EnumToNative(t)));
}
///
/// Create an expression representing t[0] * t[1] * ....
///
public ArithExpr MkMul(params ArithExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_mul(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
///
/// Create an expression representing t[0] * t[1] * ....
///
public ArithExpr MkMul(IEnumerable t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_mul(nCtx, (uint)t.Count(), AST.EnumToNative(t)));
}
///
/// Create an expression representing t[0] - t[1] - ....
///
public ArithExpr MkSub(params ArithExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_sub(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
///
/// Create an expression representing -t.
///
public ArithExpr MkUnaryMinus(ArithExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_unary_minus(nCtx, t.NativeObject));
}
///
/// Create an expression representing t1 / t2.
///
public ArithExpr MkDiv(ArithExpr t1, ArithExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_div(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t1 mod t2.
///
/// The arguments must have int type.
public IntExpr MkMod(IntExpr t1, IntExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new IntExpr(this, Native.Z3_mk_mod(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t1 rem t2.
///
/// The arguments must have int type.
public IntExpr MkRem(IntExpr t1, IntExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new IntExpr(this, Native.Z3_mk_rem(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t1 ^ t2.
///
public ArithExpr MkPower(ArithExpr t1, ArithExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_power(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t1 < t2
///
public BoolExpr MkLt(ArithExpr t1, ArithExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_lt(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t1 <= t2
///
public BoolExpr MkLe(ArithExpr t1, ArithExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_le(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t1 > t2
///
public BoolExpr MkGt(ArithExpr t1, ArithExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_gt(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an expression representing t1 >= t2
///
public BoolExpr MkGe(ArithExpr t1, ArithExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_ge(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Coerce an integer to a real.
///
///
/// There is also a converse operation exposed. It follows the semantics prescribed by the SMT-LIB standard.
///
/// You can take the floor of a real by creating an auxiliary integer Term k and
/// and asserting MakeInt2Real(k) <= t1 < MkInt2Real(k)+1.
/// The argument must be of integer sort.
///
public RealExpr MkInt2Real(IntExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new RealExpr(this, Native.Z3_mk_int2real(nCtx, t.NativeObject));
}
///
/// Coerce a real to an integer.
///
///
/// The semantics of this function follows the SMT-LIB standard for the function to_int.
/// The argument must be of real sort.
///
public IntExpr MkReal2Int(RealExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new IntExpr(this, Native.Z3_mk_real2int(nCtx, t.NativeObject));
}
///
/// Creates an expression that checks whether a real number is an integer.
///
public BoolExpr MkIsInteger(RealExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BoolExpr(this, Native.Z3_mk_is_int(nCtx, t.NativeObject));
}
#endregion
#region Bit-vectors
///
/// Bitwise negation.
///
/// The argument must have a bit-vector sort.
public BitVecExpr MkBVNot(BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_bvnot(nCtx, t.NativeObject));
}
///
/// Take conjunction of bits in a vector, return vector of length 1.
///
/// The argument must have a bit-vector sort.
public BitVecExpr MkBVRedAND(BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_bvredand(nCtx, t.NativeObject));
}
///
/// Take disjunction of bits in a vector, return vector of length 1.
///
/// The argument must have a bit-vector sort.
public BitVecExpr MkBVRedOR(BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_bvredor(nCtx, t.NativeObject));
}
///
/// Bitwise conjunction.
///
/// The arguments must have a bit-vector sort.
public BitVecExpr MkBVAND(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvand(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Bitwise disjunction.
///
/// The arguments must have a bit-vector sort.
public BitVecExpr MkBVOR(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvor(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Bitwise XOR.
///
/// The arguments must have a bit-vector sort.
public BitVecExpr MkBVXOR(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvxor(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Bitwise NAND.
///
/// The arguments must have a bit-vector sort.
public BitVecExpr MkBVNAND(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvnand(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Bitwise NOR.
///
/// The arguments must have a bit-vector sort.
public BitVecExpr MkBVNOR(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvnor(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Bitwise XNOR.
///
/// The arguments must have a bit-vector sort.
public BitVecExpr MkBVXNOR(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvxnor(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Standard two's complement unary minus.
///
/// The arguments must have a bit-vector sort.
public BitVecExpr MkBVNeg(BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_bvneg(nCtx, t.NativeObject));
}
///
/// Two's complement addition.
///
/// The arguments must have the same bit-vector sort.
public BitVecExpr MkBVAdd(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvadd(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Two's complement subtraction.
///
/// The arguments must have the same bit-vector sort.
public BitVecExpr MkBVSub(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvsub(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Two's complement multiplication.
///
/// The arguments must have the same bit-vector sort.
public BitVecExpr MkBVMul(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvmul(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Unsigned division.
///
///
/// It is defined as the floor of t1/t2 if \c t2 is
/// different from zero. If t2 is zero, then the result
/// is undefined.
/// The arguments must have the same bit-vector sort.
///
public BitVecExpr MkBVUDiv(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvudiv(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Signed division.
///
///
/// It is defined in the following way:
///
/// - The \c floor of t1/t2 if \c t2 is different from zero, and t1*t2 >= 0.
///
/// - The \c ceiling of t1/t2 if \c t2 is different from zero, and t1*t2 < 0.
///
/// If t2 is zero, then the result is undefined.
/// The arguments must have the same bit-vector sort.
///
public BitVecExpr MkBVSDiv(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvsdiv(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Unsigned remainder.
///
///
/// It is defined as t1 - (t1 /u t2) * t2, where /u represents unsigned division.
/// If t2 is zero, then the result is undefined.
/// The arguments must have the same bit-vector sort.
///
public BitVecExpr MkBVURem(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvurem(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Signed remainder.
///
///
/// It is defined as t1 - (t1 /s t2) * t2, where /s represents signed division.
/// The most significant bit (sign) of the result is equal to the most significant bit of \c t1.
///
/// If t2 is zero, then the result is undefined.
/// The arguments must have the same bit-vector sort.
///
public BitVecExpr MkBVSRem(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvsrem(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Two's complement signed remainder (sign follows divisor).
///
///
/// If t2 is zero, then the result is undefined.
/// The arguments must have the same bit-vector sort.
///
public BitVecExpr MkBVSMod(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvsmod(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Unsigned less-than
///
///
/// The arguments must have the same bit-vector sort.
///
public BoolExpr MkBVULT(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvult(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Two's complement signed less-than
///
///
/// The arguments must have the same bit-vector sort.
///
public BoolExpr MkBVSLT(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvslt(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Unsigned less-than or equal to.
///
///
/// The arguments must have the same bit-vector sort.
///
public BoolExpr MkBVULE(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvule(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Two's complement signed less-than or equal to.
///
///
/// The arguments must have the same bit-vector sort.
///
public BoolExpr MkBVSLE(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvsle(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Unsigned greater than or equal to.
///
///
/// The arguments must have the same bit-vector sort.
///
public BoolExpr MkBVUGE(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvuge(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Two's complement signed greater than or equal to.
///
///
/// The arguments must have the same bit-vector sort.
///
public BoolExpr MkBVSGE(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvsge(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Unsigned greater-than.
///
///
/// The arguments must have the same bit-vector sort.
///
public BoolExpr MkBVUGT(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvugt(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Two's complement signed greater-than.
///
///
/// The arguments must have the same bit-vector sort.
///
public BoolExpr MkBVSGT(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvsgt(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Bit-vector concatenation.
///
///
/// The arguments must have a bit-vector sort.
///
///
/// The result is a bit-vector of size n1+n2, where n1 (n2)
/// is the size of t1 (t2).
///
public BitVecExpr MkConcat(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_concat(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Bit-vector extraction.
///
///
/// Extract the bits down to from a bitvector of
/// size m to yield a new bitvector of size n, where
/// n = high - low + 1.
/// The argument must have a bit-vector sort.
///
public BitVecExpr MkExtract(uint high, uint low, BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_extract(nCtx, high, low, t.NativeObject));
}
///
/// Bit-vector sign extension.
///
///
/// Sign-extends the given bit-vector to the (signed) equivalent bitvector of
/// size m+i, where \c m is the size of the given bit-vector.
/// The argument must have a bit-vector sort.
///
public BitVecExpr MkSignExt(uint i, BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_sign_ext(nCtx, i, t.NativeObject));
}
///
/// Bit-vector zero extension.
///
///
/// Extend the given bit-vector with zeros to the (unsigned) equivalent
/// bitvector of size m+i, where \c m is the size of the
/// given bit-vector.
/// The argument must have a bit-vector sort.
///
public BitVecExpr MkZeroExt(uint i, BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_zero_ext(nCtx, i, t.NativeObject));
}
///
/// Bit-vector repetition.
///
///
/// The argument must have a bit-vector sort.
///
public BitVecExpr MkRepeat(uint i, BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_repeat(nCtx, i, t.NativeObject));
}
///
/// Shift left.
///
///
/// It is equivalent to multiplication by 2^x where \c x is the value of .
///
/// NB. The semantics of shift operations varies between environments. This
/// definition does not necessarily capture directly the semantics of the
/// programming language or assembly architecture you are modeling.
///
/// The arguments must have a bit-vector sort.
///
public BitVecExpr MkBVSHL(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvshl(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Logical shift right
///
///
/// It is equivalent to unsigned division by 2^x where \c x is the value of .
///
/// NB. The semantics of shift operations varies between environments. This
/// definition does not necessarily capture directly the semantics of the
/// programming language or assembly architecture you are modeling.
///
/// The arguments must have a bit-vector sort.
///
public BitVecExpr MkBVLSHR(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvlshr(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Arithmetic shift right
///
///
/// It is like logical shift right except that the most significant
/// bits of the result always copy the most significant bit of the
/// second argument.
///
/// NB. The semantics of shift operations varies between environments. This
/// definition does not necessarily capture directly the semantics of the
/// programming language or assembly architecture you are modeling.
///
/// The arguments must have a bit-vector sort.
///
public BitVecExpr MkBVASHR(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_bvashr(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Rotate Left.
///
///
/// Rotate bits of \c t to the left \c i times.
/// The argument must have a bit-vector sort.
///
public BitVecExpr MkBVRotateLeft(uint i, BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_rotate_left(nCtx, i, t.NativeObject));
}
///
/// Rotate Right.
///
///
/// Rotate bits of \c t to the right \c i times.
/// The argument must have a bit-vector sort.
///
public BitVecExpr MkBVRotateRight(uint i, BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_rotate_right(nCtx, i, t.NativeObject));
}
///
/// Rotate Left.
///
///
/// Rotate bits of to the left times.
/// The arguments must have the same bit-vector sort.
///
public BitVecExpr MkBVRotateLeft(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_ext_rotate_left(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Rotate Right.
///
///
/// Rotate bits of to the right times.
/// The arguments must have the same bit-vector sort.
///
public BitVecExpr MkBVRotateRight(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BitVecExpr(this, Native.Z3_mk_ext_rotate_right(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create an bit bit-vector from the integer argument .
///
///
/// NB. This function is essentially treated as uninterpreted.
/// So you cannot expect Z3 to precisely reflect the semantics of this function
/// when solving constraints with this function.
///
/// The argument must be of integer sort.
///
public BitVecExpr MkInt2BV(uint n, IntExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BitVecExpr(this, Native.Z3_mk_int2bv(nCtx, n, t.NativeObject));
}
///
/// Create an integer from the bit-vector argument .
///
///
/// If \c is_signed is false, then the bit-vector \c t1 is treated as unsigned.
/// So the result is non-negative and in the range [0..2^N-1], where
/// N are the number of bits in .
/// If \c is_signed is true, \c t1 is treated as a signed bit-vector.
///
/// NB. This function is essentially treated as uninterpreted.
/// So you cannot expect Z3 to precisely reflect the semantics of this function
/// when solving constraints with this function.
///
/// The argument must be of bit-vector sort.
///
public IntExpr MkBV2Int(BitVecExpr t, bool signed)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new IntExpr(this, Native.Z3_mk_bv2int(nCtx, t.NativeObject, (signed) ? 1 : 0));
}
///
/// Create a predicate that checks that the bit-wise addition does not overflow.
///
///
/// The arguments must be of bit-vector sort.
///
public BoolExpr MkBVAddNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvadd_no_overflow(nCtx, t1.NativeObject, t2.NativeObject, (isSigned) ? 1 : 0));
}
///
/// Create a predicate that checks that the bit-wise addition does not underflow.
///
///
/// The arguments must be of bit-vector sort.
///
public BoolExpr MkBVAddNoUnderflow(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvadd_no_underflow(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create a predicate that checks that the bit-wise subtraction does not overflow.
///
///
/// The arguments must be of bit-vector sort.
///
public BoolExpr MkBVSubNoOverflow(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvsub_no_overflow(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create a predicate that checks that the bit-wise subtraction does not underflow.
///
///
/// The arguments must be of bit-vector sort.
///
public BoolExpr MkBVSubNoUnderflow(BitVecExpr t1, BitVecExpr t2, bool isSigned)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvsub_no_underflow(nCtx, t1.NativeObject, t2.NativeObject, (isSigned) ? 1 : 0));
}
///
/// Create a predicate that checks that the bit-wise signed division does not overflow.
///
///
/// The arguments must be of bit-vector sort.
///
public BoolExpr MkBVSDivNoOverflow(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvsdiv_no_overflow(nCtx, t1.NativeObject, t2.NativeObject));
}
///
/// Create a predicate that checks that the bit-wise negation does not overflow.
///
///
/// The arguments must be of bit-vector sort.
///
public BoolExpr MkBVNegNoOverflow(BitVecExpr t)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new BoolExpr(this, Native.Z3_mk_bvneg_no_overflow(nCtx, t.NativeObject));
}
///
/// Create a predicate that checks that the bit-wise multiplication does not overflow.
///
///
/// The arguments must be of bit-vector sort.
///
public BoolExpr MkBVMulNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvmul_no_overflow(nCtx, t1.NativeObject, t2.NativeObject, (isSigned) ? 1 : 0));
}
///
/// Create a predicate that checks that the bit-wise multiplication does not underflow.
///
///
/// The arguments must be of bit-vector sort.
///
public BoolExpr MkBVMulNoUnderflow(BitVecExpr t1, BitVecExpr t2)
{
Contract.Requires(t1 != null);
Contract.Requires(t2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t1);
CheckContextMatch(t2);
return new BoolExpr(this, Native.Z3_mk_bvmul_no_underflow(nCtx, t1.NativeObject, t2.NativeObject));
}
#endregion
#region Arrays
///
/// Create an array constant.
///
public ArrayExpr MkArrayConst(Symbol name, Sort domain, Sort range)
{
Contract.Requires(name != null);
Contract.Requires(domain != null);
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
return (ArrayExpr)MkConst(name, MkArraySort(domain, range));
}
///
/// Create an array constant.
///
public ArrayExpr MkArrayConst(string name, Sort domain, Sort range)
{
Contract.Requires(domain != null);
Contract.Requires(range != null);
Contract.Ensures(Contract.Result() != null);
return (ArrayExpr)MkConst(MkSymbol(name), MkArraySort(domain, range));
}
///
/// Array read.
///
///
/// The argument a is the array and i is the index
/// of the array that gets read.
///
/// The node a must have an array sort [domain -> range],
/// and i must have the sort domain.
/// The sort of the result is range.
///
///
///
public Expr MkSelect(ArrayExpr a, Expr i)
{
Contract.Requires(a != null);
Contract.Requires(i != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(a);
CheckContextMatch(i);
return Expr.Create(this, Native.Z3_mk_select(nCtx, a.NativeObject, i.NativeObject));
}
///
/// Array read.
///
///
/// The argument a is the array and args are the indices
/// of the array that gets read.
///
/// The node a must have an array sort [domain1,..,domaink -> range],
/// and args must have the sort domain1,..,domaink.
/// The sort of the result is range.
///
///
///
public Expr MkSelect(ArrayExpr a, params Expr[] args)
{
Contract.Requires(a != null);
Contract.Requires(args != null && Contract.ForAll(args, n => n != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(a);
CheckContextMatch(args);
return Expr.Create(this, Native.Z3_mk_select_n(nCtx, a.NativeObject, AST.ArrayLength(args), AST.ArrayToNative(args)));
}
///
/// Array update.
///
///
/// The node a must have an array sort [domain -> range],
/// i must have sort domain,
/// v must have sort range. The sort of the result is [domain -> range].
/// The semantics of this function is given by the theory of arrays described in the SMT-LIB
/// standard. See http://smtlib.org for more details.
/// The result of this function is an array that is equal to a
/// (with respect to select)
/// on all indices except for i, where it maps to v
/// (and the select of a with
/// respect to i may be a different value).
///
///
///
///
public ArrayExpr MkStore(ArrayExpr a, Expr i, Expr v)
{
Contract.Requires(a != null);
Contract.Requires(i != null);
Contract.Requires(v != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(a);
CheckContextMatch(i);
CheckContextMatch(v);
return new ArrayExpr(this, Native.Z3_mk_store(nCtx, a.NativeObject, i.NativeObject, v.NativeObject));
}
///
/// Array update.
///
///
/// The node a must have an array sort [domain1,..,domaink -> range],
/// args must have sort domain1,..,domaink,
/// v must have sort range. The sort of the result is [domain -> range].
/// The semantics of this function is given by the theory of arrays described in the SMT-LIB
/// standard. See http://smtlib.org for more details.
/// The result of this function is an array that is equal to a
/// (with respect to select)
/// on all indices except for args, where it maps to v
/// (and the select of a with
/// respect to args may be a different value).
///
///
///
///
public ArrayExpr MkStore(ArrayExpr a, Expr[] args, Expr v)
{
Contract.Requires(a != null);
Contract.Requires(args != null);
Contract.Requires(v != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(args);
CheckContextMatch(a);
CheckContextMatch(v);
return new ArrayExpr(this, Native.Z3_mk_store_n(nCtx, a.NativeObject, AST.ArrayLength(args), AST.ArrayToNative(args), v.NativeObject));
}
///
/// Create a constant array.
///
///
/// The resulting term is an array, such that a selecton an arbitrary index
/// produces the value v.
///
///
///
public ArrayExpr MkConstArray(Sort domain, Expr v)
{
Contract.Requires(domain != null);
Contract.Requires(v != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(domain);
CheckContextMatch(v);
return new ArrayExpr(this, Native.Z3_mk_const_array(nCtx, domain.NativeObject, v.NativeObject));
}
///
/// Maps f on the argument arrays.
///
///
/// Each element of args must be of an array sort [domain_i -> range_i].
/// The function declaration f must have type range_1 .. range_n -> range.
/// v must have sort range. The sort of the result is [domain_i -> range].
///
///
///
///
public ArrayExpr MkMap(FuncDecl f, params ArrayExpr[] args)
{
Contract.Requires(f != null);
Contract.Requires(args == null || Contract.ForAll(args, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(f);
CheckContextMatch(args);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_map(nCtx, f.NativeObject, AST.ArrayLength(args), AST.ArrayToNative(args)));
}
///
/// Access the array default value.
///
///
/// Produces the default range value, for arrays that can be represented as
/// finite maps with a default range value.
///
public Expr MkTermArray(ArrayExpr array)
{
Contract.Requires(array != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(array);
return Expr.Create(this, Native.Z3_mk_array_default(nCtx, array.NativeObject));
}
///
/// Create Extentionality index. Two arrays are equal if and only if they are equal on the index returned by MkArrayExt.
///
public Expr MkArrayExt(ArrayExpr arg1, ArrayExpr arg2)
{
Contract.Requires(arg1 != null);
Contract.Requires(arg2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(arg1);
CheckContextMatch(arg2);
return Expr.Create(this, Native.Z3_mk_array_ext(nCtx, arg1.NativeObject, arg2.NativeObject));
}
#endregion
#region Sets
///
/// Create a set type.
///
public SetSort MkSetSort(Sort ty)
{
Contract.Requires(ty != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(ty);
return new SetSort(this, ty);
}
///
/// Create an empty set.
///
public ArrayExpr MkEmptySet(Sort domain)
{
Contract.Requires(domain != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(domain);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_empty_set(nCtx, domain.NativeObject));
}
///
/// Create the full set.
///
public ArrayExpr MkFullSet(Sort domain)
{
Contract.Requires(domain != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(domain);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_full_set(nCtx, domain.NativeObject));
}
///
/// Add an element to the set.
///
public ArrayExpr MkSetAdd(ArrayExpr set, Expr element)
{
Contract.Requires(set != null);
Contract.Requires(element != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(set);
CheckContextMatch(element);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_set_add(nCtx, set.NativeObject, element.NativeObject));
}
///
/// Remove an element from a set.
///
public ArrayExpr MkSetDel(ArrayExpr set, Expr element)
{
Contract.Requires(set != null);
Contract.Requires(element != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(set);
CheckContextMatch(element);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_set_del(nCtx, set.NativeObject, element.NativeObject));
}
///
/// Take the union of a list of sets.
///
public ArrayExpr MkSetUnion(params ArrayExpr[] args)
{
Contract.Requires(args != null);
Contract.Requires(Contract.ForAll(args, a => a != null));
CheckContextMatch(args);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_set_union(nCtx, (uint)args.Length, AST.ArrayToNative(args)));
}
///
/// Take the intersection of a list of sets.
///
public ArrayExpr MkSetIntersection(params ArrayExpr[] args)
{
Contract.Requires(args != null);
Contract.Requires(Contract.ForAll(args, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(args);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_set_intersect(nCtx, (uint)args.Length, AST.ArrayToNative(args)));
}
///
/// Take the difference between two sets.
///
public ArrayExpr MkSetDifference(ArrayExpr arg1, ArrayExpr arg2)
{
Contract.Requires(arg1 != null);
Contract.Requires(arg2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(arg1);
CheckContextMatch(arg2);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_set_difference(nCtx, arg1.NativeObject, arg2.NativeObject));
}
///
/// Take the complement of a set.
///
public ArrayExpr MkSetComplement(ArrayExpr arg)
{
Contract.Requires(arg != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(arg);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_set_complement(nCtx, arg.NativeObject));
}
///
/// Check for set membership.
///
public BoolExpr MkSetMembership(Expr elem, ArrayExpr set)
{
Contract.Requires(elem != null);
Contract.Requires(set != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(elem);
CheckContextMatch(set);
return (BoolExpr) Expr.Create(this, Native.Z3_mk_set_member(nCtx, elem.NativeObject, set.NativeObject));
}
///
/// Check for subsetness of sets.
///
public BoolExpr MkSetSubset(ArrayExpr arg1, ArrayExpr arg2)
{
Contract.Requires(arg1 != null);
Contract.Requires(arg2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(arg1);
CheckContextMatch(arg2);
return (BoolExpr) Expr.Create(this, Native.Z3_mk_set_subset(nCtx, arg1.NativeObject, arg2.NativeObject));
}
#endregion
#region Sequence, string and regular expresions
///
/// Create the empty sequence.
///
public SeqExpr MkEmptySeq(Sort s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result() != null);
return new SeqExpr(this, Native.Z3_mk_seq_empty(nCtx, s.NativeObject));
}
///
/// Create the singleton sequence.
///
public SeqExpr MkUnit(Expr elem)
{
Contract.Requires(elem != null);
Contract.Ensures(Contract.Result() != null);
return new SeqExpr(this, Native.Z3_mk_seq_unit(nCtx, elem.NativeObject));
}
///
/// Create a string constant.
///
public SeqExpr MkString(string s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result() != null);
return new SeqExpr(this, Native.Z3_mk_string(nCtx, s));
}
///
/// Convert an integer expression to a string.
///
public SeqExpr IntToString(Expr e)
{
Contract.Requires(e != null);
Contract.Requires(e is ArithExpr);
Contract.Ensures(Contract.Result() != null);
return new SeqExpr(this, Native.Z3_mk_int_to_str(nCtx, e.NativeObject));
}
///
/// Convert an integer expression to a string.
///
public IntExpr StringToInt(Expr e)
{
Contract.Requires(e != null);
Contract.Requires(e is SeqExpr);
Contract.Ensures(Contract.Result() != null);
return new IntExpr(this, Native.Z3_mk_str_to_int(nCtx, e.NativeObject));
}
///
/// Concatenate sequences.
///
public SeqExpr MkConcat(params SeqExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new SeqExpr(this, Native.Z3_mk_seq_concat(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
///
/// Retrieve the length of a given sequence.
///
public IntExpr MkLength(SeqExpr s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result() != null);
return (IntExpr) Expr.Create(this, Native.Z3_mk_seq_length(nCtx, s.NativeObject));
}
///
/// Check for sequence prefix.
///
public BoolExpr MkPrefixOf(SeqExpr s1, SeqExpr s2)
{
Contract.Requires(s1 != null);
Contract.Requires(s2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(s1, s2);
return new BoolExpr(this, Native.Z3_mk_seq_prefix(nCtx, s1.NativeObject, s2.NativeObject));
}
///
/// Check for sequence suffix.
///
public BoolExpr MkSuffixOf(SeqExpr s1, SeqExpr s2)
{
Contract.Requires(s1 != null);
Contract.Requires(s2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(s1, s2);
return new BoolExpr(this, Native.Z3_mk_seq_suffix(nCtx, s1.NativeObject, s2.NativeObject));
}
///
/// Check for sequence containment of s2 in s1.
///
public BoolExpr MkContains(SeqExpr s1, SeqExpr s2)
{
Contract.Requires(s1 != null);
Contract.Requires(s2 != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(s1, s2);
return new BoolExpr(this, Native.Z3_mk_seq_contains(nCtx, s1.NativeObject, s2.NativeObject));
}
///
/// Retrieve sequence of length one at index.
///
public SeqExpr MkAt(SeqExpr s, IntExpr index)
{
Contract.Requires(s != null);
Contract.Requires(index != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(s, index);
return new SeqExpr(this, Native.Z3_mk_seq_at(nCtx, s.NativeObject, index.NativeObject));
}
///
/// Extract subsequence.
///
public SeqExpr MkExtract(SeqExpr s, IntExpr offset, IntExpr length)
{
Contract.Requires(s != null);
Contract.Requires(offset != null);
Contract.Requires(length != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(s, offset, length);
return new SeqExpr(this, Native.Z3_mk_seq_extract(nCtx, s.NativeObject, offset.NativeObject, length.NativeObject));
}
///
/// Extract index of sub-string starting at offset.
///
public IntExpr MkIndexOf(SeqExpr s, SeqExpr substr, ArithExpr offset)
{
Contract.Requires(s != null);
Contract.Requires(offset != null);
Contract.Requires(substr != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(s, substr, offset);
return new IntExpr(this, Native.Z3_mk_seq_index(nCtx, s.NativeObject, substr.NativeObject, offset.NativeObject));
}
///
/// Replace the first occurrence of src by dst in s.
///
public SeqExpr MkReplace(SeqExpr s, SeqExpr src, SeqExpr dst)
{
Contract.Requires(s != null);
Contract.Requires(src != null);
Contract.Requires(dst != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(s, src, dst);
return new SeqExpr(this, Native.Z3_mk_seq_replace(nCtx, s.NativeObject, src.NativeObject, dst.NativeObject));
}
///
/// Convert a regular expression that accepts sequence s.
///
public ReExpr MkToRe(SeqExpr s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result() != null);
return new ReExpr(this, Native.Z3_mk_seq_to_re(nCtx, s.NativeObject));
}
///
/// Check for regular expression membership.
///
public BoolExpr MkInRe(SeqExpr s, ReExpr re)
{
Contract.Requires(s != null);
Contract.Requires(re != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(s, re);
return new BoolExpr(this, Native.Z3_mk_seq_in_re(nCtx, s.NativeObject, re.NativeObject));
}
///
/// Take the Kleene star of a regular expression.
///
public ReExpr MkStar(ReExpr re)
{
Contract.Requires(re != null);
Contract.Ensures(Contract.Result() != null);
return new ReExpr(this, Native.Z3_mk_re_star(nCtx, re.NativeObject));
}
///
/// Take the bounded Kleene star of a regular expression.
///
public ReExpr MkLoop(ReExpr re, uint lo, uint hi = 0)
{
Contract.Requires(re != null);
Contract.Ensures(Contract.Result() != null);
return new ReExpr(this, Native.Z3_mk_re_loop(nCtx, re.NativeObject, lo, hi));
}
///
/// Take the Kleene plus of a regular expression.
///
public ReExpr MkPlus(ReExpr re)
{
Contract.Requires(re != null);
Contract.Ensures(Contract.Result() != null);
return new ReExpr(this, Native.Z3_mk_re_plus(nCtx, re.NativeObject));
}
///
/// Create the optional regular expression.
///
public ReExpr MkOption(ReExpr re)
{
Contract.Requires(re != null);
Contract.Ensures(Contract.Result() != null);
return new ReExpr(this, Native.Z3_mk_re_option(nCtx, re.NativeObject));
}
///
/// Create the complement regular expression.
///
public ReExpr MkComplement(ReExpr re)
{
Contract.Requires(re != null);
Contract.Ensures(Contract.Result() != null);
return new ReExpr(this, Native.Z3_mk_re_complement(nCtx, re.NativeObject));
}
///
/// Create the concatenation of regular languages.
///
public ReExpr MkConcat(params ReExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new ReExpr(this, Native.Z3_mk_re_concat(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
///
/// Create the union of regular languages.
///
public ReExpr MkUnion(params ReExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new ReExpr(this, Native.Z3_mk_re_union(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
///
/// Create the intersection of regular languages.
///
public ReExpr MkIntersect(params ReExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(t);
return new ReExpr(this, Native.Z3_mk_re_intersect(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
///
/// Create the empty regular expression.
///
public ReExpr MkEmptyRe(Sort s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result() != null);
return new ReExpr(this, Native.Z3_mk_re_empty(nCtx, s.NativeObject));
}
///
/// Create the full regular expression.
///
public ReExpr MkFullRe(Sort s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result() != null);
return new ReExpr(this, Native.Z3_mk_re_full(nCtx, s.NativeObject));
}
///
/// Create a range expression.
///
public ReExpr MkRange(SeqExpr lo, SeqExpr hi)
{
Contract.Requires(lo != null);
Contract.Requires(hi != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(lo, hi);
return new ReExpr(this, Native.Z3_mk_re_range(nCtx, lo.NativeObject, hi.NativeObject));
}
#endregion
#region Pseudo-Boolean constraints
///
/// Create an at-most-k constraint.
///
public BoolExpr MkAtMost(BoolExpr[] args, uint k)
{
Contract.Requires(args != null);
Contract.Requires(Contract.Result() != null);
CheckContextMatch(args);
return new BoolExpr(this, Native.Z3_mk_atmost(nCtx, (uint) args.Length,
AST.ArrayToNative(args), k));
}
///
/// Create an at-least-k constraint.
///
public BoolExpr MkAtLeast(BoolExpr[] args, uint k)
{
Contract.Requires(args != null);
Contract.Requires(Contract.Result() != null);
CheckContextMatch(args);
return new BoolExpr(this, Native.Z3_mk_atleast(nCtx, (uint) args.Length,
AST.ArrayToNative(args), k));
}
///
/// Create a pseudo-Boolean less-or-equal constraint.
///
public BoolExpr MkPBLe(int[] coeffs, BoolExpr[] args, int k)
{
Contract.Requires(args != null);
Contract.Requires(coeffs != null);
Contract.Requires(args.Length == coeffs.Length);
Contract.Requires(Contract.Result() != null);
CheckContextMatch(args);
return new BoolExpr(this, Native.Z3_mk_pble(nCtx, (uint) args.Length,
AST.ArrayToNative(args),
coeffs, k));
}
///
/// Create a pseudo-Boolean greater-or-equal constraint.
///
public BoolExpr MkPBGe(int[] coeffs, BoolExpr[] args, int k)
{
Contract.Requires(args != null);
Contract.Requires(coeffs != null);
Contract.Requires(args.Length == coeffs.Length);
Contract.Requires(Contract.Result() != null);
CheckContextMatch(args);
return new BoolExpr(this, Native.Z3_mk_pbge(nCtx, (uint) args.Length,
AST.ArrayToNative(args),
coeffs, k));
}
///
/// Create a pseudo-Boolean equal constraint.
///
public BoolExpr MkPBEq(int[] coeffs, BoolExpr[] args, int k)
{
Contract.Requires(args != null);
Contract.Requires(coeffs != null);
Contract.Requires(args.Length == coeffs.Length);
Contract.Requires(Contract.Result() != null);
CheckContextMatch(args);
return new BoolExpr(this, Native.Z3_mk_pbeq(nCtx, (uint) args.Length,
AST.ArrayToNative(args),
coeffs, k));
}
#endregion
#region Numerals
#region General Numerals
///
/// Create a Term of a given sort.
///
/// A string representing the Term value in decimal notation. If the given sort is a real, then the Term can be a rational, that is, a string of the form [num]* / [num]*.
/// The sort of the numeral. In the current implementation, the given sort can be an int, real, or bit-vectors of arbitrary size.
/// A Term with value and sort
public Expr MkNumeral(string v, Sort ty)
{
Contract.Requires(ty != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(ty);
return Expr.Create(this, Native.Z3_mk_numeral(nCtx, v, ty.NativeObject));
}
///
/// Create a Term of a given sort. This function can be used to create numerals that fit in a machine integer.
/// It is slightly faster than MakeNumeral since it is not necessary to parse a string.
///
/// Value of the numeral
/// Sort of the numeral
/// A Term with value and type
public Expr MkNumeral(int v, Sort ty)
{
Contract.Requires(ty != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(ty);
return Expr.Create(this, Native.Z3_mk_int(nCtx, v, ty.NativeObject));
}
///
/// Create a Term of a given sort. This function can be used to create numerals that fit in a machine integer.
/// It is slightly faster than MakeNumeral since it is not necessary to parse a string.
///
/// Value of the numeral
/// Sort of the numeral
/// A Term with value and type
public Expr MkNumeral(uint v, Sort ty)
{
Contract.Requires(ty != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(ty);
return Expr.Create(this, Native.Z3_mk_unsigned_int(nCtx, v, ty.NativeObject));
}
///
/// Create a Term of a given sort. This function can be used to create numerals that fit in a machine integer.
/// It is slightly faster than MakeNumeral since it is not necessary to parse a string.
///
/// Value of the numeral
/// Sort of the numeral
/// A Term with value and type
public Expr MkNumeral(long v, Sort ty)
{
Contract.Requires(ty != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(ty);
return Expr.Create(this, Native.Z3_mk_int64(nCtx, v, ty.NativeObject));
}
///
/// Create a Term of a given sort. This function can be used to create numerals that fit in a machine integer.
/// It is slightly faster than MakeNumeral since it is not necessary to parse a string.
///
/// Value of the numeral
/// Sort of the numeral
/// A Term with value and type
public Expr MkNumeral(ulong v, Sort ty)
{
Contract.Requires(ty != null);
Contract.Ensures(Contract.Result() != null);
CheckContextMatch(ty);
return Expr.Create(this, Native.Z3_mk_unsigned_int64(nCtx, v, ty.NativeObject));
}
#endregion
#region Reals
///
/// Create a real from a fraction.
///
/// numerator of rational.
/// denominator of rational.
/// A Term with value / and sort Real
///
public RatNum MkReal(int num, int den)
{
if (den == 0)
throw new Z3Exception("Denominator is zero");
Contract.Ensures(Contract.Result() != null);
Contract.EndContractBlock();
return new RatNum(this, Native.Z3_mk_real(nCtx, num, den));
}
///
/// Create a real numeral.
///
/// A string representing the Term value in decimal notation.
/// A Term with value and sort Real
public RatNum MkReal(string v)
{
Contract.Ensures(Contract.Result() != null);
return new RatNum(this, Native.Z3_mk_numeral(nCtx, v, RealSort.NativeObject));
}
///
/// Create a real numeral.
///
/// value of the numeral.
/// A Term with value and sort Real
public RatNum MkReal(int v)
{
Contract.Ensures(Contract.Result() != null);
return new RatNum(this, Native.Z3_mk_int(nCtx, v, RealSort.NativeObject));
}
///
/// Create a real numeral.
///
/// value of the numeral.
/// A Term with value and sort Real
public RatNum MkReal(uint v)
{
Contract.Ensures(Contract.Result() != null);
return new RatNum(this, Native.Z3_mk_unsigned_int(nCtx, v, RealSort.NativeObject));
}
///
/// Create a real numeral.
///
/// value of the numeral.
/// A Term with value and sort Real
public RatNum MkReal(long v)
{
Contract.Ensures(Contract.Result() != null);
return new RatNum(this, Native.Z3_mk_int64(nCtx, v, RealSort.NativeObject));
}
///
/// Create a real numeral.
///
/// value of the numeral.
/// A Term with value and sort Real
public RatNum MkReal(ulong v)
{
Contract.Ensures(Contract.Result() != null);
return new RatNum(this, Native.Z3_mk_unsigned_int64(nCtx, v, RealSort.NativeObject));
}
#endregion
#region Integers
///
/// Create an integer numeral.
///
/// A string representing the Term value in decimal notation.
public IntNum MkInt(string v)
{
Contract.Ensures(Contract.Result() != null);
return new IntNum(this, Native.Z3_mk_numeral(nCtx, v, IntSort.NativeObject));
}
///
/// Create an integer numeral.
///
/// value of the numeral.
/// A Term with value and sort Integer
public IntNum MkInt(int v)
{
Contract.Ensures(Contract.Result() != null);
return new IntNum(this, Native.Z3_mk_int(nCtx, v, IntSort.NativeObject));
}
///
/// Create an integer numeral.
///
/// value of the numeral.
/// A Term with value and sort Integer
public IntNum MkInt(uint v)
{
Contract.Ensures(Contract.Result() != null);
return new IntNum(this, Native.Z3_mk_unsigned_int(nCtx, v, IntSort.NativeObject));
}
///
/// Create an integer numeral.
///
/// value of the numeral.
/// A Term with value and sort Integer
public IntNum MkInt(long v)
{
Contract.Ensures(Contract.Result() != null);
return new IntNum(this, Native.Z3_mk_int64(nCtx, v, IntSort.NativeObject));
}
///
/// Create an integer numeral.
///
/// value of the numeral.
/// A Term with value and sort Integer
public IntNum MkInt(ulong v)
{
Contract.Ensures(Contract.Result() != null);
return new IntNum(this, Native.Z3_mk_unsigned_int64(nCtx, v, IntSort.NativeObject));
}
#endregion
#region Bit-vectors
///
/// Create a bit-vector numeral.
///
/// A string representing the value in decimal notation.
/// the size of the bit-vector
public BitVecNum MkBV(string v, uint size)
{
Contract.Ensures(Contract.Result() != null);
return (BitVecNum)MkNumeral(v, MkBitVecSort(size));
}
///
/// Create a bit-vector numeral.
///
/// value of the numeral.
/// the size of the bit-vector
public BitVecNum MkBV(int v, uint size)
{
Contract.Ensures(Contract.Result() != null);
return (BitVecNum)MkNumeral(v, MkBitVecSort(size));
}
///
/// Create a bit-vector numeral.
///
/// value of the numeral.
/// the size of the bit-vector
public BitVecNum MkBV(uint v, uint size)
{
Contract.Ensures(Contract.Result() != null);
return (BitVecNum)MkNumeral(v, MkBitVecSort(size));
}
///
/// Create a bit-vector numeral.
///
/// value of the numeral.
/// the size of the bit-vector
public BitVecNum MkBV(long v, uint size)
{
Contract.Ensures(Contract.Result() != null);
return (BitVecNum)MkNumeral(v, MkBitVecSort(size));
}
///
/// Create a bit-vector numeral.
///
/// value of the numeral.
/// the size of the bit-vector
public BitVecNum MkBV(ulong v, uint size)
{
Contract.Ensures(Contract.Result() != null);
return (BitVecNum)MkNumeral(v, MkBitVecSort(size));
}
///
/// Create a bit-vector numeral.
///
/// An array of bits representing the bit-vector. Least signficant bit is at position 0.
public BitVecNum MkBV(bool[] bits)
{
Contract.Ensures(Contract.Result() != null);
int[] _bits = new int[bits.Length];
for (int i = 0; i < bits.Length; ++i) _bits[i] = bits[i] ? 1 : 0;
return (BitVecNum)Expr.Create(this, Native.Z3_mk_bv_numeral(nCtx, (uint)bits.Length, _bits));
}
#endregion
#endregion // Numerals
#region Quantifiers
///
/// Create a universal Quantifier.
///
///
/// Creates a forall formula, where