Commits

Leonardo de Moura committed 3e89fc0

Moved Microsoft.Z3V3 to dead folder

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>

  • Participants
  • Parent commits f45d4b9

Comments (0)

Files changed (73)

File scripts/mk_make.py

 add_exe('test', ['api', 'fuzzing'], exe_name='test-z3')
 API_files = ['z3_api.h']
 add_dll('api_dll', ['api', 'sat', 'extra_cmds'], 'api/dll', reexports=['api'], dll_name='libz3', export_files=API_files)
-add_dot_net_dll('dotnet', ['api_dll'], 'bindings/dotnet/Microsoft.Z3', dll_name='Microsoft.Z3', assembly_info_dir='Properties')
-add_dot_net_dll('dotnetV3', ['api_dll'], 'bindings/dotnet/Microsoft.Z3V3', dll_name='Microsoft.Z3V3')
+add_dot_net_dll('dotnet', ['api_dll'], 'bindings/dotnet', dll_name='Microsoft.Z3', assembly_info_dir='Properties')
 set_python_dir('bindings/python')
 
 update_version(4, 2, 0, 0)

File src/bindings/dotnet/AST.cs

+/*++
+Copyright (c) 2012 Microsoft Corporation
+
+Module Name:
+
+    AST.cs
+
+Abstract:
+
+    Z3 Managed API: ASTs
+
+Author:
+
+    Christoph Wintersteiger (cwinter) 2012-03-16
+
+Notes:
+    
+--*/
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Diagnostics.Contracts;
+
+namespace Microsoft.Z3
+{
+    /// <summary>
+    /// The abstract syntax tree (AST) class. 
+    /// </summary>
+    [ContractVerification(true)]
+    public class AST : Z3Object, IComparable
+    {
+        /// <summary>
+        /// Comparison operator.
+        /// </summary>
+        /// <param name="a">An AST</param>
+        /// <param name="b">An AST</param>
+        /// <returns>True if <paramref name="a"/> and <paramref name="b"/> are from the same context 
+        /// and represent the same sort; false otherwise.</returns>
+        public static bool operator ==(AST a, AST b)
+        {
+            return Object.ReferenceEquals(a, b) ||
+                   (!Object.ReferenceEquals(a, null) &&
+                    !Object.ReferenceEquals(b, null) &&
+                    a.Context.nCtx == b.Context.nCtx &&
+                    Native.Z3_is_eq_ast(a.Context.nCtx, a.NativeObject, b.NativeObject) != 0);
+        }
+
+        /// <summary>
+        /// Comparison operator.
+        /// </summary>
+        /// <param name="a">An AST</param>
+        /// <param name="b">An AST</param>
+        /// <returns>True if <paramref name="a"/> and <paramref name="b"/> are not from the same context 
+        /// or represent different sorts; false otherwise.</returns>
+        public static bool operator !=(AST a, AST b)
+        {
+            return !(a == b);
+        }
+
+        /// <summary>
+        /// Object comparison.
+        /// </summary>
+        public override bool Equals(object o)
+        {
+            AST casted = o as AST;
+            if (casted == null) return false;
+            return this == casted;
+        }
+
+        /// <summary>
+        /// Object Comparison.
+        /// </summary>
+        /// <param name="other">Another AST</param>
+        /// <returns>Negative if the object should be sorted before <paramref name="other"/>, positive if after else zero.</returns>
+        public virtual int CompareTo(object other)
+        {
+            if (other == null) return 1;
+            AST oAST = other as AST;
+            if (oAST == null)
+                return 1;
+            else
+            {
+                if (Id < oAST.Id)
+                    return -1;
+                else if (Id > oAST.Id)
+                    return +1;
+                else
+                    return 0;
+            }
+        }
+
+        /// <summary>
+        /// The AST's hash code.
+        /// </summary>
+        /// <returns>A hash code</returns>
+        public override int GetHashCode()
+        {
+            return (int)Native.Z3_get_ast_hash(Context.nCtx, NativeObject);
+        }
+
+        /// <summary>
+        /// A unique identifier for the AST (unique among all ASTs).
+        /// </summary>
+        public uint Id
+        {
+            get { return Native.Z3_get_ast_id(Context.nCtx, NativeObject); }
+        }
+
+        /// <summary>
+        /// Translates (copies) the AST to the Context <paramref name="ctx"/>.
+        /// </summary>
+        /// <param name="ctx">A context</param>
+        /// <returns>A copy of the AST which is associated with <paramref name="ctx"/></returns>
+        public AST Translate(Context ctx)
+        {
+            Contract.Requires(ctx != null);
+            Contract.Ensures(Contract.Result<AST>() != null);
+
+            if (ReferenceEquals(Context, ctx))
+                return this;
+            else
+                return new AST(ctx, Native.Z3_translate(Context.nCtx, NativeObject, ctx.nCtx));
+        }
+
+        /// <summary>
+        /// The kind of the AST.
+        /// </summary>    
+        public Z3_ast_kind ASTKind
+        {
+            get { return (Z3_ast_kind)Native.Z3_get_ast_kind(Context.nCtx, NativeObject); }
+        }
+
+        /// <summary>
+        /// Indicates whether the AST is an Expr
+        /// </summary>
+        public bool IsExpr
+        {
+            get
+            {
+                switch (ASTKind)
+                {
+                    case Z3_ast_kind.Z3_APP_AST:
+                    case Z3_ast_kind.Z3_NUMERAL_AST:
+                    case Z3_ast_kind.Z3_QUANTIFIER_AST:
+                    case Z3_ast_kind.Z3_VAR_AST: return true;
+                    default: return false;
+                }
+            }
+        }
+
+        /// <summary>
+        /// Indicates whether the AST is a BoundVariable
+        /// </summary>
+        public bool IsVar
+        {
+            get { return this.ASTKind == Z3_ast_kind.Z3_VAR_AST; }
+        }
+
+        /// <summary>
+        /// Indicates whether the AST is a Quantifier
+        /// </summary>
+        public bool IsQuantifier
+        {
+            get { return this.ASTKind == Z3_ast_kind.Z3_QUANTIFIER_AST; }
+        }
+
+        /// <summary>
+        /// Indicates whether the AST is a Sort
+        /// </summary>
+        public bool IsSort
+        {
+            get { return this.ASTKind == Z3_ast_kind.Z3_SORT_AST; }
+        }
+
+        /// <summary>
+        /// Indicates whether the AST is a FunctionDeclaration
+        /// </summary>
+        public bool IsFuncDecl
+        {
+            get { return this.ASTKind == Z3_ast_kind.Z3_FUNC_DECL_AST; }
+        }
+
+        /// <summary>
+        /// A string representation of the AST.
+        /// </summary>
+        public override string ToString()
+        {
+            return Native.Z3_ast_to_string(Context.nCtx, NativeObject);
+        }
+
+        /// <summary>
+        /// A string representation of the AST in s-expression notation.
+        /// </summary>
+        public string SExpr()
+        {
+            Contract.Ensures(Contract.Result<string>() != null);
+
+            return Native.Z3_ast_to_string(Context.nCtx, NativeObject);
+        }
+
+        #region Internal
+        internal AST(Context ctx) : base(ctx) { Contract.Requires(ctx != null); }
+        internal AST(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
+
+        internal class DecRefQueue : Z3.DecRefQueue
+        {
+            public override void IncRef(Context ctx, IntPtr obj)
+            {
+                Native.Z3_inc_ref(ctx.nCtx, obj);
+            }
+
+            public override void DecRef(Context ctx, IntPtr obj)
+            {
+                Native.Z3_dec_ref(ctx.nCtx, obj);
+            }
+        };        
+
+        internal override void IncRef(IntPtr o)
+        {            
+            // Console.WriteLine("AST IncRef()");
+            if (Context == null)
+                throw new Z3Exception("inc() called on null context");
+            if (o == IntPtr.Zero)
+                throw new Z3Exception("inc() called on null AST");
+            Context.AST_DRQ.IncAndClear(Context, o);
+            base.IncRef(o);
+        }
+
+        internal override void DecRef(IntPtr o)
+        {
+            // Console.WriteLine("AST DecRef()");
+            if (Context == null)
+                throw new Z3Exception("dec() called on null context");
+            if (o == IntPtr.Zero)
+                throw new Z3Exception("dec() called on null AST");
+            Context.AST_DRQ.Add(o);
+            base.DecRef(o);
+        }
+
+        internal static AST Create(Context ctx, IntPtr obj)
+        {
+            Contract.Requires(ctx != null);
+            Contract.Ensures(Contract.Result<AST>() != null);
+
+            switch ((Z3_ast_kind)Native.Z3_get_ast_kind(ctx.nCtx, obj))
+            {
+                case Z3_ast_kind.Z3_FUNC_DECL_AST: return new FuncDecl(ctx, obj);
+                case Z3_ast_kind.Z3_QUANTIFIER_AST: return new Quantifier(ctx, obj);
+                case Z3_ast_kind.Z3_SORT_AST: return Sort.Create(ctx, obj);
+                case Z3_ast_kind.Z3_APP_AST:
+                case Z3_ast_kind.Z3_NUMERAL_AST:
+                case Z3_ast_kind.Z3_VAR_AST: return Expr.Create(ctx, obj);
+                default:
+                    throw new Z3Exception("Unknown AST kind");
+            }
+        }
+        #endregion
+    }
+}

File src/bindings/dotnet/ASTMap.cs

+/*++
+Copyright (c) 2012 Microsoft Corporation
+
+Module Name:
+
+    ASTMap.cs
+
+Abstract:
+
+    Z3 Managed API: AST Maps
+
+Author:
+
+    Christoph Wintersteiger (cwinter) 2012-03-21
+
+Notes:
+    
+--*/
+
+using System;
+using System.Diagnostics.Contracts;
+
+namespace Microsoft.Z3
+{
+    /// <summary>
+    /// Map from AST to AST
+    /// </summary>
+    [ContractVerification(true)]
+    internal class ASTMap : Z3Object
+    {
+        /// <summary>
+        /// Checks whether the map contains the key <paramref name="k"/>.
+        /// </summary>
+        /// <param name="k">An AST</param>
+        /// <returns>True if <paramref name="k"/> is a key in the map, false otherwise.</returns>
+        public bool Contains(AST k)
+        {
+            Contract.Requires(k != null);
+
+            return Native.Z3_ast_map_contains(Context.nCtx, NativeObject, k.NativeObject) != 0;
+        }
+
+        /// <summary>
+        /// Finds the value associated with the key <paramref name="k"/>.
+        /// </summary>
+        /// <remarks>
+        /// This function signs an error when <paramref name="k"/> is not a key in the map.
+        /// </remarks>
+        /// <param name="k">An AST</param>    
+        public AST Find(AST k)
+        {
+            Contract.Requires(k != null);
+            Contract.Ensures(Contract.Result<AST>() != null);
+
+            return new AST(Context, Native.Z3_ast_map_find(Context.nCtx, NativeObject, k.NativeObject));
+        }
+
+        /// <summary>
+        /// Stores or replaces a new key/value pair in the map.
+        /// </summary>
+        /// <param name="k">The key AST</param>
+        /// <param name="v">The value AST</param>
+        public void Insert(AST k, AST v)
+        {
+            Contract.Requires(k != null);
+            Contract.Requires(v != null);
+
+            Native.Z3_ast_map_insert(Context.nCtx, NativeObject, k.NativeObject, v.NativeObject);
+        }
+
+        /// <summary>
+        /// Erases the key <paramref name="k"/> from the map.
+        /// </summary>
+        /// <param name="k">An AST</param>
+        public void Erase(AST k)
+        {
+            Contract.Requires(k != null);
+
+            Native.Z3_ast_map_erase(Context.nCtx, NativeObject, k.NativeObject);
+        }
+
+        /// <summary>
+        /// Removes all keys from the map.
+        /// </summary>
+        public void Reset()
+        {
+            Native.Z3_ast_map_reset(Context.nCtx, NativeObject);
+        }
+
+        /// <summary>
+        /// The size of the map
+        /// </summary>
+        public uint Size
+        {
+            get { return Native.Z3_ast_map_size(Context.nCtx, NativeObject); }
+        }
+
+        /// <summary>
+        /// The keys stored in the map.
+        /// </summary>
+        public ASTVector Keys
+        {
+            get
+            {
+                return new ASTVector(Context, Native.Z3_ast_map_keys(Context.nCtx, NativeObject));
+            }
+        }
+
+        /// <summary>
+        /// Retrieves a string representation of the map. 
+        /// </summary>    
+        public override string ToString()
+        {
+            return Native.Z3_ast_map_to_string(Context.nCtx, NativeObject);
+        }
+
+        #region Internal
+        internal ASTMap(Context ctx, IntPtr obj)
+            : base(ctx, obj)
+        {
+            Contract.Requires(ctx != null);
+        }
+        internal ASTMap(Context ctx)
+            : base(ctx, Native.Z3_mk_ast_map(ctx.nCtx))
+        {
+            Contract.Requires(ctx != null);
+        }
+
+        internal class DecRefQueue : Z3.DecRefQueue
+        {
+            public override void IncRef(Context ctx, IntPtr obj)
+            {
+                Native.Z3_ast_map_inc_ref(ctx.nCtx, obj);
+            }
+
+            public override void DecRef(Context ctx, IntPtr obj)
+            {
+                Native.Z3_ast_map_dec_ref(ctx.nCtx, obj);
+            }
+        };
+
+        internal override void IncRef(IntPtr o)
+        {
+            Context.ASTMap_DRQ.IncAndClear(Context, o);
+            base.IncRef(o);
+        }
+
+        internal override void DecRef(IntPtr o)
+        {
+            Context.ASTMap_DRQ.Add(o);
+            base.DecRef(o);
+        }
+        #endregion
+    }
+}

File src/bindings/dotnet/ASTVector.cs

+/*++
+Copyright (c) 2012 Microsoft Corporation
+
+Module Name:
+
+    ASTVector.cs
+
+Abstract:
+
+    Z3 Managed API: AST Vectors
+
+Author:
+
+    Christoph Wintersteiger (cwinter) 2012-03-21
+
+Notes:
+    
+--*/
+
+using System;
+using System.Diagnostics.Contracts;
+
+namespace Microsoft.Z3
+{
+    /// <summary>
+    /// Vectors of ASTs.
+    /// </summary>
+    internal class ASTVector : Z3Object
+    {
+        /// <summary>
+        /// The size of the vector
+        /// </summary>
+        public uint Size
+        {
+            get { return Native.Z3_ast_vector_size(Context.nCtx, NativeObject); }
+        }
+
+        /// <summary>
+        /// Retrieves the i-th object in the vector.
+        /// </summary>
+        /// <remarks>May throw an IndexOutOfBoundsException when <paramref name="i"/> is out of range.</remarks>
+        /// <param name="i">Index</param>
+        /// <returns>An AST</returns>
+        public AST this[uint i]
+        {
+            get
+            {
+                Contract.Ensures(Contract.Result<AST>() != null);
+
+                return new AST(Context, Native.Z3_ast_vector_get(Context.nCtx, NativeObject, i));
+            }
+            set
+            {
+                Contract.Requires(value!= null);
+
+                Native.Z3_ast_vector_set(Context.nCtx, NativeObject, i, value.NativeObject);
+            }
+        }
+
+        /// <summary>
+        /// Resize the vector to <paramref name="newSize"/>.
+        /// </summary>
+        /// <param name="newSize">The new size of the vector.</param>
+        public void Resize(uint newSize)
+        {
+            Native.Z3_ast_vector_resize(Context.nCtx, NativeObject, newSize);
+        }
+
+        /// <summary>
+        /// Add the AST <paramref name="a"/> to the back of the vector. The size
+        /// is increased by 1.
+        /// </summary>
+        /// <param name="a">An AST</param>
+        public void Push(AST a)
+        {
+            Contract.Requires(a != null);
+
+            Native.Z3_ast_vector_push(Context.nCtx, NativeObject, a.NativeObject);
+        }
+
+        /// <summary>
+        /// Translates all ASTs in the vector to <paramref name="ctx"/>.
+        /// </summary>
+        /// <param name="ctx">A context</param>
+        /// <returns>A new ASTVector</returns>
+        public ASTVector Translate(Context ctx)
+        {
+            Contract.Requires(ctx != null);
+            Contract.Ensures(Contract.Result<ASTVector>() != null);
+
+            return new ASTVector(Context, Native.Z3_ast_vector_translate(Context.nCtx, NativeObject, ctx.nCtx));
+        }
+
+        /// <summary>
+        /// Retrieves a string representation of the vector. 
+        /// </summary>    
+        public override string ToString()
+        {
+            return Native.Z3_ast_vector_to_string(Context.nCtx, NativeObject);
+        }
+
+        #region Internal
+        internal ASTVector(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
+        internal ASTVector(Context ctx) : base(ctx, Native.Z3_mk_ast_vector(ctx.nCtx)) { Contract.Requires(ctx != null); }
+
+        internal class DecRefQueue : Z3.DecRefQueue
+        {
+            public override void IncRef(Context ctx, IntPtr obj)
+            {
+                Native.Z3_ast_vector_inc_ref(ctx.nCtx, obj);
+            }
+
+            public override void DecRef(Context ctx, IntPtr obj)
+            {
+                Native.Z3_ast_vector_dec_ref(ctx.nCtx, obj);
+            }
+        };
+
+        internal override void IncRef(IntPtr o)
+        {
+            Context.ASTVector_DRQ.IncAndClear(Context, o);
+            base.IncRef(o);
+        }
+
+        internal override void DecRef(IntPtr o)
+        {
+            Context.ASTVector_DRQ.Add(o);
+            base.DecRef(o);
+        }
+        #endregion
+    }
+}

File src/bindings/dotnet/ApplyResult.cs

+/*++
+Copyright (c) 2012 Microsoft Corporation
+
+Module Name:
+
+    ApplyResult.cs
+
+Abstract:
+
+    Z3 Managed API: Result object for tactic applications
+
+Author:
+
+    Christoph Wintersteiger (cwinter) 2012-03-21
+
+Notes:
+    
+--*/
+
+using System;
+using System.Diagnostics.Contracts;
+
+namespace Microsoft.Z3
+{
+    /// <summary>
+    /// ApplyResult objects represent the result of an application of a 
+    /// tactic to a goal. It contains the subgoals that were produced.
+    /// </summary>
+    [ContractVerification(true)]
+    public class ApplyResult : Z3Object
+    {
+        /// <summary>
+        /// The number of Subgoals.
+        /// </summary>
+        public uint NumSubgoals
+        {
+            get { return Native.Z3_apply_result_get_num_subgoals(Context.nCtx, NativeObject); }
+        }
+
+        /// <summary>
+        /// Retrieves the subgoals from the ApplyResult.
+        /// </summary>
+        public Goal[] Subgoals
+        {
+            get
+            {
+              Contract.Ensures(Contract.Result<Goal[]>() != null);
+              Contract.Ensures(Contract.Result<Goal[]>().Length == this.NumSubgoals);
+
+                uint n = NumSubgoals;
+                Goal[] res = new Goal[n];
+                for (uint i = 0; i < n; i++)
+                    res[i] = new Goal(Context, Native.Z3_apply_result_get_subgoal(Context.nCtx, NativeObject, i));
+                return res;
+            }
+        }
+
+        /// <summary>
+        /// Convert a model for the subgoal <paramref name="i"/> into a model for the original 
+        /// goal <c>g</c>, that the ApplyResult was obtained from. 
+        /// </summary>
+        /// <returns>A model for <c>g</c></returns>
+        public Model ConvertModel(uint i, Model m)
+        {
+            Contract.Requires(m != null);
+            Contract.Ensures(Contract.Result<Model>() != null);
+
+            return new Model(Context, Native.Z3_apply_result_convert_model(Context.nCtx, NativeObject, i, m.NativeObject));
+        }
+
+        /// <summary>
+        /// A string representation of the ApplyResult.
+        /// </summary>
+        public override string ToString()
+        {
+            return Native.Z3_apply_result_to_string(Context.nCtx, NativeObject);
+        }
+
+        #region Internal
+        internal ApplyResult(Context ctx, IntPtr obj) : base(ctx, obj) 
+        {
+            Contract.Requires(ctx != null);
+        }
+
+        internal class DecRefQueue : Z3.DecRefQueue
+        {
+            public override void IncRef(Context ctx, IntPtr obj)
+            {
+                Native.Z3_apply_result_inc_ref(ctx.nCtx, obj);
+            }
+
+            public override void DecRef(Context ctx, IntPtr obj)
+            {
+                Native.Z3_apply_result_dec_ref(ctx.nCtx, obj);
+            }
+        };        
+
+        internal override void IncRef(IntPtr o)
+        {
+            Context.ApplyResult_DRQ.IncAndClear(Context, o);
+            base.IncRef(o);
+        }
+
+        internal override void DecRef(IntPtr o)
+        {
+            Context.ApplyResult_DRQ.Add(o);
+            base.DecRef(o);
+        }
+        #endregion
+    }
+}

File src/bindings/dotnet/Constructor.cs

+/*++
+Copyright (c) 2012 Microsoft Corporation
+
+Module Name:
+
+    Constructor.cs
+
+Abstract:
+
+    Z3 Managed API: Constructors
+
+Author:
+
+    Christoph Wintersteiger (cwinter) 2012-03-22
+
+Notes:
+    
+--*/
+
+using System;
+using System.Diagnostics.Contracts;
+
+namespace Microsoft.Z3
+{
+    /// <summary>
+    /// Constructors are used for datatype sorts.
+    /// </summary>
+    [ContractVerification(true)]
+    public class Constructor : Z3Object
+    {
+        /// <summary>
+        /// The number of fields of the constructor.
+        /// </summary>
+        public uint NumFields
+        {
+            get { init();  return n; }
+        }
+
+        /// <summary>
+        /// The function declaration of the constructor.
+        /// </summary>
+        public FuncDecl ConstructorDecl
+        {
+            get {
+                Contract.Ensures(Contract.Result<FuncDecl>() != null);
+                init();  return m_constructorDecl; }
+        }
+
+        /// <summary>
+        /// The function declaration of the tester.
+        /// </summary>
+        public FuncDecl TesterDecl
+        {
+            get {
+                Contract.Ensures(Contract.Result<FuncDecl>() != null);
+                init();  return m_testerDecl; }
+        }
+
+        /// <summary>
+        /// The function declarations of the accessors
+        /// </summary>
+        public FuncDecl[] AccessorDecls
+        {
+            get {
+                Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
+                init();  return m_accessorDecls; }
+        }        
+
+        /// <summary>
+        /// Destructor.
+        /// </summary>
+        ~Constructor()
+        {
+            Native.Z3_del_constructor(Context.nCtx, NativeObject);
+        }
+
+        #region Object invariant
+
+        [ContractInvariantMethod]
+        private void ObjectInvariant()
+        {
+            Contract.Invariant(m_testerDecl  == null || m_constructorDecl != null);
+            Contract.Invariant(m_testerDecl == null || m_accessorDecls != null);
+        }
+        
+        #endregion
+
+        #region Internal
+        readonly private uint n = 0;
+        private FuncDecl m_testerDecl = null;
+        private FuncDecl m_constructorDecl = null;
+        private FuncDecl[] m_accessorDecls = null;
+
+        internal Constructor(Context ctx, Symbol name, Symbol recognizer, Symbol[] fieldNames,
+                             Sort[] sorts, uint[] sortRefs)
+            : base(ctx)
+        {
+            Contract.Requires(ctx != null);
+            Contract.Requires(name != null);
+            Contract.Requires(recognizer != null);
+
+            n = AST.ArrayLength(fieldNames);
+
+            if (n != AST.ArrayLength(sorts))
+                throw new Z3Exception("Number of field names does not match number of sorts");
+            if (sortRefs != null && sortRefs.Length != n)
+                throw new Z3Exception("Number of field names does not match number of sort refs");
+            
+            if (sortRefs == null) sortRefs = new uint[n];
+
+            NativeObject = Native.Z3_mk_constructor(ctx.nCtx, name.NativeObject, recognizer.NativeObject,
+                                                    n,
+                                                    Symbol.ArrayToNative(fieldNames),
+                                                    Sort.ArrayToNative(sorts),
+                                                    sortRefs);
+
+        }
+
+        private void init() 
+        {
+            Contract.Ensures(m_constructorDecl != null);
+            Contract.Ensures(m_testerDecl != null);
+            Contract.Ensures(m_accessorDecls != null);
+
+            if (m_testerDecl != null) return;
+            IntPtr constructor = IntPtr.Zero;
+            IntPtr tester = IntPtr.Zero;
+            IntPtr[] accessors = new IntPtr[n];
+            Native.Z3_query_constructor(Context.nCtx, NativeObject, n, ref constructor, ref tester, accessors);
+            m_constructorDecl = new FuncDecl(Context, constructor);
+            m_testerDecl = new FuncDecl(Context, tester);
+            m_accessorDecls = new FuncDecl[n];
+            for (uint i = 0; i < n; i++)
+                m_accessorDecls[i] = new FuncDecl(Context, accessors[i]);
+        }
+
+        #endregion
+    }
+
+    /// <summary>
+    /// Lists of constructors
+    /// </summary>
+    public class ConstructorList : Z3Object
+    {
+        /// <summary>
+        /// Destructor.
+        /// </summary>
+        ~ConstructorList()
+        {         
+            Native.Z3_del_constructor_list(Context.nCtx, NativeObject);
+        }
+
+        #region Internal
+        internal ConstructorList(Context ctx, IntPtr obj)
+            : base(ctx, obj)
+        {
+            Contract.Requires(ctx != null);
+        }
+
+        internal ConstructorList(Context ctx, Constructor[] constructors)
+            : base(ctx)
+        {
+            Contract.Requires(ctx != null);
+            Contract.Requires(constructors != null);
+
+            NativeObject = Native.Z3_mk_constructor_list(Context.nCtx, (uint)constructors.Length, Constructor.ArrayToNative(constructors));
+        }        
+        #endregion
+    }
+}

File src/bindings/dotnet/Context.cs

+/*++
+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;
+
+namespace Microsoft.Z3
+{
+    /// <summary>
+    /// The main interaction with Z3 happens via the Context.
+    /// </summary>
+    [ContractVerification(true)]
+    public class Context : IDisposable
+    {
+        #region Constructors
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        public Context()
+            : base()
+        {
+            m_ctx = Native.Z3_mk_context_rc(IntPtr.Zero);
+            InitContext();
+        }
+
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        public Context(Dictionary<string, string> settings)
+            : base()
+        {
+            Contract.Requires(settings != null);
+
+            IntPtr cfg = Native.Z3_mk_config();
+            foreach (KeyValuePair<string, string> 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
+        /// <summary>
+        /// Creates a new symbol using an integer.
+        /// </summary>
+        /// <remarks>
+        /// Not all integers can be passed to this function.
+        /// The legal range of unsigned integers is 0 to 2^30-1.
+        /// </remarks>
+        public IntSymbol MkSymbol(int i)
+        {
+            Contract.Ensures(Contract.Result<IntSymbol>() != null);
+
+            return new IntSymbol(this, i);
+        }
+
+        /// <summary>
+        /// Create a symbol using a string.
+        /// </summary>
+        public StringSymbol MkSymbol(string name)
+        {
+            Contract.Ensures(Contract.Result<StringSymbol>() != null);
+
+            return new StringSymbol(this, name);
+        }
+
+        /// <summary>
+        /// Create an array of symbols.
+        /// </summary>
+        internal Symbol[] MkSymbols(string[] names)
+        {
+            Contract.Ensures(names == null || Contract.Result<Symbol[]>() != null);
+            Contract.Ensures(names != null || Contract.Result<Symbol[]>() == null);
+            Contract.Ensures(Contract.Result<Symbol[]>() == null || Contract.Result<Symbol[]>().Length == names.Length);
+            Contract.Ensures(Contract.Result<Symbol[]>() == null || Contract.ForAll(Contract.Result<Symbol[]>(), 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;
+
+        /// <summary>
+        /// Retrieves the Boolean sort of the context.
+        /// </summary>
+        public BoolSort BoolSort
+        {
+            get
+            {
+                Contract.Ensures(Contract.Result<BoolSort>() != null);
+
+                if (m_boolSort == null) m_boolSort = new BoolSort(this); return m_boolSort;
+            }
+        }
+
+        /// <summary>
+        /// Retrieves the Integer sort of the context.
+        /// </summary>
+        public IntSort IntSort
+        {
+            get
+            {
+                Contract.Ensures(Contract.Result<IntSort>() != null);
+                if (m_intSort == null) m_intSort = new IntSort(this); return m_intSort;
+            }
+        }
+
+
+        /// <summary>
+        /// Retrieves the Real sort of the context.
+        /// </summary>
+        public RealSort RealSort { get { Contract.Ensures(Contract.Result<RealSort>() != null); if (m_realSort == null) m_realSort = new RealSort(this); return m_realSort; } }
+
+        /// <summary>
+        /// Create a new Boolean sort.
+        /// </summary>
+        public BoolSort MkBoolSort()
+        {
+            Contract.Ensures(Contract.Result<BoolSort>() != null);
+            return new BoolSort(this);
+        }
+
+        /// <summary>
+        /// Create a new uninterpreted sort.
+        /// </summary>
+        public UninterpretedSort MkUninterpretedSort(Symbol s)
+        {
+            Contract.Requires(s != null);
+            Contract.Ensures(Contract.Result<UninterpretedSort>() != null);
+
+            CheckContextMatch(s);
+            return new UninterpretedSort(this, s);
+        }
+
+        /// <summary>
+        /// Create a new uninterpreted sort.
+        /// </summary>
+        public UninterpretedSort MkUninterpretedSort(string str)
+        {
+            Contract.Ensures(Contract.Result<UninterpretedSort>() != null);
+
+            return MkUninterpretedSort(MkSymbol(str));
+        }
+
+        /// <summary>
+        /// Create a new integer sort.
+        /// </summary>
+        public IntSort MkIntSort()
+        {
+            Contract.Ensures(Contract.Result<IntSort>() != null);
+
+            return new IntSort(this);
+        }
+
+        /// <summary>
+        /// Create a real sort.
+        /// </summary>    
+        public RealSort MkRealSort()
+        {
+            Contract.Ensures(Contract.Result<RealSort>() != null);
+            return new RealSort(this);
+        }
+
+        /// <summary>
+        /// Create a new bit-vector sort.
+        /// </summary>
+        public BitVecSort MkBitVecSort(uint size)
+        {
+            Contract.Ensures(Contract.Result<BitVecSort>() != null);
+
+            return new BitVecSort(this, size);
+        }
+
+        /// <summary>
+        /// Create a new array sort.
+        /// </summary>
+        public ArraySort MkArraySort(Sort domain, Sort range)
+        {
+            Contract.Requires(domain != null);
+            Contract.Requires(range != null);
+            Contract.Ensures(Contract.Result<ArraySort>() != null);
+
+            CheckContextMatch(domain);
+            CheckContextMatch(range);
+            return new ArraySort(this, domain, range);
+        }
+
+        /// <summary>
+        /// Create a new tuple sort.
+        /// </summary>    
+        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<TupleSort>() != null);
+
+            CheckContextMatch(name);
+            CheckContextMatch(fieldNames);
+            CheckContextMatch(fieldSorts);
+            return new TupleSort(this, name, (uint)fieldNames.Length, fieldNames, fieldSorts);
+        }
+
+        /// <summary>
+        /// Create a new enumeration sort.
+        /// </summary>
+        public EnumSort MkEnumSort(Symbol name, Symbol[] enumNames)
+        {
+            Contract.Requires(name != null);
+            Contract.Requires(enumNames != null);
+            Contract.Requires(Contract.ForAll(enumNames, f => f != null));
+
+            Contract.Ensures(Contract.Result<EnumSort>() != null);
+
+            CheckContextMatch(name);
+            CheckContextMatch(enumNames);
+            return new EnumSort(this, name, enumNames);
+        }
+
+        /// <summary>
+        /// Create a new enumeration sort.
+        /// </summary>
+        public EnumSort MkEnumSort(string name, string[] enumNames)
+        {
+            Contract.Requires(enumNames != null);
+            Contract.Ensures(Contract.Result<EnumSort>() != null);
+
+            return new EnumSort(this, MkSymbol(name), MkSymbols(enumNames));
+        }
+
+        /// <summary>
+        /// Create a new list sort.
+        /// </summary>
+        public ListSort MkListSort(Symbol name, Sort elemSort)
+        {
+            Contract.Requires(name != null);
+            Contract.Requires(elemSort != null);
+            Contract.Ensures(Contract.Result<ListSort>() != null);
+
+            CheckContextMatch(name);
+            CheckContextMatch(elemSort);
+            return new ListSort(this, name, elemSort);
+        }
+
+        /// <summary>
+        /// Create a new list sort.
+        /// </summary>
+        public ListSort MkListSort(string name, Sort elemSort)
+        {
+            Contract.Requires(elemSort != null);
+            Contract.Ensures(Contract.Result<ListSort>() != null);
+
+            CheckContextMatch(elemSort);
+            return new ListSort(this, MkSymbol(name), elemSort);
+        }
+
+        /// <summary>
+        /// Create a new finite domain sort.
+        /// </summary>
+        public FiniteDomainSort MkFiniteDomainSort(Symbol name, ulong size)
+        {
+            Contract.Requires(name != null);
+            Contract.Ensures(Contract.Result<FiniteDomainSort>() != null);
+
+            CheckContextMatch(name);
+            return new FiniteDomainSort(this, name, size);
+        }
+
+        /// <summary>
+        /// Create a new finite domain sort.
+        /// </summary>
+        public FiniteDomainSort MkFiniteDomainSort(string name, ulong size)
+        {
+            Contract.Ensures(Contract.Result<FiniteDomainSort>() != null);
+
+            return new FiniteDomainSort(this, MkSymbol(name), size);
+        }
+
+
+        #region Datatypes
+        /// <summary>
+        /// Create a datatype constructor.
+        /// </summary>
+        /// <param name="name">constructor name</param>
+        /// <param name="recognizer">name of recognizer function.</param>
+        /// <param name="fieldNames">names of the constructor fields.</param>
+        /// <param name="sorts">field sorts, 0 if the field sort refers to a recursive sort.</param>
+        /// <param name="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.</param>
+        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<Constructor>() != null);
+
+            return new Constructor(this, name, recognizer, fieldNames, sorts, sortRefs);
+        }
+
+        /// <summary>
+        /// Create a datatype constructor.
+        /// </summary>
+        /// <param name="name"></param>
+        /// <param name="recognizer"></param>
+        /// <param name="fieldNames"></param>
+        /// <param name="sorts"></param>
+        /// <param name="sortRefs"></param>
+        /// <returns></returns>
+        public Constructor MkConstructor(string name, string recognizer, string[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null)
+        {
+            Contract.Ensures(Contract.Result<Constructor>() != null);
+
+            return new Constructor(this, MkSymbol(name), MkSymbol(recognizer), MkSymbols(fieldNames), sorts, sortRefs);
+        }
+
+        /// <summary>
+        /// Create a new datatype sort.
+        /// </summary>
+        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<DatatypeSort>() != null);
+
+            CheckContextMatch(name);
+            CheckContextMatch(constructors);
+            return new DatatypeSort(this, name, constructors);
+        }
+
+        /// <summary>
+        /// Create a new datatype sort.
+        /// </summary>
+        public DatatypeSort MkDatatypeSort(string name, Constructor[] constructors)
+        {
+            Contract.Requires(constructors != null);
+            Contract.Requires(Contract.ForAll(constructors, c => c != null));
+            Contract.Ensures(Contract.Result<DatatypeSort>() != null);
+
+            CheckContextMatch(constructors);
+            return new DatatypeSort(this, MkSymbol(name), constructors);
+        }
+
+        /// <summary>
+        /// Create mutually recursive datatypes.
+        /// </summary>
+        /// <param name="names">names of datatype sorts</param>
+        /// <param name="c">list of constructors, one list per sort.</param>
+        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<DatatypeSort[]>() != 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++)
+            {
+                var 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;
+        }
+
+        /// <summary>
+        ///  Create mutually recursive data-types.
+        /// </summary>
+        /// <param name="names"></param>
+        /// <param name="c"></param>
+        /// <returns></returns>
+        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<DatatypeSort[]>() != null);
+
+            return MkDatatypeSorts(MkSymbols(names), c);
+        }
+
+        #endregion
+        #endregion
+
+        #region Function Declarations
+        /// <summary>
+        /// Creates a new function declaration.
+        /// </summary>
+        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<FuncDecl>() != null);
+
+            CheckContextMatch(name);
+            CheckContextMatch(domain);
+            CheckContextMatch(range);
+            return new FuncDecl(this, name, domain, range);
+        }
+
+        /// <summary>
+        /// Creates a new function declaration.
+        /// </summary>
+        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<FuncDecl>() != null);
+
+            CheckContextMatch(name);
+            CheckContextMatch(domain);
+            CheckContextMatch(range);
+            Sort[] q = new Sort[] { domain };
+            return new FuncDecl(this, name, q, range);
+        }
+
+        /// <summary>
+        /// Creates a new function declaration.
+        /// </summary>
+        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<FuncDecl>() != null);
+
+            CheckContextMatch(domain);
+            CheckContextMatch(range);
+            return new FuncDecl(this, MkSymbol(name), domain, range);
+        }
+
+        /// <summary>
+        /// Creates a new function declaration.
+        /// </summary>
+        public FuncDecl MkFuncDecl(string name, Sort domain, Sort range)
+        {
+            Contract.Requires(range != null);
+            Contract.Requires(domain != null);
+            Contract.Ensures(Contract.Result<FuncDecl>() != null);
+
+            CheckContextMatch(domain);
+            CheckContextMatch(range);
+            Sort[] q = new Sort[] { domain };
+            return new FuncDecl(this, MkSymbol(name), q, range);
+        }
+
+        /// <summary>
+        /// Creates a fresh function declaration with a name prefixed with <paramref name="prefix"/>.
+        /// </summary>
+        /// <seealso cref="MkFuncDecl(string,Sort,Sort)"/>
+        /// <seealso cref="MkFuncDecl(string,Sort[],Sort)"/>
+        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<FuncDecl>() != null);
+
+            CheckContextMatch(domain);
+            CheckContextMatch(range);
+            return new FuncDecl(this, prefix, domain, range);
+        }
+
+        /// <summary>
+        /// Creates a new constant function declaration.
+        /// </summary>
+        public FuncDecl MkConstDecl(Symbol name, Sort range)
+        {
+            Contract.Requires(name != null);
+            Contract.Requires(range != null);
+            Contract.Ensures(Contract.Result<FuncDecl>() != null);
+
+            CheckContextMatch(name);
+            CheckContextMatch(range);
+            return new FuncDecl(this, name, null, range);
+        }
+
+        /// <summary>
+        /// Creates a new constant function declaration.
+        /// </summary>
+        public FuncDecl MkConstDecl(string name, Sort range)
+        {
+            Contract.Requires(range != null);
+            Contract.Ensures(Contract.Result<FuncDecl>() != null);
+
+            CheckContextMatch(range);
+            return new FuncDecl(this, MkSymbol(name), null, range);
+        }
+
+        /// <summary>
+        /// Creates a fresh constant function declaration with a name prefixed with <paramref name="prefix"/>.
+        /// </summary>
+        /// <seealso cref="MkFuncDecl(string,Sort,Sort)"/>
+        /// <seealso cref="MkFuncDecl(string,Sort[],Sort)"/>
+        public FuncDecl MkFreshConstDecl(string prefix, Sort range)
+        {
+            Contract.Requires(range != null);
+            Contract.Ensures(Contract.Result<FuncDecl>() != null);
+
+            CheckContextMatch(range);
+            return new FuncDecl(this, prefix, null, range);
+        }
+        #endregion
+
+        #region Bound Variables
+        /// <summary>
+        /// Creates a new bound variable.
+        /// </summary>
+        /// <param name="index">The de-Bruijn index of the variable</param>
+        /// <param name="ty">The sort of the variable</param>
+        public Expr MkBound(uint index, Sort ty)
+        {
+            Contract.Requires(ty != null);
+            Contract.Ensures(Contract.Result<Expr>() != null);
+
+            return Expr.Create(this, Native.Z3_mk_bound(nCtx, index, ty.NativeObject));
+        }
+        #endregion
+
+        #region Quantifier Patterns
+        /// <summary>
+        /// Create a quantifier pattern.
+        /// </summary>
+        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<Pattern>() != null);
+
+            Contract.EndContractBlock();
+
+            IntPtr[] termsNative = AST.ArrayToNative(terms);
+            return new Pattern(this, Native.Z3_mk_pattern(nCtx, (uint)terms.Length, termsNative));
+        }
+        #endregion
+
+        #region Constants
+        /// <summary>
+        /// Creates a new Constant of sort <paramref name="range"/> and named <paramref name="name"/>.
+        /// </summary>
+        public Expr MkConst(Symbol name, Sort range)
+        {
+            Contract.Requires(name != null);
+            Contract.Requires(range != null);
+            Contract.Ensures(Contract.Result<Expr>() != null);
+
+            CheckContextMatch(name);
+            CheckContextMatch(range);
+
+            return Expr.Create(this, Native.Z3_mk_const(nCtx, name.NativeObject, range.NativeObject));
+        }
+
+        /// <summary>
+        /// Creates a new Constant of sort <paramref name="range"/> and named <paramref name="name"/>.
+        /// </summary>
+        public Expr MkConst(string name, Sort range)
+        {
+            Contract.Requires(range != null);
+            Contract.Ensures(Contract.Result<Expr>() != null);
+
+            return MkConst(MkSymbol(name), range);
+        }
+
+        /// <summary>
+        /// Creates a fresh Constant of sort <paramref name="range"/> and a 
+        /// name prefixed with <paramref name="prefix"/>.
+        /// </summary>
+        public Expr MkFreshConst(string prefix, Sort range)
+        {
+            Contract.Requires(range != null);
+            Contract.Ensures(Contract.Result<Expr>() != null);
+
+            CheckContextMatch(range);
+            return Expr.Create(this, Native.Z3_mk_fresh_const(nCtx, prefix, range.NativeObject));
+        }
+
+        /// <summary>
+        /// Creates a fresh constant from the FuncDecl <paramref name="f"/>.
+        /// </summary>
+        /// <param name="f">A decl of a 0-arity function</param>
+        public Expr MkConst(FuncDecl f)
+        {
+            Contract.Requires(f != null);
+            Contract.Ensures(Contract.Result<Expr>() != null);
+
+            return MkApp(f);
+        }
+
+        /// <summary>
+        /// Create a Boolean constant.
+        /// </summary>        
+        public BoolExpr MkBoolConst(Symbol name)
+        {
+            Contract.Requires(name != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            return (BoolExpr)MkConst(name, BoolSort);
+        }
+
+        /// <summary>
+        /// Create a Boolean constant.
+        /// </summary>        
+        public BoolExpr MkBoolConst(string name)
+        {
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            return (BoolExpr)MkConst(MkSymbol(name), BoolSort);
+        }
+
+        /// <summary>
+        /// Creates an integer constant.
+        /// </summary>        
+        public IntExpr MkIntConst(Symbol name)
+        {
+            Contract.Requires(name != null);
+            Contract.Ensures(Contract.Result<IntExpr>() != null);
+
+            return (IntExpr)MkConst(name, IntSort);
+        }
+
+        /// <summary>
+        /// Creates an integer constant.
+        /// </summary>
+        public IntExpr MkIntConst(string name)
+        {
+            Contract.Requires(name != null);
+            Contract.Ensures(Contract.Result<IntExpr>() != null);
+
+            return (IntExpr)MkConst(name, IntSort);
+        }
+
+        /// <summary>
+        /// Creates a real constant.
+        /// </summary>
+        public RealExpr MkRealConst(Symbol name)
+        {
+            Contract.Requires(name != null);
+            Contract.Ensures(Contract.Result<RealExpr>() != null);
+
+            return (RealExpr)MkConst(name, RealSort);
+        }
+
+        /// <summary>
+        /// Creates a real constant.
+        /// </summary>
+        public RealExpr MkRealConst(string name)
+        {
+            Contract.Ensures(Contract.Result<RealExpr>() != null);
+
+            return (RealExpr)MkConst(name, RealSort);
+        }
+
+        /// <summary>
+        /// Creates a bit-vector constant.
+        /// </summary>
+        public BitVecExpr MkBVConst(Symbol name, uint size)
+        {
+            Contract.Requires(name != null);
+            Contract.Ensures(Contract.Result<BitVecExpr>() != null);
+
+            return (BitVecExpr)MkConst(name, MkBitVecSort(size));
+        }
+
+        /// <summary>
+        /// Creates a bit-vector constant.
+        /// </summary>
+        public BitVecExpr MkBVConst(string name, uint size)
+        {
+            Contract.Ensures(Contract.Result<BitVecExpr>() != null);
+
+            return (BitVecExpr)MkConst(name, MkBitVecSort(size));
+        }
+        #endregion
+
+        #region Terms
+        /// <summary>
+        /// Create a new function application.
+        /// </summary>
+        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<Expr>() != null);
+
+            CheckContextMatch(f);
+            CheckContextMatch(args);
+            return Expr.Create(this, f, args);
+        }
+
+        #region Propositional
+        /// <summary>
+        /// The true Term.
+        /// </summary>    
+        public BoolExpr MkTrue()
+        {
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            return new BoolExpr(this, Native.Z3_mk_true(nCtx));
+        }
+
+        /// <summary>
+        /// The false Term.
+        /// </summary>    
+        public BoolExpr MkFalse()
+        {
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            return new BoolExpr(this, Native.Z3_mk_false(nCtx));
+        }
+
+        /// <summary>
+        /// Creates a Boolean value.
+        /// </summary>        
+        public BoolExpr MkBool(bool value)
+        {
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            return value ? MkTrue() : MkFalse();
+        }
+
+        /// <summary>
+        /// Creates the equality <paramref name="x"/> = <paramref name="y"/>.
+        /// </summary>
+        public BoolExpr MkEq(Expr x, Expr y)
+        {
+            Contract.Requires(x != null);
+            Contract.Requires(y != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(x);
+            CheckContextMatch(y);
+            return new BoolExpr(this, Native.Z3_mk_eq(nCtx, x.NativeObject, y.NativeObject));
+        }
+
+        /// <summary>
+        /// Creates a <c>distinct</c> term.
+        /// </summary>
+        public BoolExpr MkDistinct(params Expr[] args)
+        {
+            Contract.Requires(args != null);
+            Contract.Requires(Contract.ForAll(args, a => a != null));
+
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(args);
+            return new BoolExpr(this, Native.Z3_mk_distinct(nCtx, (uint)args.Length, AST.ArrayToNative(args)));
+        }
+
+        /// <summary>
+        ///  Mk an expression representing <c>not(a)</c>.
+        /// </summary>    
+        public BoolExpr MkNot(BoolExpr a)
+        {
+            Contract.Requires(a != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(a);
+            return new BoolExpr(this, Native.Z3_mk_not(nCtx, a.NativeObject));
+        }
+
+        /// <summary>    
+        ///  Create an expression representing an if-then-else: <c>ite(t1, t2, t3)</c>.
+        /// </summary>
+        /// <param name="t1">An expression with Boolean sort</param>
+        /// <param name="t2">An expression </param>
+        /// <param name="t3">An expression with the same sort as <paramref name="t2"/></param>
+        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<Expr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            CheckContextMatch(t3);
+            return Expr.Create(this, Native.Z3_mk_ite(nCtx, t1.NativeObject, t2.NativeObject, t3.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 iff t2</c>.
+        /// </summary>
+        public BoolExpr MkIff(BoolExpr t1, BoolExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return new BoolExpr(this, Native.Z3_mk_iff(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 -> t2</c>.
+        /// </summary>
+        public BoolExpr MkImplies(BoolExpr t1, BoolExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return new BoolExpr(this, Native.Z3_mk_implies(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 xor t2</c>.
+        /// </summary>
+        public BoolExpr MkXor(BoolExpr t1, BoolExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return new BoolExpr(this, Native.Z3_mk_xor(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t[0] and t[1] and ...</c>.
+        /// </summary>
+        public BoolExpr MkAnd(params BoolExpr[] t)
+        {
+            Contract.Requires(t != null);
+            Contract.Requires(Contract.ForAll(t, a => a != null));
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t);
+            return new BoolExpr(this, Native.Z3_mk_and(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t[0] or t[1] or ...</c>.
+        /// </summary>
+        public BoolExpr MkOr(params BoolExpr[] t)
+        {
+            Contract.Requires(t != null);
+            Contract.Requires(Contract.ForAll(t, a => a != null));
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t);
+            return new BoolExpr(this, Native.Z3_mk_or(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
+        }
+        #endregion
+
+        #region Arithmetic
+        /// <summary>
+        /// Create an expression representing <c>t[0] + t[1] + ...</c>.
+        /// </summary>    
+        public ArithExpr MkAdd(params ArithExpr[] t)
+        {
+            Contract.Requires(t != null);
+            Contract.Requires(Contract.ForAll(t, a => a != null));
+            Contract.Ensures(Contract.Result<ArithExpr>() != null);
+
+            CheckContextMatch(t);
+            return (ArithExpr)Expr.Create(this, Native.Z3_mk_add(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t[0] * t[1] * ...</c>.
+        /// </summary>    
+        public ArithExpr MkMul(params ArithExpr[] t)
+        {
+            Contract.Requires(t != null);
+            Contract.Requires(Contract.ForAll(t, a => a != null));
+            Contract.Ensures(Contract.Result<ArithExpr>() != null);
+
+            CheckContextMatch(t);
+            return (ArithExpr)Expr.Create(this, Native.Z3_mk_mul(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t[0] - t[1] - ...</c>.
+        /// </summary>    
+        public ArithExpr MkSub(params ArithExpr[] t)
+        {
+            Contract.Requires(t != null);
+            Contract.Requires(Contract.ForAll(t, a => a != null));
+            Contract.Ensures(Contract.Result<ArithExpr>() != null);
+
+            CheckContextMatch(t);
+            return (ArithExpr)Expr.Create(this, Native.Z3_mk_sub(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>-t</c>.
+        /// </summary>    
+        public ArithExpr MkUnaryMinus(ArithExpr t)
+        {
+            Contract.Requires(t != null);
+            Contract.Ensures(Contract.Result<ArithExpr>() != null);
+
+            CheckContextMatch(t);
+            return (ArithExpr)Expr.Create(this, Native.Z3_mk_unary_minus(nCtx, t.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 / t2</c>.
+        /// </summary>    
+        public ArithExpr MkDiv(ArithExpr t1, ArithExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<ArithExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return (ArithExpr)Expr.Create(this, Native.Z3_mk_div(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 mod t2</c>.
+        /// </summary>
+        /// <remarks>The arguments must have int type.</remarks>
+        public IntExpr MkMod(IntExpr t1, IntExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<IntExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return new IntExpr(this, Native.Z3_mk_mod(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 rem t2</c>.
+        /// </summary>
+        /// <remarks>The arguments must have int type.</remarks>
+        public IntExpr MkRem(IntExpr t1, IntExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<IntExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return new IntExpr(this, Native.Z3_mk_rem(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 ^ t2</c>.
+        /// </summary>    
+        public ArithExpr MkPower(ArithExpr t1, ArithExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<ArithExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return (ArithExpr)Expr.Create(this, Native.Z3_mk_power(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 &lt; t2</c>
+        /// </summary>    
+        public BoolExpr MkLt(ArithExpr t1, ArithExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return new BoolExpr(this, Native.Z3_mk_lt(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 &lt;= t2</c>
+        /// </summary>    
+        public BoolExpr MkLe(ArithExpr t1, ArithExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return new BoolExpr(this, Native.Z3_mk_le(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 &gt; t2</c>
+        /// </summary>    
+        public BoolExpr MkGt(ArithExpr t1, ArithExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return new BoolExpr(this, Native.Z3_mk_gt(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Create an expression representing <c>t1 &gt;= t2</c>
+        /// </summary>    
+        public BoolExpr MkGe(ArithExpr t1, ArithExpr t2)
+        {
+            Contract.Requires(t1 != null);
+            Contract.Requires(t2 != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t1);
+            CheckContextMatch(t2);
+            return new BoolExpr(this, Native.Z3_mk_ge(nCtx, t1.NativeObject, t2.NativeObject));
+        }
+
+        /// <summary>
+        /// Coerce an integer to a real.
+        /// </summary>
+        /// <remarks>
+        /// 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 <c>k</c> and
+        /// and asserting <c>MakeInt2Real(k) &lt;= t1 &lt; MkInt2Real(k)+1</c>.
+        /// The argument must be of integer sort.
+        /// </remarks>
+        public RealExpr MkInt2Real(IntExpr t)
+        {
+            Contract.Requires(t != null);
+            Contract.Ensures(Contract.Result<RealExpr>() != null);
+
+            CheckContextMatch(t);
+            return new RealExpr(this, Native.Z3_mk_int2real(nCtx, t.NativeObject));
+        }
+
+        /// <summary>
+        /// Coerce a real to an integer.
+        /// </summary>
+        /// <remarks>
+        /// The semantics of this function follows the SMT-LIB standard for the function to_int.
+        /// The argument must be of real sort.
+        /// </remarks>
+        public IntExpr MkReal2Int(RealExpr t)
+        {
+            Contract.Requires(t != null);
+            Contract.Ensures(Contract.Result<IntExpr>() != null);
+
+            CheckContextMatch(t);
+            return new IntExpr(this, Native.Z3_mk_real2int(nCtx, t.NativeObject));
+        }
+
+        /// <summary>
+        /// Creates an expression that checks whether a real number is an integer.
+        /// </summary>
+        public BoolExpr MkIsInteger(RealExpr t)
+        {
+            Contract.Requires(t != null);
+            Contract.Ensures(Contract.Result<BoolExpr>() != null);
+
+            CheckContextMatch(t);
+            return new BoolExpr(this, Native.Z3_mk_is_int(nCtx, t.NativeObject));
+        }
+        #endregion
+
+        #region Bit-vectors
+        /// <summary>
+        /// Bitwise negation.
+        /// </summary>
+        /// <remarks>The argument must have a bit-vector sort.</remarks>
+        public BitVecExpr MkBVNot(BitVecExpr t)
+        {
+            Contract.Requires(t != null);
+            Contract.Ensures(Contract.Result<BitVecExpr>() != null);
+
+            CheckContextMatch(t);
+            return new BitVecExpr(this, Native.Z3_mk_bvnot(nCtx, t.NativeObject));
+        }
+
+        /// <summary>
+        /// Take conjunction of bits in a vector, return vector of length 1.
+        /// </summary>