diff --git a/scripts/mk_util.py b/scripts/mk_util.py index bf28d06bd..d62a2c3a3 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -519,6 +519,9 @@ def get_c_files(path): def get_cs_files(path): return filter(lambda f: f.endswith('.cs'), os.listdir(path)) +def get_java_files(path): + return filter(lambda f: f.endswith('.java'), os.listdir(path)) + def find_all_deps(name, deps): new_deps = [] for dep in deps: @@ -957,20 +960,20 @@ class JavaDLLComponent(Component): def mk_makefile(self, out): if is_java_enabled(): - dllfile = '%s$(SO_EXT)' % self.dll_name - out.write('%s: %s/Z3Native.java %s$(SO_EXT)\n' % (dllfile, self.to_src_dir, get_component('api_dll').dll_name)) - if IS_WINDOWS: - out.write('\tcd %s && %s Z3Native.java\n' % (unix_path2dos(self.to_src_dir), JAVAC)) - out.write('\tmove %s\\*.class .\n' % unix_path2dos(self.to_src_dir)) - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)Z3Native$(OBJ_EXT) -I"%s/include" -I"%s/include/win32" -I%s %s/Z3Native.c\n' % (JAVA_HOME, JAVA_HOME, get_component('api').to_src_dir, self.to_src_dir)) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) Z3Native$(OBJ_EXT) libz3.lib\n' % dllfile) - else: - out.write('\tcd %s; %s Z3Native.java\n' % (self.to_src_dir, JAVAC)) - out.write('\tmv %s/*.class .\n' % self.to_src_dir) - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)Z3Native$(OBJ_EXT) -I"%s/include" -I%s %s/Z3Native.c\n' % (JAVA_HOME, get_component('api').to_src_dir, self.to_src_dir)) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) -L. Z3Native$(OBJ_EXT) -lz3\n' % dllfile) - out.write('%s: %s\n\n' % (self.name, dllfile)) - # TODO: Compile and package all the .class files. + dllfile = '%s$(SO_EXT)' % self.dll_name + out.write('libz3java$(SO_EXT): libz3$(SO_EXT) ../src/api/java/Native.cpp\n') + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)Native$(OBJ_EXT) -I"%s/include" -I"%s/include/win32" -I%s %s/Native.cpp\n' % (JAVA_HOME, JAVA_HOME, get_component('api').to_src_dir, self.to_src_dir)) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3java$(SO_EXT) $(SLINK_FLAGS) Native$(OBJ_EXT) libz3.lib\n') + out.write('%s.jar: libz3java$(SO_EXT) ' % self.package_name) + # for java_file in get_java_files(self.src_dir): + # out.write('%s ' % java_file) + # for java_file in get_java_files((self.src_dir + "/%s/Enumerations") % subdir): + # out.write('%s ' % java_file) + out.write('\n') + out.write(('\t%s %s/Enumerations/*.java -d api/java\n' % (JAVAC, self.to_src_dir)).replace("/","\\")) + out.write(('\t%s -cp api/java %s/*.java -d api/java\n' % (JAVAC, self.to_src_dir)).replace("/","\\")) + out.write('\tjar cf %s.jar api/java/\n' % self.package_name) + out.write('java: %s.jar\n\n' % self.package_name) def main_component(self): return is_java_enabled() @@ -1822,7 +1825,7 @@ def mk_z3consts_java(api_files): java = get_component(JAVA_COMPONENT) DeprecatedEnums = [ 'Z3_search_failure' ] - gendir = java.src_dir + "/" + java.package_name.replace(".", "/") + "/Enumerations" + gendir = java.src_dir + "/Enumerations" if not os.path.exists(gendir): os.mkdir(gendir) @@ -1873,15 +1876,32 @@ def mk_z3consts_java(api_files): if name not in DeprecatedEnums: efile = open('%s/%s.java' % (gendir, name), 'w') efile.write('/**\n * Automatically generated file\n **/\n\n') - efile.write('package %s;\n\n' % java.package_name); + efile.write('package %s.Enumerations;\n\n' % java.package_name); efile.write('/**\n') efile.write(' * %s\n' % name) efile.write(' **/\n') efile.write('public enum %s {\n' % name) efile.write + first = True for k, i in decls.iteritems(): - efile.write('%s (%s),\n' % (k, i)) + if first: + first = False + else: + efile.write(',\n') + efile.write(' %s (%s)' % (k, i)) + efile.write(";\n") + efile.write('\n private final int intValue;\n\n') + efile.write(' %s(int v) {\n' % name) + efile.write(' this.intValue = v;\n') + efile.write(' }\n\n') + efile.write(' public static final %s fromInt(int v) {\n' % name) + efile.write(' for (%s k: values()) \n' % name) + efile.write(' if (k.intValue == v) return k;\n') + efile.write(' return values()[0];\n') + efile.write(' }\n\n') + efile.write(' public final int toInt() { return this.intValue; }\n') + # efile.write(';\n %s(int v) {}\n' % name) efile.write('}\n\n') efile.close() mode = SEARCHING diff --git a/scripts/update_api.py b/scripts/update_api.py index 7e1439375..da760fbea 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -252,11 +252,11 @@ def param2java(p): k = param_kind(p) if k == OUT: if param_type(p) == INT or param_type(p) == UINT: - return "Integer" + return "IntPtr" elif param_type(p) == INT64 or param_type(p) == UINT64 or param_type(p) >= FIRST_OBJ_ID: - return "Long" + return "LongPtr" elif param_type(p) == STRING: - return "String" + return "StringPtr" else: print "ERROR: unreachable code" assert(False) @@ -496,19 +496,16 @@ def mk_java(): if not is_java_enabled(): return java_dir = get_component('java').src_dir - try: - os.mkdir('%s/com/Microsoft/Z3/' % java_dir) - except: - pass # OK if it exists already. - java_nativef = '%s/com/Microsoft/Z3/Native.java' % java_dir - java_wrapperf = '%s/com/Microsoft/Z3/Native.c' % java_dir + java_nativef = '%s/Native.java' % java_dir + java_wrapperf = '%s/Native.cpp' % java_dir java_native = open(java_nativef, 'w') java_native.write('// Automatically generated file\n') - java_native.write('package com.Microsoft.Z3;\n') + java_native.write('package %s;\n' % get_component('java').package_name) java_native.write('public final class Native {\n') java_native.write(' public static class IntPtr { public int value; }\n') java_native.write(' public static class LongPtr { public long value; }\n') java_native.write(' public static class StringPtr { public String value; }\n') + java_native.write(' public static class errorHandler { public long ptr; }\n') if is_windows(): java_native.write(' static { System.loadLibrary("%s"); }\n' % get_component('java')) diff --git a/src/api/dotnet/BitVecSort.cs b/src/api/dotnet/BitVecSort.cs index 55ef4ae49..d865159f4 100644 --- a/src/api/dotnet/BitVecSort.cs +++ b/src/api/dotnet/BitVecSort.cs @@ -37,7 +37,6 @@ namespace Microsoft.Z3 #region Internal internal BitVecSort(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); } - internal BitVecSort(Context ctx, uint size) : base(ctx, Native.Z3_mk_bv_sort(ctx.nCtx, size)) { Contract.Requires(ctx != null); } #endregion }; } diff --git a/src/api/dotnet/Context.cs b/src/api/dotnet/Context.cs index 2aea1586c..3e438d69d 100644 --- a/src/api/dotnet/Context.cs +++ b/src/api/dotnet/Context.cs @@ -193,7 +193,7 @@ namespace Microsoft.Z3 { Contract.Ensures(Contract.Result() != null); - return new BitVecSort(this, size); + return new BitVecSort(this, Native.Z3_mk_bv_sort(nCtx, size)); } /// @@ -388,7 +388,7 @@ namespace Microsoft.Z3 IntPtr[] n_constr = new IntPtr[n]; for (uint i = 0; i < n; i++) { - var constructor = c[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); diff --git a/src/api/dotnet/Expr.cs b/src/api/dotnet/Expr.cs index 22a506c71..dade77eb1 100644 --- a/src/api/dotnet/Expr.cs +++ b/src/api/dotnet/Expr.cs @@ -433,7 +433,8 @@ namespace Microsoft.Z3 get { return (Native.Z3_is_app(Context.nCtx, NativeObject) != 0 && - (Z3_sort_kind)Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == Z3_sort_kind.Z3_ARRAY_SORT); + (Z3_sort_kind)Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) + == Z3_sort_kind.Z3_ARRAY_SORT); } } @@ -1308,7 +1309,8 @@ namespace Microsoft.Z3 get { return (Native.Z3_is_app(Context.nCtx, NativeObject) != 0 && - (Z3_sort_kind)Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == Z3_sort_kind.Z3_RELATION_SORT); + Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) + == (uint)Z3_sort_kind.Z3_RELATION_SORT); } } @@ -1429,7 +1431,7 @@ namespace Microsoft.Z3 get { return (Native.Z3_is_app(Context.nCtx, NativeObject) != 0 && - (Z3_sort_kind)Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == Z3_sort_kind.Z3_FINITE_DOMAIN_SORT); + Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == (uint)Z3_sort_kind.Z3_FINITE_DOMAIN_SORT); } } @@ -1489,8 +1491,8 @@ namespace Microsoft.Z3 internal override void CheckNativeObject(IntPtr obj) { if (Native.Z3_is_app(Context.nCtx, obj) == 0 && - (Z3_ast_kind)Native.Z3_get_ast_kind(Context.nCtx, obj) != Z3_ast_kind.Z3_VAR_AST && - (Z3_ast_kind)Native.Z3_get_ast_kind(Context.nCtx, obj) != Z3_ast_kind.Z3_QUANTIFIER_AST) + Native.Z3_get_ast_kind(Context.nCtx, obj) != (uint)Z3_ast_kind.Z3_VAR_AST && + Native.Z3_get_ast_kind(Context.nCtx, obj) != (uint)Z3_ast_kind.Z3_QUANTIFIER_AST) throw new Z3Exception("Underlying object is not a term"); base.CheckNativeObject(obj); } @@ -1531,6 +1533,7 @@ namespace Microsoft.Z3 case Z3_sort_kind.Z3_INT_SORT: return new IntNum(ctx, obj); case Z3_sort_kind.Z3_REAL_SORT: return new RatNum(ctx, obj); case Z3_sort_kind.Z3_BV_SORT: return new BitVecNum(ctx, obj); + case Z3_sort_kind.Z3_UNKNOWN_SORT: throw new Z3Exception("Unknown Sort"); } } @@ -1542,6 +1545,7 @@ namespace Microsoft.Z3 case Z3_sort_kind.Z3_BV_SORT: return new BitVecExpr(ctx, obj); case Z3_sort_kind.Z3_ARRAY_SORT: return new ArrayExpr(ctx, obj); case Z3_sort_kind.Z3_DATATYPE_SORT: return new DatatypeExpr(ctx, obj); + case Z3_sort_kind.Z3_UNKNOWN_SORT: throw new Z3Exception("Unknown Sort"); } return new Expr(ctx, obj); diff --git a/src/api/dotnet/FuncDecl.cs b/src/api/dotnet/FuncDecl.cs index 37929e88f..15b6a59db 100644 --- a/src/api/dotnet/FuncDecl.cs +++ b/src/api/dotnet/FuncDecl.cs @@ -110,7 +110,7 @@ namespace Microsoft.Z3 { Contract.Ensures(Contract.Result() != null); - var n = DomainSize; + uint n = DomainSize; Sort[] res = new Sort[n]; for (uint i = 0; i < n; i++) diff --git a/src/api/dotnet/Goal.cs b/src/api/dotnet/Goal.cs index 6a0b253bb..e648ac80c 100644 --- a/src/api/dotnet/Goal.cs +++ b/src/api/dotnet/Goal.cs @@ -184,10 +184,10 @@ namespace Microsoft.Z3 { Tactic t = Context.MkTactic("simplify"); ApplyResult res = t.Apply(this, p); - + if (res.NumSubgoals == 0) - return Context.MkGoal(); - else + throw new Z3Exception("No subgoals"); + else return res.Subgoals[0]; } diff --git a/src/api/dotnet/Model.cs b/src/api/dotnet/Model.cs index 5529677dd..5c0bc24f8 100644 --- a/src/api/dotnet/Model.cs +++ b/src/api/dotnet/Model.cs @@ -165,8 +165,8 @@ namespace Microsoft.Z3 { Contract.Ensures(Contract.Result() != null); - var nFuncs = NumFuncs; - var nConsts = NumConsts; + uint nFuncs = NumFuncs; + uint nConsts = NumConsts; uint n = nFuncs + nConsts; FuncDecl[] res = new FuncDecl[n]; for (uint i = 0; i < nConsts; i++) diff --git a/src/api/dotnet/Quantifier.cs b/src/api/dotnet/Quantifier.cs index c6754e570..f59d0bda2 100644 --- a/src/api/dotnet/Quantifier.cs +++ b/src/api/dotnet/Quantifier.cs @@ -181,8 +181,6 @@ namespace Microsoft.Z3 if (sorts.Length != names.Length) throw new Z3Exception("Number of sorts does not match number of names"); - IntPtr[] _patterns = AST.ArrayToNative(patterns); - if (noPatterns == null && quantifierID == null && skolemID == null) { NativeObject = Native.Z3_mk_quantifier(ctx.nCtx, (isForall) ? 1 : 0, weight, diff --git a/src/api/java/AST.java b/src/api/java/AST.java new file mode 100644 index 000000000..e8017e020 --- /dev/null +++ b/src/api/java/AST.java @@ -0,0 +1,228 @@ +/** + * This file was automatically generated from AST.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * The abstract syntax tree (AST) class. + **/ +public class AST extends Z3Object +{ + /** + * Comparison operator. An AST An + * AST + * + * @return True if and are from + * the same context and represent the same sort; false otherwise. + **/ + /* Overloaded operators are not translated. */ + + /** + * Comparison operator. An AST An + * AST + * + * @return True if and are not + * from the same context or represent different sorts; false + * otherwise. + **/ + /* Overloaded operators are not translated. */ + + /** + * Object comparison. + **/ + public boolean Equals(Object o) + { + AST casted = (AST) o; + if (casted == null) + return false; + return this == casted; + } + + /** + * Object Comparison. Another AST + * + * @return Negative if the object should be sorted before , positive if after else zero. + **/ + public int CompareTo(Object other) throws Z3Exception + { + if (other == null) + return 1; + AST oAST = (AST) other; + if (oAST == null) + return 1; + else + { + if (Id() < oAST.Id()) + return -1; + else if (Id() > oAST.Id()) + return +1; + else + return 0; + } + } + + /** + * The AST's hash code. + * + * @return A hash code + **/ + public int GetHashCode() throws Z3Exception + { + return (int) Native.getAstHash(Context().nCtx(), NativeObject()); + } + + /** + * A unique identifier for the AST (unique among all ASTs). + **/ + public int Id() throws Z3Exception + { + return Native.getAstId(Context().nCtx(), NativeObject()); + } + + /** + * Translates (copies) the AST to the Context . A context + * + * @return A copy of the AST which is associated with + **/ + public AST Translate(Context ctx) throws Z3Exception + { + + if (Context() == ctx) + return this; + else + return new AST(ctx, Native.translate(Context().nCtx(), + NativeObject(), ctx.nCtx())); + } + + /** + * The kind of the AST. + **/ + public Z3_ast_kind ASTKind() + { + return Z3_ast_kind.fromInt(Native.getAstKind(Context().nCtx(), + NativeObject())); + } + + /** + * Indicates whether the AST is an Expr + **/ + public boolean IsExpr() throws Z3Exception + { + switch (ASTKind()) + { + case Z3_APP_AST: + case Z3_NUMERAL_AST: + case Z3_QUANTIFIER_AST: + case Z3_VAR_AST: + return true; + default: + return false; + } + } + + /** + * Indicates whether the AST is a BoundVariable + **/ + public boolean IsVar() throws Z3Exception + { + return this.ASTKind() == Z3_ast_kind.Z3_VAR_AST; + } + + /** + * Indicates whether the AST is a Quantifier + **/ + public boolean IsQuantifier() throws Z3Exception + { + return this.ASTKind() == Z3_ast_kind.Z3_QUANTIFIER_AST; + } + + /** + * Indicates whether the AST is a Sort + **/ + public boolean IsSort() throws Z3Exception + { + return this.ASTKind() == Z3_ast_kind.Z3_SORT_AST; + } + + /** + * Indicates whether the AST is a FunctionDeclaration + **/ + public boolean IsFuncDecl() throws Z3Exception + { + return this.ASTKind() == Z3_ast_kind.Z3_FUNC_DECL_AST; + } + + /** + * A string representation of the AST. + **/ + public String toString() + { + return Native.astToString(Context().nCtx(), NativeObject()); + } + + /** + * A string representation of the AST in s-expression notation. + **/ + public String SExpr() throws Z3Exception + { + return Native.astToString(Context().nCtx(), NativeObject()); + } + + AST(Context ctx) + { + super(ctx); + } + + AST(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + void IncRef(long o) throws Z3Exception + { + // Console.WriteLine("AST IncRef()"); + if (Context() == null) + throw new Z3Exception("inc() called on null context"); + if (o == 0) + throw new Z3Exception("inc() called on null AST"); + Context().AST_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + // Console.WriteLine("AST DecRef()"); + if (Context() == null) + throw new Z3Exception("dec() called on null context"); + if (o == 0) + throw new Z3Exception("dec() called on null AST"); + Context().AST_DRQ().Add(o); + super.DecRef(o); + } + + static AST Create(Context ctx, long obj) throws Z3Exception + { + switch (Z3_ast_kind.fromInt(Native.getAstKind(ctx.nCtx(), obj))) + { + case Z3_FUNC_DECL_AST: + return new FuncDecl(ctx, obj); + case Z3_QUANTIFIER_AST: + return new Quantifier(ctx, obj); + case Z3_SORT_AST: + return Sort.Create(ctx, obj); + case Z3_APP_AST: + case Z3_NUMERAL_AST: + case Z3_VAR_AST: + return Expr.Create(ctx, obj); + default: + throw new Z3Exception("Unknown AST kind"); + } + } +} diff --git a/src/api/java/ASTDecRefQueue.java b/src/api/java/ASTDecRefQueue.java new file mode 100644 index 000000000..1672dc14c --- /dev/null +++ b/src/api/java/ASTDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +public class ASTDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.incRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.decRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/ASTMap.java b/src/api/java/ASTMap.java new file mode 100644 index 000000000..51d4e02bb --- /dev/null +++ b/src/api/java/ASTMap.java @@ -0,0 +1,116 @@ +/** + * This file was automatically generated from ASTMap.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Map from AST to AST + **/ +class ASTMap extends Z3Object +{ + /** + * Checks whether the map contains the key . An AST + * + * @return True if is a key in the map, false + * otherwise. + **/ + public boolean Contains(AST k) + { + + return Native.astMapContains(Context().nCtx(), NativeObject(), + k.NativeObject()); + } + + /** + * Finds the value associated with the key . + * This function signs an error when is not a key in + * the map. An AST + * @throws Z3Exception + **/ + public AST Find(AST k) throws Z3Exception + { + return new AST(Context(), Native.astMapFind(Context().nCtx(), + NativeObject(), k.NativeObject())); + } + + /** + * Stores or replaces a new key/value pair in the map. The + * key AST The value AST + **/ + public void Insert(AST k, AST v) + { + + Native.astMapInsert(Context().nCtx(), NativeObject(), k.NativeObject(), + v.NativeObject()); + } + + /** + * Erases the key from the map. An + * AST + **/ + public void Erase(AST k) + { + + Native.astMapErase(Context().nCtx(), NativeObject(), k.NativeObject()); + } + + /** + * Removes all keys from the map. + **/ + public void Reset() + { + Native.astMapReset(Context().nCtx(), NativeObject()); + } + + /** + * The size of the map + **/ + public int Size() + { + return Native.astMapSize(Context().nCtx(), NativeObject()); + } + + /** + * The keys stored in the map. + * @throws Z3Exception + **/ + public ASTVector Keys() throws Z3Exception + { + return new ASTVector(Context(), Native.astMapKeys(Context().nCtx(), + NativeObject())); + } + + /** + * Retrieves a string representation of the map. + **/ + public String toString() + { + return Native.astMapToString(Context().nCtx(), NativeObject()); + } + + ASTMap(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + ASTMap(Context ctx) throws Z3Exception + { + super(ctx, Native.mkAstMap(ctx.nCtx())); + } + + void IncRef(long o) throws Z3Exception + { + Context().ASTMap_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().ASTMap_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/ASTVector.java b/src/api/java/ASTVector.java new file mode 100644 index 000000000..7451e93b3 --- /dev/null +++ b/src/api/java/ASTVector.java @@ -0,0 +1,104 @@ +/** + * This file was automatically generated from ASTVector.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Vectors of ASTs. + **/ +class ASTVector extends Z3Object +{ + /** + * The size of the vector + **/ + public int Size() + { + return Native.astVectorSize(Context().nCtx(), NativeObject()); + } + + /** + * Retrieves the i-th object in the vector. May throw an + * IndexOutOfBoundsException when is out of + * range. Index + * + * @return An AST + * @throws Z3Exception + **/ + public AST get(int i) throws Z3Exception + { + return new AST(Context(), Native.astVectorGet(Context().nCtx(), + NativeObject(), i)); + } + + public void set(int i, AST value) + { + + Native.astVectorSet(Context().nCtx(), NativeObject(), i, + value.NativeObject()); + } + + /** + * Resize the vector to . The new size of the vector. + **/ + public void Resize(int newSize) + { + Native.astVectorResize(Context().nCtx(), NativeObject(), newSize); + } + + /** + * Add the AST to the back of the vector. The size is + * increased by 1. An AST + **/ + public void Push(AST a) + { + + Native.astVectorPush(Context().nCtx(), NativeObject(), a.NativeObject()); + } + + /** + * Translates all ASTs in the vector to . A context + * + * @return A new ASTVector + * @throws Z3Exception + **/ + public ASTVector Translate(Context ctx) throws Z3Exception + { + return new ASTVector(Context(), Native.astVectorTranslate(Context() + .nCtx(), NativeObject(), ctx.nCtx())); + } + + /** + * Retrieves a string representation of the vector. + **/ + public String toString() + { + return Native.astVectorToString(Context().nCtx(), NativeObject()); + } + + ASTVector(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + ASTVector(Context ctx) throws Z3Exception + { + super(ctx, Native.mkAstVector(ctx.nCtx())); + } + + void IncRef(long o) throws Z3Exception + { + Context().ASTVector_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().ASTVector_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/AlgebraicNum.java b/src/api/java/AlgebraicNum.java new file mode 100644 index 000000000..2ed2d8315 --- /dev/null +++ b/src/api/java/AlgebraicNum.java @@ -0,0 +1,59 @@ +/** + * This file was automatically generated from AlgebraicNum.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Algebraic numbers + **/ +public class AlgebraicNum extends ArithExpr +{ + /** + * Return a upper bound for a given real algebraic number. The interval + * isolating the number is smaller than 1/10^. + * the + * precision of the result + * + * @return A numeral Expr of sort Real + **/ + public RatNum ToUpper(int precision) throws Z3Exception + { + + return new RatNum(Context(), Native.getAlgebraicNumberUpper(Context() + .nCtx(), NativeObject(), precision)); + } + + /** + * Return a lower bound for the given real algebraic number. The interval + * isolating the number is smaller than 1/10^. + * + * + * @return A numeral Expr of sort Real + **/ + public RatNum ToLower(int precision) throws Z3Exception + { + + return new RatNum(Context(), Native.getAlgebraicNumberLower(Context() + .nCtx(), NativeObject(), precision)); + } + + /** + * Returns a string representation in decimal notation. The result + * has at most decimal places. + **/ + public String ToDecimal(int precision) throws Z3Exception + { + + return Native.getNumeralDecimalString(Context().nCtx(), NativeObject(), + precision); + } + + AlgebraicNum(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + + } +} diff --git a/src/api/java/ApplyResult.java b/src/api/java/ApplyResult.java new file mode 100644 index 000000000..afcc3f0f7 --- /dev/null +++ b/src/api/java/ApplyResult.java @@ -0,0 +1,75 @@ +/** + * This file was automatically generated from ApplyResult.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * ApplyResult objects represent the result of an application of a tactic to a + * goal. It contains the subgoals that were produced. + **/ +public class ApplyResult extends Z3Object +{ + /** + * The number of Subgoals. + **/ + public int NumSubgoals() + { + return Native.applyResultGetNumSubgoals(Context().nCtx(), + NativeObject()); + } + + /** + * Retrieves the subgoals from the ApplyResult. + * @throws Z3Exception + **/ + public Goal[] Subgoals() throws Z3Exception + { + int n = NumSubgoals(); + Goal[] res = new Goal[n]; + for (int i = 0; i < n; i++) + res[i] = new Goal(Context(), Native.applyResultGetSubgoal(Context() + .nCtx(), NativeObject(), i)); + return res; + } + + /** + * Convert a model for the subgoal into a model for the + * original goal g, that the ApplyResult was obtained from. + * + * @return A model for g + * @throws Z3Exception + **/ + public Model ConvertModel(int i, Model m) throws Z3Exception + { + return new Model(Context(), Native.applyResultConvertModel(Context() + .nCtx(), NativeObject(), i, m.NativeObject())); + } + + /** + * A string representation of the ApplyResult. + **/ + public String toString() + { + return Native.applyResultToString(Context().nCtx(), NativeObject()); + } + + ApplyResult(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + void IncRef(long o) throws Z3Exception + { + Context().ApplyResult_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().ApplyResult_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/ApplyResultDecRefQueue.java b/src/api/java/ApplyResultDecRefQueue.java new file mode 100644 index 000000000..98d727522 --- /dev/null +++ b/src/api/java/ApplyResultDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class ApplyResultDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.applyResultIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.applyResultDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/ArithExpr.java b/src/api/java/ArithExpr.java new file mode 100644 index 000000000..c15cf212e --- /dev/null +++ b/src/api/java/ArithExpr.java @@ -0,0 +1,26 @@ +/** + * This file was automatically generated from ArithExpr.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + * **/ + +package com.Microsoft.Z3; + +/** + * Arithmetic expressions (int/real) + **/ +public class ArithExpr extends Expr +{ + /** + * Constructor for ArithExpr + **/ + protected ArithExpr(Context ctx) + { + super(ctx); + } + + ArithExpr(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/ArithSort.java b/src/api/java/ArithSort.java new file mode 100644 index 000000000..bcaf5a88f --- /dev/null +++ b/src/api/java/ArithSort.java @@ -0,0 +1,18 @@ +/** + * This file was automatically generated from ArithSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * An arithmetic sort, i.e., Int or Real. + **/ +public class ArithSort extends Sort +{ + ArithSort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +}; diff --git a/src/api/java/ArrayExpr.java b/src/api/java/ArrayExpr.java new file mode 100644 index 000000000..7082bc64b --- /dev/null +++ b/src/api/java/ArrayExpr.java @@ -0,0 +1,27 @@ +/** + * This file was automatically generated from ArrayExpr.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + + +/** + * Array expressions + **/ +public class ArrayExpr extends Expr +{ + /** + * Constructor for ArrayExpr + **/ + protected ArrayExpr(Context ctx) + { + super(ctx); + } + + ArrayExpr(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/ArraySort.java b/src/api/java/ArraySort.java new file mode 100644 index 000000000..2b7979468 --- /dev/null +++ b/src/api/java/ArraySort.java @@ -0,0 +1,44 @@ +/** + * This file was automatically generated from ArraySort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Array sorts. + **/ +public class ArraySort extends Sort +{ + /** + * The domain of the array sort. + * @throws Z3Exception + **/ + public Sort Domain() throws Z3Exception + { + return Sort.Create(Context(), + Native.getArraySortDomain(Context().nCtx(), NativeObject())); + } + + /** + * The range of the array sort. + * @throws Z3Exception + **/ + public Sort Range() throws Z3Exception + { + return Sort.Create(Context(), + Native.getArraySortRange(Context().nCtx(), NativeObject())); + } + + ArraySort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + ArraySort(Context ctx, Sort domain, Sort range) throws Z3Exception + { + super(ctx, Native.mkArraySort(ctx.nCtx(), domain.NativeObject(), + range.NativeObject())); + } +}; diff --git a/src/api/java/AstMapDecRefQueue.java b/src/api/java/AstMapDecRefQueue.java new file mode 100644 index 000000000..a6232866f --- /dev/null +++ b/src/api/java/AstMapDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class ASTMapDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.astMapIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.astMapDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/AstVectorDecRefQueue.java b/src/api/java/AstVectorDecRefQueue.java new file mode 100644 index 000000000..013cc5351 --- /dev/null +++ b/src/api/java/AstVectorDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class ASTVectorDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.astVectorIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.astVectorDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/BitVecExpr.java b/src/api/java/BitVecExpr.java new file mode 100644 index 000000000..cd64cfc82 --- /dev/null +++ b/src/api/java/BitVecExpr.java @@ -0,0 +1,36 @@ +/** + * This file was automatically generated from BitVecExpr.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Bit-vector expressions + **/ +public class BitVecExpr extends Expr +{ + + /** + * The size of the sort of a bit-vector term. + * @throws Z3Exception + **/ + public int SortSize() throws Z3Exception + { + return ((BitVecSort) Sort()).Size(); + } + + /** + * Constructor for BitVecExpr + **/ + protected BitVecExpr(Context ctx) + { + super(ctx); + } + + BitVecExpr(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/BitVecNum.java b/src/api/java/BitVecNum.java new file mode 100644 index 000000000..b1f12fae5 --- /dev/null +++ b/src/api/java/BitVecNum.java @@ -0,0 +1,62 @@ +/** + * This file was automatically generated from BitVecNum.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import java.math.BigInteger; + +/** + * Bit-vector numerals + **/ +public class BitVecNum extends BitVecExpr +{ + /** + * Retrieve the int value. + * + * @throws Z3Exception + **/ + public int Int() throws Z3Exception + { + Native.IntPtr res = new Native.IntPtr(); + if (Native.getNumeralInt(Context().nCtx(), NativeObject(), res) ^ true) + throw new Z3Exception("Numeral is not an int"); + return res.value; + } + + /** + * Retrieve the 64-bit int value. + * + * @throws Z3Exception + **/ + public long Long() throws Z3Exception + { + Native.LongPtr res = new Native.LongPtr(); + if (Native.getNumeralInt64(Context().nCtx(), NativeObject(), res) ^ true) + throw new Z3Exception("Numeral is not an int64"); + return res.value; + } + + /** + * Retrieve the BigInteger value. + **/ + public BigInteger BigInteger() + { + return new BigInteger(this.toString()); + } + + /** + * Returns a string representation of the numeral. + **/ + public String toString() + { + return Native.getNumeralString(Context().nCtx(), NativeObject()); + } + + BitVecNum(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/BitVecSort.java b/src/api/java/BitVecSort.java new file mode 100644 index 000000000..8ce31e7bb --- /dev/null +++ b/src/api/java/BitVecSort.java @@ -0,0 +1,25 @@ +/** + * This file was automatically generated from BitVecSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ +package com.Microsoft.Z3; + +/** + * Bit-vector sorts. + **/ +public class BitVecSort extends Sort +{ + /** + * The size of the bit-vector sort. + **/ + public int Size() + { + return Native.getBvSortSize(Context().nCtx(), NativeObject()); + } + + BitVecSort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +}; diff --git a/src/api/java/BoolExpr.java b/src/api/java/BoolExpr.java new file mode 100644 index 000000000..ddabc81d9 --- /dev/null +++ b/src/api/java/BoolExpr.java @@ -0,0 +1,30 @@ +/** + * This file was automatically generated from BoolExpr.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Boolean expressions + **/ +public class BoolExpr extends Expr +{ + /** + * Constructor for BoolExpr + **/ + protected BoolExpr(Context ctx) + { + super(ctx); + } + + /** + * Constructor for BoolExpr + * @throws Z3Exception + **/ + BoolExpr(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/BoolSort.java b/src/api/java/BoolSort.java new file mode 100644 index 000000000..501467bfc --- /dev/null +++ b/src/api/java/BoolSort.java @@ -0,0 +1,16 @@ +/** + * This file was automatically generated from BoolSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * A Boolean sort. + **/ +public class BoolSort extends Sort +{ + BoolSort(Context ctx, long obj) throws Z3Exception { super(ctx, obj); { }} + BoolSort(Context ctx) throws Z3Exception { super(ctx, Native.mkBoolSort(ctx.nCtx())); { }} +}; diff --git a/src/api/java/Constructor.java b/src/api/java/Constructor.java new file mode 100644 index 000000000..146c7daa0 --- /dev/null +++ b/src/api/java/Constructor.java @@ -0,0 +1,107 @@ +/** + * This file was automatically generated from Constructor.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Constructors are used for datatype sorts. + **/ +public class Constructor extends Z3Object +{ + /** + * The number of fields of the constructor. + * @throws Z3Exception + **/ + public int NumFields() throws Z3Exception + { + init(); + return n; + } + + /** + * The function declaration of the constructor. + * @throws Z3Exception + **/ + public FuncDecl ConstructorDecl() throws Z3Exception + { + init(); + return m_constructorDecl; + } + + /** + * The function declaration of the tester. + * @throws Z3Exception + **/ + public FuncDecl TesterDecl() throws Z3Exception + { + init(); + return m_testerDecl; + } + + /** + * The function declarations of the accessors + * @throws Z3Exception + **/ + public FuncDecl[] AccessorDecls() throws Z3Exception + { + init(); + return m_accessorDecls; + } + + /** + * Destructor. + **/ + protected void finalize() + { + Native.delConstructor(Context().nCtx(), NativeObject()); + } + + private int n = 0; + private FuncDecl m_testerDecl = null; + private FuncDecl m_constructorDecl = null; + private FuncDecl[] m_accessorDecls = null; + + Constructor(Context ctx, Symbol name, Symbol recognizer, + Symbol[] fieldNames, Sort[] sorts, int[] sortRefs) + throws Z3Exception + { + super(ctx); + + 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 int[n]; + + setNativeObject(Native.mkConstructor(ctx.nCtx(), name.NativeObject(), + recognizer.NativeObject(), n, Symbol.ArrayToNative(fieldNames), + Sort.ArrayToNative(sorts), sortRefs)); + + } + + private void init() throws Z3Exception + { + if (m_testerDecl != null) + return; + Native.LongPtr constructor = new Native.LongPtr(); + Native.LongPtr tester = new Native.LongPtr(); + long[] accessors = new long[n]; + Native.queryConstructor(Context().nCtx(), NativeObject(), n, + constructor, tester, accessors); + m_constructorDecl = new FuncDecl(Context(), constructor.value); + m_testerDecl = new FuncDecl(Context(), tester.value); + m_accessorDecls = new FuncDecl[n]; + for (int i = 0; i < n; i++) + m_accessorDecls[i] = new FuncDecl(Context(), accessors[i]); + } + +} diff --git a/src/api/java/ConstructorList.java b/src/api/java/ConstructorList.java new file mode 100644 index 000000000..a158240eb --- /dev/null +++ b/src/api/java/ConstructorList.java @@ -0,0 +1,35 @@ +/** + * This file was automatically generated from ConstructorList.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Lists of constructors + **/ +public class ConstructorList extends Z3Object +{ + /** + * Destructor. + **/ + protected void finalize() + { + Native.delConstructorList(Context().nCtx(), NativeObject()); + } + + ConstructorList(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + ConstructorList(Context ctx, Constructor[] constructors) throws Z3Exception + { + super(ctx); + + setNativeObject(Native.mkConstructorList(Context().nCtx(), + (int) constructors.length, + Constructor.ArrayToNative(constructors))); + } +} diff --git a/src/api/java/Context.java b/src/api/java/Context.java new file mode 100644 index 000000000..f728f1b25 --- /dev/null +++ b/src/api/java/Context.java @@ -0,0 +1,3112 @@ +/** + * This file was automatically generated from Context.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import java.util.*; +import com.Microsoft.Z3.Enumerations.*; + +/** + * The main interaction with Z3 happens via the Context. + **/ +public class Context extends IDisposable +{ + /** + * Constructor. + **/ + public Context() throws Z3Exception + { + super(); + m_ctx = Native.mkContextRc(0); + InitContext(); + } + + /** + * Constructor. + **/ + public Context(Map settings) throws Z3Exception + { + super(); + long cfg = Native.mkConfig(); + for (Map.Entry kv : settings.entrySet()) + Native.setParamValue(cfg, kv.getKey(), kv.getValue()); + m_ctx = Native.mkContextRc(cfg); + Native.delConfig(cfg); + InitContext(); + } + + private Context(long ctx, long refCount, Native.errorHandler errh) + { + super(); + this.m_ctx = ctx; + this.m_refCount = refCount; + this.m_n_err_handler = errh; + } + + /** + * 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) throws Z3Exception + { + return new IntSymbol(this, i); + } + + /** + * Create a symbol using a string. + **/ + public StringSymbol MkSymbol(String name) throws Z3Exception + { + return new StringSymbol(this, name); + } + + /** + * Create an array of symbols. + **/ + Symbol[] MkSymbols(String[] names) throws Z3Exception + { + if (names == null) + return null; + Symbol[] result = new Symbol[names.length]; + for (int i = 0; i < names.length; ++i) + result[i] = MkSymbol(names[i]); + return result; + } + + private BoolSort m_boolSort = null; + private IntSort m_intSort = null; + private RealSort m_realSort = null; + + /** + * Retrieves the Boolean sort of the context. + **/ + public BoolSort BoolSort() throws Z3Exception + { + + if (m_boolSort == null) + m_boolSort = new BoolSort(this); + return m_boolSort; + } + + /** + * Retrieves the Integer sort of the context. + **/ + public IntSort IntSort() throws Z3Exception + { + + if (m_intSort == null) + m_intSort = new IntSort(this); + return m_intSort; + } + + /** + * Retrieves the Real sort of the context. + **/ + public RealSort RealSort() + { + return m_realSort; + } + + /** + * Create a new Boolean sort. + **/ + public BoolSort MkBoolSort() throws Z3Exception + { + + return new BoolSort(this); + } + + /** + * Create a new uninterpreted sort. + **/ + public UninterpretedSort MkUninterpretedSort(Symbol s) throws Z3Exception + { + + CheckContextMatch(s); + return new UninterpretedSort(this, s); + } + + /** + * Create a new uninterpreted sort. + **/ + public UninterpretedSort MkUninterpretedSort(String str) throws Z3Exception + { + + return MkUninterpretedSort(MkSymbol(str)); + } + + /** + * Create a new integer sort. + **/ + public IntSort MkIntSort() throws Z3Exception + { + + return new IntSort(this); + } + + /** + * Create a real sort. + **/ + public RealSort MkRealSort() throws Z3Exception + { + + return new RealSort(this); + } + + /** + * Create a new bit-vector sort. + **/ + public BitVecSort MkBitVecSort(int size) throws Z3Exception + { + + return new BitVecSort(this, Native.mkBvSort(nCtx(), size)); + } + + /** + * Create a new array sort. + **/ + public ArraySort MkArraySort(Sort domain, Sort range) throws Z3Exception + { + + CheckContextMatch(domain); + CheckContextMatch(range); + return new ArraySort(this, domain, range); + } + + /** + * Create a new tuple sort. + **/ + public TupleSort MkTupleSort(Symbol name, Symbol[] fieldNames, + Sort[] fieldSorts) throws Z3Exception + { + + CheckContextMatch(name); + CheckContextMatch(fieldNames); + CheckContextMatch(fieldSorts); + return new TupleSort(this, name, (int) fieldNames.length, fieldNames, + fieldSorts); + } + + /** + * Create a new enumeration sort. + **/ + public EnumSort MkEnumSort(Symbol name, Symbol[] enumNames) + throws Z3Exception + { + + CheckContextMatch(name); + CheckContextMatch(enumNames); + return new EnumSort(this, name, enumNames); + } + + /** + * Create a new enumeration sort. + **/ + public EnumSort MkEnumSort(String name, String[] enumNames) + throws Z3Exception + { + + return new EnumSort(this, MkSymbol(name), MkSymbols(enumNames)); + } + + /** + * Create a new list sort. + **/ + public ListSort MkListSort(Symbol name, Sort elemSort) throws Z3Exception + { + + CheckContextMatch(name); + CheckContextMatch(elemSort); + return new ListSort(this, name, elemSort); + } + + /** + * Create a new list sort. + **/ + public ListSort MkListSort(String name, Sort elemSort) throws Z3Exception + { + + CheckContextMatch(elemSort); + return new ListSort(this, MkSymbol(name), elemSort); + } + + /** + * Create a new finite domain sort. + **/ + public FiniteDomainSort MkFiniteDomainSort(Symbol name, long size) + throws Z3Exception + { + + CheckContextMatch(name); + return new FiniteDomainSort(this, name, size); + } + + /** + * Create a new finite domain sort. + **/ + public FiniteDomainSort MkFiniteDomainSort(String name, long size) + throws Z3Exception + { + + return new FiniteDomainSort(this, MkSymbol(name), size); + } + + /** + * Create a datatype constructor. 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, Sort[] sorts, int[] sortRefs) + throws Z3Exception + { + + return new Constructor(this, name, recognizer, fieldNames, sorts, + sortRefs); + } + + /** + * Create a datatype constructor. + * + * @return + **/ + public Constructor MkConstructor(String name, String recognizer, + String[] fieldNames, Sort[] sorts, int[] sortRefs) + throws Z3Exception + { + + return new Constructor(this, MkSymbol(name), MkSymbol(recognizer), + MkSymbols(fieldNames), sorts, sortRefs); + } + + /** + * Create a new datatype sort. + **/ + public DatatypeSort MkDatatypeSort(Symbol name, Constructor[] constructors) + throws Z3Exception + { + + CheckContextMatch(name); + CheckContextMatch(constructors); + return new DatatypeSort(this, name, constructors); + } + + /** + * Create a new datatype sort. + **/ + public DatatypeSort MkDatatypeSort(String name, Constructor[] constructors) + throws Z3Exception + { + + CheckContextMatch(constructors); + return new DatatypeSort(this, MkSymbol(name), constructors); + } + + /** + * Create mutually recursive datatypes. names of + * datatype sorts list of constructors, one list per + * sort. + **/ + public DatatypeSort[] MkDatatypeSorts(Symbol[] names, Constructor[][] c) + throws Z3Exception + { + + CheckContextMatch(names); + int n = (int) names.length; + ConstructorList[] cla = new ConstructorList[n]; + long[] n_constr = new long[n]; + for (int i = 0; i < n; i++) + { + Constructor[] constructor = c[i]; + + CheckContextMatch(constructor); + cla[i] = new ConstructorList(this, constructor); + n_constr[i] = cla[i].NativeObject(); + } + long[] n_res = new long[n]; + Native.mkDatatypes(nCtx(), n, Symbol.ArrayToNative(names), n_res, + n_constr); + DatatypeSort[] res = new DatatypeSort[n]; + for (int i = 0; i < n; i++) + res[i] = new DatatypeSort(this, n_res[i]); + return res; + } + + /** + * Create mutually recursive data-types. + * + * @return + **/ + public DatatypeSort[] MkDatatypeSorts(String[] names, Constructor[][] c) + throws Z3Exception + { + + return MkDatatypeSorts(MkSymbols(names), c); + } + + /** + * Creates a new function declaration. + **/ + public FuncDecl MkFuncDecl(Symbol name, Sort[] domain, Sort range) + throws Z3Exception + { + + CheckContextMatch(name); + CheckContextMatch(domain); + CheckContextMatch(range); + return new FuncDecl(this, name, domain, range); + } + + /** + * Creates a new function declaration. + **/ + public FuncDecl MkFuncDecl(Symbol name, Sort domain, Sort range) + throws Z3Exception + { + + CheckContextMatch(name); + CheckContextMatch(domain); + CheckContextMatch(range); + Sort[] q = new Sort[] { domain }; + return new FuncDecl(this, name, q, range); + } + + /** + * Creates a new function declaration. + **/ + public FuncDecl MkFuncDecl(String name, Sort[] domain, Sort range) + throws Z3Exception + { + + CheckContextMatch(domain); + CheckContextMatch(range); + return new FuncDecl(this, MkSymbol(name), domain, range); + } + + /** + * Creates a new function declaration. + **/ + public FuncDecl MkFuncDecl(String name, Sort domain, Sort range) + throws Z3Exception + { + + CheckContextMatch(domain); + CheckContextMatch(range); + Sort[] q = new Sort[] { domain }; + return new FuncDecl(this, MkSymbol(name), q, range); + } + + /** + * Creates a fresh function declaration with a name prefixed with . + **/ + public FuncDecl MkFreshFuncDecl(String prefix, Sort[] domain, Sort range) + throws Z3Exception + { + + CheckContextMatch(domain); + CheckContextMatch(range); + return new FuncDecl(this, prefix, domain, range); + } + + /** + * Creates a new constant function declaration. + **/ + public FuncDecl MkConstDecl(Symbol name, Sort range) throws Z3Exception + { + + CheckContextMatch(name); + CheckContextMatch(range); + return new FuncDecl(this, name, null, range); + } + + /** + * Creates a new constant function declaration. + **/ + public FuncDecl MkConstDecl(String name, Sort range) throws Z3Exception + { + + CheckContextMatch(range); + return new FuncDecl(this, MkSymbol(name), null, range); + } + + /** + * Creates a fresh constant function declaration with a name prefixed with + * . + * + **/ + public FuncDecl MkFreshConstDecl(String prefix, Sort range) + throws Z3Exception + { + + CheckContextMatch(range); + return new FuncDecl(this, prefix, null, range); + } + + /** + * Creates a new bound variable. The de-Bruijn index of + * the variable The sort of the variable + **/ + public Expr MkBound(int index, Sort ty) throws Z3Exception + { + return Expr.Create(this, + Native.mkBound(nCtx(), index, ty.NativeObject())); + } + + /** + * Create a quantifier pattern. + **/ + public Pattern MkPattern(Expr[] terms) throws Z3Exception + { + if (terms.length == 0) + throw new Z3Exception("Cannot create a pattern from zero terms"); + + long[] termsNative = AST.ArrayToNative(terms); + return new Pattern(this, Native.mkPattern(nCtx(), (int) terms.length, + termsNative)); + } + + /** + * Creates a new Constant of sort and named + * . + **/ + public Expr MkConst(Symbol name, Sort range) throws Z3Exception + { + + CheckContextMatch(name); + CheckContextMatch(range); + + return Expr.Create( + this, + Native.mkConst(nCtx(), name.NativeObject(), + range.NativeObject())); + } + + /** + * Creates a new Constant of sort and named + * . + **/ + public Expr MkConst(String name, Sort range) throws Z3Exception + { + + return MkConst(MkSymbol(name), range); + } + + /** + * Creates a fresh Constant of sort and a name + * prefixed with . + **/ + public Expr MkFreshConst(String prefix, Sort range) throws Z3Exception + { + + CheckContextMatch(range); + return Expr.Create(this, + Native.mkFreshConst(nCtx(), prefix, range.NativeObject())); + } + + /** + * Creates a fresh constant from the FuncDecl . A decl of a 0-arity function + **/ + public Expr MkConst(FuncDecl f) throws Z3Exception + { + + return MkApp(f, null); + } + + /** + * Create a Boolean constant. + **/ + public BoolExpr MkBoolConst(Symbol name) throws Z3Exception + { + + return (BoolExpr) MkConst(name, BoolSort()); + } + + /** + * Create a Boolean constant. + **/ + public BoolExpr MkBoolConst(String name) throws Z3Exception + { + + return (BoolExpr) MkConst(MkSymbol(name), BoolSort()); + } + + /** + * Creates an integer constant. + **/ + public IntExpr MkIntConst(Symbol name) throws Z3Exception + { + + return (IntExpr) MkConst(name, IntSort()); + } + + /** + * Creates an integer constant. + **/ + public IntExpr MkIntConst(String name) throws Z3Exception + { + + return (IntExpr) MkConst(name, IntSort()); + } + + /** + * Creates a real constant. + **/ + public RealExpr MkRealConst(Symbol name) throws Z3Exception + { + + return (RealExpr) MkConst(name, RealSort()); + } + + /** + * Creates a real constant. + **/ + public RealExpr MkRealConst(String name) throws Z3Exception + { + + return (RealExpr) MkConst(name, RealSort()); + } + + /** + * Creates a bit-vector constant. + **/ + public BitVecExpr MkBVConst(Symbol name, int size) throws Z3Exception + { + + return (BitVecExpr) MkConst(name, MkBitVecSort(size)); + } + + /** + * Creates a bit-vector constant. + **/ + public BitVecExpr MkBVConst(String name, int size) throws Z3Exception + { + + return (BitVecExpr) MkConst(name, MkBitVecSort(size)); + } + + /** + * Create a new function application. + **/ + public Expr MkApp(FuncDecl f, Expr[] args) throws Z3Exception + { + + CheckContextMatch(f); + CheckContextMatch(args); + return Expr.Create(this, f, args); + } + + /** + * The true Term. + **/ + public BoolExpr MkTrue() throws Z3Exception + { + return new BoolExpr(this, Native.mkTrue(nCtx())); + } + + /** + * The false Term. + **/ + public BoolExpr MkFalse() throws Z3Exception + { + return new BoolExpr(this, Native.mkFalse(nCtx())); + } + + /** + * Creates a Boolean value. + **/ + public BoolExpr MkBool(boolean value) throws Z3Exception + { + return value ? MkTrue() : MkFalse(); + } + + /** + * Creates the equality = . + **/ + public BoolExpr MkEq(Expr x, Expr y) throws Z3Exception + { + CheckContextMatch(x); + CheckContextMatch(y); + return new BoolExpr(this, Native.mkEq(nCtx(), x.NativeObject(), + y.NativeObject())); + } + + /** + * Creates a distinct term. + **/ + public BoolExpr MkDistinct(Expr[] args) throws Z3Exception + { + CheckContextMatch(args); + return new BoolExpr(this, Native.mkDistinct(nCtx(), (int) args.length, + AST.ArrayToNative(args))); + } + + /** + * Mk an expression representing not(a). + **/ + public BoolExpr MkNot(BoolExpr a) throws Z3Exception + { + + CheckContextMatch(a); + return new BoolExpr(this, Native.mkNot(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + CheckContextMatch(t3); + return Expr.Create( + this, + Native.mkIte(nCtx(), t1.NativeObject(), t2.NativeObject(), + t3.NativeObject())); + } + + /** + * Create an expression representing t1 iff t2. + **/ + public BoolExpr MkIff(BoolExpr t1, BoolExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkIff(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Create an expression representing t1 -> t2. + **/ + public BoolExpr MkImplies(BoolExpr t1, BoolExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkImplies(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Create an expression representing t1 xor t2. + **/ + public BoolExpr MkXor(BoolExpr t1, BoolExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkXor(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Create an expression representing t[0] and t[1] and .... + **/ + public BoolExpr MkAnd(BoolExpr[] t) throws Z3Exception + { + + CheckContextMatch(t); + return new BoolExpr(this, Native.mkAnd(nCtx(), (int) t.length, + AST.ArrayToNative(t))); + } + + /** + * Create an expression representing t[0] or t[1] or .... + **/ + public BoolExpr MkOr(BoolExpr[] t) throws Z3Exception + { + + CheckContextMatch(t); + return new BoolExpr(this, Native.mkOr(nCtx(), (int) t.length, + AST.ArrayToNative(t))); + } + + /** + * Create an expression representing t[0] + t[1] + .... + **/ + public ArithExpr MkAdd(ArithExpr[] t) throws Z3Exception + { + + CheckContextMatch(t); + return (ArithExpr) Expr.Create(this, + Native.mkAdd(nCtx(), (int) t.length, AST.ArrayToNative(t))); + } + + /** + * Create an expression representing t[0] * t[1] * .... + **/ + public ArithExpr MkMul(ArithExpr[] t) throws Z3Exception + { + + CheckContextMatch(t); + return (ArithExpr) Expr.Create(this, + Native.mkMul(nCtx(), (int) t.length, AST.ArrayToNative(t))); + } + + /** + * Create an expression representing t[0] - t[1] - .... + **/ + public ArithExpr MkSub(ArithExpr[] t) throws Z3Exception + { + + CheckContextMatch(t); + return (ArithExpr) Expr.Create(this, + Native.mkSub(nCtx(), (int) t.length, AST.ArrayToNative(t))); + } + + /** + * Create an expression representing -t. + **/ + public ArithExpr MkUnaryMinus(ArithExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return (ArithExpr) Expr.Create(this, + Native.mkUnaryMinus(nCtx(), t.NativeObject())); + } + + /** + * Create an expression representing t1 / t2. + **/ + public ArithExpr MkDiv(ArithExpr t1, ArithExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return (ArithExpr) Expr.Create(this, + Native.mkDiv(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new IntExpr(this, Native.mkMod(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new IntExpr(this, Native.mkRem(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Create an expression representing t1 ^ t2. + **/ + public ArithExpr MkPower(ArithExpr t1, ArithExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return (ArithExpr) Expr.Create(this, + Native.mkPower(nCtx(), t1.NativeObject(), t2.NativeObject())); + } + + /** + * Create an expression representing t1 < t2 + **/ + public BoolExpr MkLt(ArithExpr t1, ArithExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkLt(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Create an expression representing t1 <= t2 + **/ + public BoolExpr MkLe(ArithExpr t1, ArithExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkLe(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Create an expression representing t1 > t2 + **/ + public BoolExpr MkGt(ArithExpr t1, ArithExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkGt(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Create an expression representing t1 >= t2 + **/ + public BoolExpr MkGe(ArithExpr t1, ArithExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkGe(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) throws Z3Exception + { + + CheckContextMatch(t); + return new RealExpr(this, Native.mkInt2real(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) throws Z3Exception + { + + CheckContextMatch(t); + return new IntExpr(this, Native.mkReal2int(nCtx(), t.NativeObject())); + } + + /** + * Creates an expression that checks whether a real number is an integer. + **/ + public BoolExpr MkIsInteger(RealExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return new BoolExpr(this, Native.mkIsInt(nCtx(), t.NativeObject())); + } + + /** + * Bitwise negation. The argument must have a bit-vector + * sort. + **/ + public BitVecExpr MkBVNot(BitVecExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, Native.mkBvnot(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) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, Native.mkBvredand(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) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, Native.mkBvredor(nCtx(), t.NativeObject())); + } + + /** + * Bitwise conjunction. The arguments must have a bit-vector + * sort. + **/ + public BitVecExpr MkBVAND(BitVecExpr t1, BitVecExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvand(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Bitwise disjunction. The arguments must have a bit-vector + * sort. + **/ + public BitVecExpr MkBVOR(BitVecExpr t1, BitVecExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvor(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Bitwise XOR. The arguments must have a bit-vector + * sort. + **/ + public BitVecExpr MkBVXOR(BitVecExpr t1, BitVecExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvxor(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Bitwise NAND. The arguments must have a bit-vector + * sort. + **/ + public BitVecExpr MkBVNAND(BitVecExpr t1, BitVecExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvnand(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Bitwise NOR. The arguments must have a bit-vector + * sort. + **/ + public BitVecExpr MkBVNOR(BitVecExpr t1, BitVecExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvnor(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Bitwise XNOR. The arguments must have a bit-vector + * sort. + **/ + public BitVecExpr MkBVXNOR(BitVecExpr t1, BitVecExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvxnor(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Standard two's complement unary minus. The arguments must have a + * bit-vector sort. + **/ + public BitVecExpr MkBVNeg(BitVecExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, Native.mkBvneg(nCtx(), t.NativeObject())); + } + + /** + * Two's complement addition. The arguments must have the same + * bit-vector sort. + **/ + public BitVecExpr MkBVAdd(BitVecExpr t1, BitVecExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvadd(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvsub(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvmul(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvudiv(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvsdiv(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvurem(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvsrem(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvsmod(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Unsigned less-than The arguments must have the same bit-vector + * sort. + **/ + public BoolExpr MkBVULT(BitVecExpr t1, BitVecExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvult(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvslt(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvule(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvsle(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvuge(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvsge(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Unsigned greater-than. The arguments must have the same + * bit-vector sort. + **/ + public BoolExpr MkBVUGT(BitVecExpr t1, BitVecExpr t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvugt(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvsgt(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Bit-vector concatenation. The arguments must have a bit-vector + * sort. + * + * @return 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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkConcat(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(int high, int low, BitVecExpr t) + throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, Native.mkExtract(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(int i, BitVecExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, Native.mkSignExt(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(int i, BitVecExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, Native.mkZeroExt(nCtx(), i, + t.NativeObject())); + } + + /** + * Bit-vector repetition. The argument must + * have a bit-vector sort. + **/ + public BitVecExpr MkRepeat(int i, BitVecExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, + Native.mkRepeat(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvshl(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvlshr(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) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkBvashr(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(int i, BitVecExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, Native.mkRotateLeft(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(int i, BitVecExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, Native.mkRotateRight(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) + throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkExtRotateLeft(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) + throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Native.mkExtRotateRight(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(int n, IntExpr t) throws Z3Exception + { + + CheckContextMatch(t); + return new BitVecExpr(this, + Native.mkInt2bv(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, boolean signed) throws Z3Exception + { + + CheckContextMatch(t); + return new IntExpr(this, Native.mkBv2int(nCtx(), t.NativeObject(), + (signed) ? true : false)); + } + + /** + * 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, + boolean isSigned) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, + Native.mkBvaddNoOverflow(nCtx(), t1.NativeObject(), + t2.NativeObject(), (isSigned) ? true : false)); + } + + /** + * 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) + throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvaddNoUnderflow(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) + throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvsubNoOverflow(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, + boolean isSigned) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, + Native.mkBvsubNoUnderflow(nCtx(), t1.NativeObject(), + t2.NativeObject(), (isSigned) ? true : false)); + } + + /** + * 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) + throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvsdivNoOverflow(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) throws Z3Exception + { + + CheckContextMatch(t); + return new BoolExpr(this, Native.mkBvnegNoOverflow(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, + boolean isSigned) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, + Native.mkBvmulNoOverflow(nCtx(), t1.NativeObject(), + t2.NativeObject(), (isSigned) ? true : false)); + } + + /** + * 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) + throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Native.mkBvmulNoUnderflow(nCtx(), + t1.NativeObject(), t2.NativeObject())); + } + + /** + * Create an array constant. + **/ + public ArrayExpr MkArrayConst(Symbol name, Sort domain, Sort range) + throws Z3Exception + { + + return (ArrayExpr) MkConst(name, MkArraySort(domain, range)); + } + + /** + * Create an array constant. + **/ + public ArrayExpr MkArrayConst(String name, Sort domain, Sort range) + throws Z3Exception + { + + 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) throws Z3Exception + { + + CheckContextMatch(a); + CheckContextMatch(i); + return Expr.Create(this, + Native.mkSelect(nCtx(), a.NativeObject(), i.NativeObject())); + } + + /** + * 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) throws Z3Exception + { + + CheckContextMatch(a); + CheckContextMatch(i); + CheckContextMatch(v); + return new ArrayExpr(this, Native.mkStore(nCtx(), a.NativeObject(), + i.NativeObject(), 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) throws Z3Exception + { + + CheckContextMatch(domain); + CheckContextMatch(v); + return new ArrayExpr(this, Native.mkConstArray(nCtx(), + domain.NativeObject(), v.NativeObject())); + } + + /** + * Maps f on the argument arrays. Eeach 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, ArrayExpr[] args) throws Z3Exception + { + + CheckContextMatch(f); + CheckContextMatch(args); + return (ArrayExpr) Expr.Create(this, Native.mkMap(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) throws Z3Exception + { + + CheckContextMatch(array); + return Expr.Create(this, + Native.mkArrayDefault(nCtx(), array.NativeObject())); + } + + /** + * Create a set type. + **/ + public SetSort MkSetSort(Sort ty) throws Z3Exception + { + + CheckContextMatch(ty); + return new SetSort(this, ty); + } + + /** + * Create an empty set. + **/ + public Expr MkEmptySet(Sort domain) throws Z3Exception + { + + CheckContextMatch(domain); + return Expr.Create(this, + Native.mkEmptySet(nCtx(), domain.NativeObject())); + } + + /** + * Create the full set. + **/ + public Expr MkFullSet(Sort domain) throws Z3Exception + { + + CheckContextMatch(domain); + return Expr.Create(this, + Native.mkFullSet(nCtx(), domain.NativeObject())); + } + + /** + * Add an element to the set. + **/ + public Expr MkSetAdd(Expr set, Expr element) throws Z3Exception + { + + CheckContextMatch(set); + CheckContextMatch(element); + return Expr.Create( + this, + Native.mkSetAdd(nCtx(), set.NativeObject(), + element.NativeObject())); + } + + /** + * Remove an element from a set. + **/ + public Expr MkSetDel(Expr set, Expr element) throws Z3Exception + { + + CheckContextMatch(set); + CheckContextMatch(element); + return Expr.Create( + this, + Native.mkSetDel(nCtx(), set.NativeObject(), + element.NativeObject())); + } + + /** + * Take the union of a list of sets. + **/ + public Expr MkSetUnion(Expr[] args) throws Z3Exception + { + + CheckContextMatch(args); + return Expr.Create( + this, + Native.mkSetUnion(nCtx(), (int) args.length, + AST.ArrayToNative(args))); + } + + /** + * Take the intersection of a list of sets. + **/ + public Expr MkSetIntersection(Expr[] args) throws Z3Exception + { + + CheckContextMatch(args); + return Expr.Create( + this, + Native.mkSetIntersect(nCtx(), (int) args.length, + AST.ArrayToNative(args))); + } + + /** + * Take the difference between two sets. + **/ + public Expr MkSetDifference(Expr arg1, Expr arg2) throws Z3Exception + { + + CheckContextMatch(arg1); + CheckContextMatch(arg2); + return Expr.Create( + this, + Native.mkSetDifference(nCtx(), arg1.NativeObject(), + arg2.NativeObject())); + } + + /** + * Take the complement of a set. + **/ + public Expr MkSetComplement(Expr arg) throws Z3Exception + { + + CheckContextMatch(arg); + return Expr.Create(this, + Native.mkSetComplement(nCtx(), arg.NativeObject())); + } + + /** + * Check for set membership. + **/ + public Expr MkSetMembership(Expr elem, Expr set) throws Z3Exception + { + + CheckContextMatch(elem); + CheckContextMatch(set); + return Expr.Create( + this, + Native.mkSetMember(nCtx(), elem.NativeObject(), + set.NativeObject())); + } + + /** + * Check for subsetness of sets. + **/ + public Expr MkSetSubset(Expr arg1, Expr arg2) throws Z3Exception + { + + CheckContextMatch(arg1); + CheckContextMatch(arg2); + return Expr.Create( + this, + Native.mkSetSubset(nCtx(), arg1.NativeObject(), + arg2.NativeObject())); + } + + /** + * 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. + * + * @return A Term with value and sort + **/ + public Expr MkNumeral(String v, Sort ty) throws Z3Exception + { + + CheckContextMatch(ty); + return Expr + .Create(this, Native.mkNumeral(nCtx(), v, ty.NativeObject())); + } + + /** + * Create a Term of a given sort. This function can be use 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 + * + * @return A Term with value and type + **/ + public Expr MkNumeral(int v, Sort ty) throws Z3Exception + { + + CheckContextMatch(ty); + return Expr.Create(this, Native.mkInt(nCtx(), v, ty.NativeObject())); + } + + /** + * Create a Term of a given sort. This function can be use 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 + * + * @return A Term with value and type + **/ + public Expr MkNumeral(long v, Sort ty) throws Z3Exception + { + + CheckContextMatch(ty); + return Expr.Create(this, Native.mkInt64(nCtx(), v, ty.NativeObject())); + } + + /** + * Create a real from a fraction. numerator of + * rational. denominator of rational. + * + * @return A Term with value / + * and sort Real + **/ + public RatNum MkReal(int num, int den) throws Z3Exception + { + if (den == 0) + throw new Z3Exception("Denominator is zero"); + + return new RatNum(this, Native.mkReal(nCtx(), num, den)); + } + + /** + * Create a real numeral. A string representing the Term + * value in decimal notation. + * + * @return A Term with value and sort Real + **/ + public RatNum MkReal(String v) throws Z3Exception + { + + return new RatNum(this, Native.mkNumeral(nCtx(), v, RealSort() + .NativeObject())); + } + + /** + * Create a real numeral. value of the numeral. + * + * @return A Term with value and sort Real + **/ + public RatNum MkReal(int v) throws Z3Exception + { + + return new RatNum(this, Native.mkInt(nCtx(), v, RealSort() + .NativeObject())); + } + + /** + * Create a real numeral. value of the numeral. + * + * @return A Term with value and sort Real + **/ + public RatNum MkReal(long v) throws Z3Exception + { + + return new RatNum(this, Native.mkInt64(nCtx(), v, RealSort() + .NativeObject())); + } + + /** + * Create an integer numeral. A string representing the Term + * value in decimal notation. + **/ + public IntNum MkInt(String v) throws Z3Exception + { + + return new IntNum(this, Native.mkNumeral(nCtx(), v, IntSort() + .NativeObject())); + } + + /** + * Create an integer numeral. value of the numeral. + * + * @return A Term with value and sort Integer + **/ + public IntNum MkInt(int v) throws Z3Exception + { + + return new IntNum(this, Native.mkInt(nCtx(), v, IntSort() + .NativeObject())); + } + + /** + * Create an integer numeral. value of the numeral. + * + * @return A Term with value and sort Integer + **/ + public IntNum MkInt(long v) throws Z3Exception + { + + return new IntNum(this, Native.mkInt64(nCtx(), v, IntSort() + .NativeObject())); + } + + /** + * Create a bit-vector numeral. A string representing the + * value in decimal notation. the size of the + * bit-vector + **/ + public BitVecNum MkBV(String v, int size) throws Z3Exception + { + + 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, int size) throws Z3Exception + { + + 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, int size) throws Z3Exception + { + + return (BitVecNum) MkNumeral(v, MkBitVecSort(size)); + } + + /** + * Create a universal Quantifier. Creates a forall formula, where + * is the weight, is + * an array of patterns, is an array with the sorts + * of the bound variables, is an array with the + * 'names' of the bound variables, and is the body + * of the quantifier. Quantifiers are associated with weights indicating the + * importance of using the quantifier during instantiation. + * the sorts of the bound variables. names of the bound variables the + * body of the quantifier. quantifiers are + * associated with weights indicating the importance of using the quantifier + * during instantiation. By default, pass the weight 0. array containing the patterns created using + * MkPattern. array containing + * the anti-patterns created using MkPattern. optional symbol to track quantifier. optional symbol to track skolem constants. + **/ + public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, + int weight, Pattern[] patterns, Expr[] noPatterns, + Symbol quantifierID, Symbol skolemID) throws Z3Exception + { + + return new Quantifier(this, true, sorts, names, body, weight, patterns, + noPatterns, quantifierID, skolemID); + } + + /** + * Create a universal Quantifier. + **/ + public Quantifier MkForall(Expr[] boundConstants, Expr body, int weight, + Pattern[] patterns, Expr[] noPatterns, Symbol quantifierID, + Symbol skolemID) throws Z3Exception + { + + return new Quantifier(this, true, boundConstants, body, weight, + patterns, noPatterns, quantifierID, skolemID); + } + + /** + * Create an existential Quantifier. + **/ + public Quantifier MkExists(Sort[] sorts, Symbol[] names, Expr body, + int weight, Pattern[] patterns, Expr[] noPatterns, + Symbol quantifierID, Symbol skolemID) throws Z3Exception + { + + return new Quantifier(this, false, sorts, names, body, weight, + patterns, noPatterns, quantifierID, skolemID); + } + + /** + * Create an existential Quantifier. + **/ + public Quantifier MkExists(Expr[] boundConstants, Expr body, int weight, + Pattern[] patterns, Expr[] noPatterns, Symbol quantifierID, + Symbol skolemID) throws Z3Exception + { + + return new Quantifier(this, false, boundConstants, body, weight, + patterns, noPatterns, quantifierID, skolemID); + } + + /** + * Create a Quantifier. + **/ + public Quantifier MkQuantifier(boolean universal, Sort[] sorts, + Symbol[] names, Expr body, int weight, Pattern[] patterns, + Expr[] noPatterns, Symbol quantifierID, Symbol skolemID) + throws Z3Exception + { + + if (universal) + return MkForall(sorts, names, body, weight, patterns, noPatterns, + quantifierID, skolemID); + else + return MkExists(sorts, names, body, weight, patterns, noPatterns, + quantifierID, skolemID); + } + + /** + * Create a Quantifier. + **/ + public Quantifier MkQuantifier(boolean universal, Expr[] boundConstants, + Expr body, int weight, Pattern[] patterns, Expr[] noPatterns, + Symbol quantifierID, Symbol skolemID) throws Z3Exception + { + + if (universal) + return MkForall(boundConstants, body, weight, patterns, noPatterns, + quantifierID, skolemID); + else + return MkExists(boundConstants, body, weight, patterns, noPatterns, + quantifierID, skolemID); + } + + /** + * Selects the format used for pretty-printing expressions. The + * default mode for pretty printing expressions is to produce SMT-LIB style + * output where common subexpressions are printed at each occurrence. The + * mode is called Z3_PRINT_SMTLIB_FULL. To print shared common + * subexpressions only once, use the Z3_PRINT_LOW_LEVEL mode. To print in + * way that conforms to SMT-LIB standards and uses let expressions to share + * common sub-expressions use Z3_PRINT_SMTLIB_COMPLIANT. + **/ + public void setPrintMode(Z3_ast_print_mode value) throws Z3Exception + { + Native.setAstPrintMode(nCtx(), value.toInt()); + } + + /** + * Convert a benchmark into an SMT-LIB formatted string. Name of the benchmark. The argument is optional. + * The benchmark logic. The status string (sat, unsat, or unknown) Other attributes, such as source, difficulty or + * category. Auxiliary + * assumptions. Formula to be checked for + * consistency in conjunction with assumptions. + * + * @return A string representation of the benchmark. + **/ + public String BenchmarkToSMTString(String name, String logic, + String status, String attributes, BoolExpr[] assumptions, + BoolExpr formula) throws Z3Exception + { + + return Native.benchmarkToSmtlibString(nCtx(), name, logic, status, + attributes, (int) assumptions.length, + AST.ArrayToNative(assumptions), formula.NativeObject()); + } + + /** + * Parse the given string using the SMT-LIB parser. The symbol + * table of the parser can be initialized using the given sorts and + * declarations. The symbols in the arrays and + * don't need to match the names of the sorts + * and declarations in the arrays and . This is a useful feature since we can use arbitrary names + * to reference sorts and declarations. + **/ + public void ParseSMTLIBString(String str, Symbol[] sortNames, Sort[] sorts, + Symbol[] declNames, FuncDecl[] decls) throws Z3Exception + { + int csn = Symbol.ArrayLength(sortNames); + int cs = Sort.ArrayLength(sorts); + int cdn = Symbol.ArrayLength(declNames); + int cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Native.parseSmtlibString(nCtx(), str, AST.ArrayLength(sorts), + Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), + AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), + AST.ArrayToNative(decls)); + } + + /** + * Parse the given file using the SMT-LIB parser. + **/ + public void ParseSMTLIBFile(String fileName, Symbol[] sortNames, + Sort[] sorts, Symbol[] declNames, FuncDecl[] decls) + throws Z3Exception + { + int csn = Symbol.ArrayLength(sortNames); + int cs = Sort.ArrayLength(sorts); + int cdn = Symbol.ArrayLength(declNames); + int cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Native.parseSmtlibFile(nCtx(), fileName, AST.ArrayLength(sorts), + Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), + AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), + AST.ArrayToNative(decls)); + } + + /** + * The number of SMTLIB formulas parsed by the last call to + * ParseSMTLIBString or ParseSMTLIBFile. + **/ + public int NumSMTLIBFormulas() throws Z3Exception + { + return Native.getSmtlibNumFormulas(nCtx()); + } + + /** + * The formulas parsed by the last call to ParseSMTLIBString or + * ParseSMTLIBFile. + **/ + public BoolExpr[] SMTLIBFormulas() throws Z3Exception + { + + int n = NumSMTLIBFormulas(); + BoolExpr[] res = new BoolExpr[n]; + for (int i = 0; i < n; i++) + res[i] = (BoolExpr) Expr.Create(this, + Native.getSmtlibFormula(nCtx(), i)); + return res; + } + + /** + * The number of SMTLIB assumptions parsed by the last call to + * ParseSMTLIBString or ParseSMTLIBFile. + **/ + public int NumSMTLIBAssumptions() throws Z3Exception + { + return Native.getSmtlibNumAssumptions(nCtx()); + } + + /** + * The assumptions parsed by the last call to ParseSMTLIBString + * or ParseSMTLIBFile. + **/ + public BoolExpr[] SMTLIBAssumptions() throws Z3Exception + { + + int n = NumSMTLIBAssumptions(); + BoolExpr[] res = new BoolExpr[n]; + for (int i = 0; i < n; i++) + res[i] = (BoolExpr) Expr.Create(this, + Native.getSmtlibAssumption(nCtx(), i)); + return res; + } + + /** + * The number of SMTLIB declarations parsed by the last call to + * ParseSMTLIBString or ParseSMTLIBFile. + **/ + public int NumSMTLIBDecls() throws Z3Exception + { + return Native.getSmtlibNumDecls(nCtx()); + } + + /** + * The declarations parsed by the last call to + * ParseSMTLIBString or ParseSMTLIBFile. + **/ + public FuncDecl[] SMTLIBDecls() throws Z3Exception + { + + int n = NumSMTLIBDecls(); + FuncDecl[] res = new FuncDecl[n]; + for (int i = 0; i < n; i++) + res[i] = new FuncDecl(this, Native.getSmtlibDecl(nCtx(), i)); + return res; + } + + /** + * The number of SMTLIB sorts parsed by the last call to + * ParseSMTLIBString or ParseSMTLIBFile. + **/ + public int NumSMTLIBSorts() throws Z3Exception + { + return Native.getSmtlibNumSorts(nCtx()); + } + + /** + * The declarations parsed by the last call to + * ParseSMTLIBString or ParseSMTLIBFile. + **/ + public Sort[] SMTLIBSorts() throws Z3Exception + { + + int n = NumSMTLIBSorts(); + Sort[] res = new Sort[n]; + for (int i = 0; i < n; i++) + res[i] = Sort.Create(this, Native.getSmtlibSort(nCtx(), i)); + return res; + } + + /** + * Parse the given string using the SMT-LIB2 parser. + * + * @return A conjunction of assertions in the scope (up to push/pop) at the + * end of the string. + **/ + public BoolExpr ParseSMTLIB2String(String str, Symbol[] sortNames, + Sort[] sorts, Symbol[] declNames, FuncDecl[] decls) + throws Z3Exception + { + + int csn = Symbol.ArrayLength(sortNames); + int cs = Sort.ArrayLength(sorts); + int cdn = Symbol.ArrayLength(declNames); + int cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + return (BoolExpr) Expr.Create(this, Native.parseSmtlib2String(nCtx(), + str, AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), + AST.ArrayToNative(sorts), AST.ArrayLength(decls), + Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls))); + } + + /** + * Parse the given file using the SMT-LIB2 parser. + **/ + public BoolExpr ParseSMTLIB2File(String fileName, Symbol[] sortNames, + Sort[] sorts, Symbol[] declNames, FuncDecl[] decls) + throws Z3Exception + { + + int csn = Symbol.ArrayLength(sortNames); + int cs = Sort.ArrayLength(sorts); + int cdn = Symbol.ArrayLength(declNames); + int cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + return (BoolExpr) Expr.Create(this, Native.parseSmtlib2File(nCtx(), + fileName, AST.ArrayLength(sorts), + Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), + AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), + AST.ArrayToNative(decls))); + } + + /** + * Creates a new Goal. Note that the Context must have been + * created with proof generation support if is set + * to true here. Indicates whether model + * generation should be enabled. Indicates + * whether unsat core generation should be enabled. Indicates whether proof generation should be + * enabled. + **/ + public Goal MkGoal(boolean models, boolean unsatCores, boolean proofs) + throws Z3Exception + { + + return new Goal(this, models, unsatCores, proofs); + } + + /** + * Creates a new ParameterSet. + **/ + public Params MkParams() throws Z3Exception + { + + return new Params(this); + } + + /** + * The number of supported tactics. + **/ + public int NumTactics() throws Z3Exception + { + return Native.getNumTactics(nCtx()); + } + + /** + * The names of all supported tactics. + **/ + public String[] TacticNames() throws Z3Exception + { + + int n = NumTactics(); + String[] res = new String[n]; + for (int i = 0; i < n; i++) + res[i] = Native.getTacticName(nCtx(), i); + return res; + } + + /** + * Returns a string containing a description of the tactic with the given + * name. + **/ + public String TacticDescription(String name) throws Z3Exception + { + + return Native.tacticGetDescr(nCtx(), name); + } + + /** + * Creates a new Tactic. + **/ + public Tactic MkTactic(String name) throws Z3Exception + { + + return new Tactic(this, name); + } + + /** + * Create a tactic that applies to a Goal and then + * to every subgoal produced by . + **/ + public Tactic AndThen(Tactic t1, Tactic t2, Tactic[] ts) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + CheckContextMatch(ts); + + long last = 0; + if (ts != null && ts.length > 0) + { + last = ts[ts.length - 1].NativeObject(); + for (int i = ts.length - 2; i >= 0; i--) + last = Native.tacticAndThen(nCtx(), ts[i].NativeObject(), last); + } + if (last != 0) + { + last = Native.tacticAndThen(nCtx(), t2.NativeObject(), last); + return new Tactic(this, Native.tacticAndThen(nCtx(), + t1.NativeObject(), last)); + } else + return new Tactic(this, Native.tacticAndThen(nCtx(), + t1.NativeObject(), t2.NativeObject())); + } + + /** + * Create a tactic that applies to a Goal and then + * to every subgoal produced by . + * Shorthand for AndThen. + **/ + public Tactic Then(Tactic t1, Tactic t2, Tactic[] ts) throws Z3Exception + { + + return AndThen(t1, t2, ts); + } + + /** + * Create a tactic that first applies to a Goal and if + * it fails then returns the result of applied to the + * Goal. + **/ + public Tactic OrElse(Tactic t1, Tactic t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new Tactic(this, Native.tacticOrElse(nCtx(), t1.NativeObject(), + t2.NativeObject())); + } + + /** + * Create a tactic that applies to a goal for milliseconds. If does not + * terminate within milliseconds, then it fails. + * + **/ + public Tactic TryFor(Tactic t, int ms) throws Z3Exception + { + + CheckContextMatch(t); + return new Tactic(this, Native.tacticTryFor(nCtx(), t.NativeObject(), + ms)); + } + + /** + * Create a tactic that applies to a given goal if the + * probe evaluates to true. If evaluates to false, then the new tactic behaves like the + * skip tactic. + **/ + public Tactic When(Probe p, Tactic t) throws Z3Exception + { + + CheckContextMatch(t); + CheckContextMatch(p); + return new Tactic(this, Native.tacticWhen(nCtx(), p.NativeObject(), + t.NativeObject())); + } + + /** + * Create a tactic that applies to a given goal if the + * probe evaluates to true and + * otherwise. + **/ + public Tactic Cond(Probe p, Tactic t1, Tactic t2) throws Z3Exception + { + + CheckContextMatch(p); + CheckContextMatch(t1); + CheckContextMatch(t2); + return new Tactic(this, Native.tacticCond(nCtx(), p.NativeObject(), + t1.NativeObject(), t2.NativeObject())); + } + + /** + * Create a tactic that keeps applying until the goal + * is not modified anymore or the maximum number of iterations is reached. + **/ + public Tactic Repeat(Tactic t, int max) throws Z3Exception + { + + CheckContextMatch(t); + return new Tactic(this, Native.tacticRepeat(nCtx(), t.NativeObject(), + max)); + } + + /** + * Create a tactic that just returns the given goal. + **/ + public Tactic Skip() throws Z3Exception + { + + return new Tactic(this, Native.tacticSkip(nCtx())); + } + + /** + * Create a tactic always fails. + **/ + public Tactic Fail() throws Z3Exception + { + + return new Tactic(this, Native.tacticFail(nCtx())); + } + + /** + * Create a tactic that fails if the probe evaluates to + * false. + **/ + public Tactic FailIf(Probe p) throws Z3Exception + { + + CheckContextMatch(p); + return new Tactic(this, Native.tacticFailIf(nCtx(), p.NativeObject())); + } + + /** + * Create a tactic that fails if the goal is not triviall satisfiable (i.e., + * empty) or trivially unsatisfiable (i.e., contains `false'). + **/ + public Tactic FailIfNotDecided() throws Z3Exception + { + + return new Tactic(this, Native.tacticFailIfNotDecided(nCtx())); + } + + /** + * Create a tactic that applies using the given set of + * parameters . + **/ + public Tactic UsingParams(Tactic t, Params p) throws Z3Exception + { + + CheckContextMatch(t); + CheckContextMatch(p); + return new Tactic(this, Native.tacticUsingParams(nCtx(), + t.NativeObject(), p.NativeObject())); + } + + /** + * Create a tactic that applies using the given set of + * parameters . Alias for + * UsingParams + **/ + public Tactic With(Tactic t, Params p) throws Z3Exception + { + + return UsingParams(t, p); + } + + /** + * Create a tactic that applies the given tactics in parallel. + **/ + public Tactic ParOr(Tactic[] t) throws Z3Exception + { + + CheckContextMatch(t); + return new Tactic(this, Native.tacticParOr(nCtx(), + Tactic.ArrayLength(t), Tactic.ArrayToNative(t))); + } + + /** + * Create a tactic that applies to a given goal and + * then to every subgoal produced by . The subgoals are processed in parallel. + **/ + public Tactic ParAndThen(Tactic t1, Tactic t2) throws Z3Exception + { + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new Tactic(this, Native.tacticParAndThen(nCtx(), + t1.NativeObject(), t2.NativeObject())); + } + + /** + * Interrupt the execution of a Z3 procedure. This procedure can be + * used to interrupt: solvers, simplifiers and tactics. + **/ + public void Interrupt() throws Z3Exception + { + Native.interrupt(nCtx()); + } + + /** + * The number of supported Probes. + **/ + public int NumProbes() throws Z3Exception + { + return Native.getNumProbes(nCtx()); + } + + /** + * The names of all supported Probes. + **/ + public String[] ProbeNames() throws Z3Exception + { + + int n = NumProbes(); + String[] res = new String[n]; + for (int i = 0; i < n; i++) + res[i] = Native.getProbeName(nCtx(), i); + return res; + } + + /** + * Returns a string containing a description of the probe with the given + * name. + **/ + public String ProbeDescription(String name) throws Z3Exception + { + + return Native.probeGetDescr(nCtx(), name); + } + + /** + * Creates a new Probe. + **/ + public Probe MkProbe(String name) throws Z3Exception + { + + return new Probe(this, name); + } + + /** + * Create a probe that always evaluates to . + **/ + public Probe Const(double val) throws Z3Exception + { + + return new Probe(this, Native.probeConst(nCtx(), val)); + } + + /** + * Create a probe that evaluates to "true" when the value returned by + * is less than the value returned by + **/ + public Probe Lt(Probe p1, Probe p2) throws Z3Exception + { + + CheckContextMatch(p1); + CheckContextMatch(p2); + return new Probe(this, Native.probeLt(nCtx(), p1.NativeObject(), + p2.NativeObject())); + } + + /** + * Create a probe that evaluates to "true" when the value returned by + * is greater than the value returned by + **/ + public Probe Gt(Probe p1, Probe p2) throws Z3Exception + { + + CheckContextMatch(p1); + CheckContextMatch(p2); + return new Probe(this, Native.probeGt(nCtx(), p1.NativeObject(), + p2.NativeObject())); + } + + /** + * Create a probe that evaluates to "true" when the value returned by + * is less than or equal the value returned by + * + **/ + public Probe Le(Probe p1, Probe p2) throws Z3Exception + { + + CheckContextMatch(p1); + CheckContextMatch(p2); + return new Probe(this, Native.probeLe(nCtx(), p1.NativeObject(), + p2.NativeObject())); + } + + /** + * Create a probe that evaluates to "true" when the value returned by + * is greater than or equal the value returned by + * + **/ + public Probe Ge(Probe p1, Probe p2) throws Z3Exception + { + + CheckContextMatch(p1); + CheckContextMatch(p2); + return new Probe(this, Native.probeGe(nCtx(), p1.NativeObject(), + p2.NativeObject())); + } + + /** + * Create a probe that evaluates to "true" when the value returned by + * is equal to the value returned by + **/ + public Probe Eq(Probe p1, Probe p2) throws Z3Exception + { + + CheckContextMatch(p1); + CheckContextMatch(p2); + return new Probe(this, Native.probeEq(nCtx(), p1.NativeObject(), + p2.NativeObject())); + } + + /** + * Create a probe that evaluates to "true" when the value and evaluate to "true". + **/ + public Probe And(Probe p1, Probe p2) throws Z3Exception + { + + CheckContextMatch(p1); + CheckContextMatch(p2); + return new Probe(this, Native.probeAnd(nCtx(), p1.NativeObject(), + p2.NativeObject())); + } + + /** + * Create a probe that evaluates to "true" when the value or evaluate to "true". + **/ + public Probe Or(Probe p1, Probe p2) throws Z3Exception + { + + CheckContextMatch(p1); + CheckContextMatch(p2); + return new Probe(this, Native.probeOr(nCtx(), p1.NativeObject(), + p2.NativeObject())); + } + + /** + * Create a probe that evaluates to "true" when the value does not evaluate to "true". + **/ + public Probe Not(Probe p) throws Z3Exception + { + + CheckContextMatch(p); + return new Probe(this, Native.probeNot(nCtx(), p.NativeObject())); + } + + /** + * Creates a new (incremental) solver. This solver also uses a set + * of builtin tactics for handling the first check-sat command, and + * check-sat commands that take more than a given number of milliseconds to + * be solved. + **/ + public Solver MkSolver(Symbol logic) throws Z3Exception + { + + if (logic == null) + return new Solver(this, Native.mkSolver(nCtx())); + else + return new Solver(this, Native.mkSolverForLogic(nCtx(), + logic.NativeObject())); + } + + /** + * Creates a new (incremental) solver. + **/ + public Solver MkSolver(String logic) throws Z3Exception + { + + return MkSolver(MkSymbol(logic)); + } + + /** + * Creates a new (incremental) solver. + **/ + public Solver MkSimpleSolver() throws Z3Exception + { + + return new Solver(this, Native.mkSimpleSolver(nCtx())); + } + + /** + * Creates a solver that is implemented using the given tactic. + * The solver supports the commands Push and Pop, + * but it will always solve each check from scratch. + **/ + public Solver MkSolver(Tactic t) throws Z3Exception + { + + return new Solver(this, Native.mkSolverFromTactic(nCtx(), + t.NativeObject())); + } + + /** + * Create a Fixedpoint context. + **/ + public Fixedpoint MkFixedpoint() throws Z3Exception + { + + return new Fixedpoint(this); + } + + /** + * Wraps an AST. This function is used for transitions between + * native and managed objects. Note that + * must be a native object obtained from Z3 (e.g., through ) and that it must have a correct reference count (see + * e.g., . The native pointer to + * wrap. + **/ + public AST WrapAST(long nativeObject) throws Z3Exception + { + + return AST.Create(this, nativeObject); + } + + /** + * Unwraps an AST. This function is used for transitions between + * native and managed objects. It returns the native pointer to the AST. + * Note that AST objects are reference counted and unwrapping an AST + * disables automatic reference counting, i.e., all references to the IntPtr + * that is returned must be handled externally and through native calls (see + * e.g., ). The AST to unwrap. + **/ + public long UnwrapAST(AST a) + { + return a.NativeObject(); + } + + /** + * Return a string describing all available parameters to + * Expr.Simplify. + **/ + public String SimplifyHelp() throws Z3Exception + { + + return Native.simplifyGetHelp(nCtx()); + } + + /** + * Retrieves parameter descriptions for simplifier. + **/ + public ParamDescrs SimplifyParameterDescriptions() throws Z3Exception + { + return new ParamDescrs(this, Native.simplifyGetParamDescrs(nCtx())); + } + + /** + * Enable/disable printing of warning messages to the console. Note + * that this function is static and effects the behaviour of all contexts + * globally. + **/ + public static void ToggleWarningMessages(boolean enabled) + throws Z3Exception + { + Native.toggleWarningMessages((enabled) ? true : false); + } + + // /// + // /// A delegate which is executed when an error is raised. + // /// + // /// + // /// Note that it is possible for memory leaks to occur if error handlers + // /// throw exceptions. + // /// + // public delegate void ErrorHandler(Context ctx, Z3_error_code errorCode, + // String errorString); + + // /// + // /// The OnError event. + // /// + // public event ErrorHandler OnError = null; + + /** + * Update a mutable configuration parameter. The list of all + * configuration parameters can be obtained using the Z3 executable: + * z3.exe -ini? Only a few configuration parameters are mutable + * once the context is created. An exception is thrown when trying to modify + * an immutable parameter. + **/ + public void UpdateParamValue(String id, String value) throws Z3Exception + { + Native.updateParamValue(nCtx(), id, value); + } + + /** + * Get a configuration parameter. Returns null if the parameter + * value does not exist. + **/ + public String GetParamValue(String id) throws Z3Exception + { + Native.StringPtr res = new Native.StringPtr(); + boolean r = Native.getParamValue(nCtx(), id, res); + if (!r) + return null; + else + return res.value; + } + + long m_ctx = 0; + Native.errorHandler m_n_err_handler = null; + + long nCtx() + { + return m_ctx; + } + + // void NativeErrorHandler(long ctx, Z3_error_code errorCode) + // { + // // Do-nothing error handler. The wrappers in Z3.Native will throw + // exceptions upon errors. + // } + + void InitContext() throws Z3Exception + { + setPrintMode(Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT); + // m_n_err_handler = new Native.errorHandler(NativeErrorHandler); // + // keep reference so it doesn't get collected. + // if (m_n_err_handler != null) Native.setErrorHandler(m_ctx, + // m_n_err_handler); + } + + void CheckContextMatch(Z3Object other) throws Z3Exception + { + + if (this == other.Context()) + throw new Z3Exception("Context mismatch"); + } + + void CheckContextMatch(Z3Object[] arr) throws Z3Exception + { + + if (arr != null) + { + for (Z3Object a : arr) + { + // It was an assume, now we added the precondition, and we made + // it into an assert + CheckContextMatch(a); + } + } + } + + private ASTDecRefQueue m_AST_DRQ = new ASTDecRefQueue(); + private ASTMapDecRefQueue m_ASTMap_DRQ = new ASTMapDecRefQueue(); + private ASTVectorDecRefQueue m_ASTVector_DRQ = new ASTVectorDecRefQueue(); + private ApplyResultDecRefQueue m_ApplyResult_DRQ = new ApplyResultDecRefQueue(); + private FuncInterpEntryDecRefQueue m_FuncEntry_DRQ = new FuncInterpEntryDecRefQueue(); + private FuncInterpDecRefQueue m_FuncInterp_DRQ = new FuncInterpDecRefQueue(); + private GoalDecRefQueue m_Goal_DRQ = new GoalDecRefQueue(); + private ModelDecRefQueue m_Model_DRQ = new ModelDecRefQueue(); + private ParamsDecRefQueue m_Params_DRQ = new ParamsDecRefQueue(); + private ParamDescrsDecRefQueue m_ParamDescrs_DRQ = new ParamDescrsDecRefQueue(); + private ProbeDecRefQueue m_Probe_DRQ = new ProbeDecRefQueue(); + private SolverDecRefQueue m_Solver_DRQ = new SolverDecRefQueue(); + private StatisticsDecRefQueue m_Statistics_DRQ = new StatisticsDecRefQueue(); + private TacticDecRefQueue m_Tactic_DRQ = new TacticDecRefQueue(); + private FixedpointDecRefQueue m_Fixedpoint_DRQ = new FixedpointDecRefQueue(); + + ASTDecRefQueue AST_DRQ() + { + return m_AST_DRQ; + } + + ASTMapDecRefQueue ASTMap_DRQ() + { + return m_ASTMap_DRQ; + } + + ASTVectorDecRefQueue ASTVector_DRQ() + { + return m_ASTVector_DRQ; + } + + ApplyResultDecRefQueue ApplyResult_DRQ() + { + return m_ApplyResult_DRQ; + } + + FuncInterpEntryDecRefQueue FuncEntry_DRQ() + { + return m_FuncEntry_DRQ; + } + + FuncInterpDecRefQueue FuncInterp_DRQ() + { + return m_FuncInterp_DRQ; + } + + GoalDecRefQueue Goal_DRQ() + { + return m_Goal_DRQ; + } + + ModelDecRefQueue Model_DRQ() + { + return m_Model_DRQ; + } + + ParamsDecRefQueue Params_DRQ() + { + return m_Params_DRQ; + } + + ParamDescrsDecRefQueue ParamDescrs_DRQ() + { + return m_ParamDescrs_DRQ; + } + + ProbeDecRefQueue Probe_DRQ() + { + return m_Probe_DRQ; + } + + SolverDecRefQueue Solver_DRQ() + { + return m_Solver_DRQ; + } + + StatisticsDecRefQueue Statistics_DRQ() + { + return m_Statistics_DRQ; + } + + TacticDecRefQueue Tactic_DRQ() + { + return m_Tactic_DRQ; + } + + FixedpointDecRefQueue Fixedpoint_DRQ() + { + return m_Fixedpoint_DRQ; + } + + protected long m_refCount = 0; + + /** + * Finalizer. + **/ + protected void finalize() + { + // Console.WriteLine("Context Finalizer from " + + // System.Threading.Thread.CurrentThread.ManagedThreadId); + Dispose(); + + if (m_refCount == 0) + { + m_n_err_handler = null; + Native.delContext(m_ctx); + m_ctx = 0; + } else + /* re-queue the finalizer */ + new Context(m_ctx, m_refCount, m_n_err_handler); + } + + /** + * Disposes of the context. + **/ + public void Dispose() + { + // Console.WriteLine("Context Dispose from " + + // System.Threading.Thread.CurrentThread.ManagedThreadId); + m_AST_DRQ.Clear(this); + m_ASTMap_DRQ.Clear(this); + m_ASTVector_DRQ.Clear(this); + m_ApplyResult_DRQ.Clear(this); + m_FuncEntry_DRQ.Clear(this); + m_FuncInterp_DRQ.Clear(this); + m_Goal_DRQ.Clear(this); + m_Model_DRQ.Clear(this); + m_Params_DRQ.Clear(this); + m_Probe_DRQ.Clear(this); + m_Solver_DRQ.Clear(this); + m_Statistics_DRQ.Clear(this); + m_Tactic_DRQ.Clear(this); + m_Fixedpoint_DRQ.Clear(this); + + m_boolSort = null; + m_intSort = null; + m_realSort = null; + } +} diff --git a/src/api/java/DatatypeExpr.java b/src/api/java/DatatypeExpr.java new file mode 100644 index 000000000..c29507163 --- /dev/null +++ b/src/api/java/DatatypeExpr.java @@ -0,0 +1,26 @@ +/** + * This file was automatically generated from DatatypeExpr.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Datatype expressions + **/ +public class DatatypeExpr extends Expr +{ + /** + * Constructor for DatatypeExpr + **/ + protected DatatypeExpr(Context ctx) + { + super(ctx); + } + + DatatypeExpr(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/DatatypeSort.java b/src/api/java/DatatypeSort.java new file mode 100644 index 000000000..30e9f9d4c --- /dev/null +++ b/src/api/java/DatatypeSort.java @@ -0,0 +1,91 @@ +/** + * This file was automatically generated from DatatypeSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Datatype sorts. + **/ +public class DatatypeSort extends Sort +{ + /** + * The number of constructors of the datatype sort. + **/ + public int NumConstructors() + { + return Native.getDatatypeSortNumConstructors(Context().nCtx(), + NativeObject()); + } + + /** + * The constructors. + * + * @throws Z3Exception + **/ + public FuncDecl[] Constructors() throws Z3Exception + { + int n = NumConstructors(); + FuncDecl[] res = new FuncDecl[n]; + for (int i = 0; i < n; i++) + res[i] = new FuncDecl(Context(), Native.getDatatypeSortConstructor( + Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * The recognizers. + * + * @throws Z3Exception + **/ + public FuncDecl[] Recognizers() throws Z3Exception + { + int n = NumConstructors(); + FuncDecl[] res = new FuncDecl[n]; + for (int i = 0; i < n; i++) + res[i] = new FuncDecl(Context(), Native.getDatatypeSortRecognizer( + Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * The constructor accessors. + * + * @throws Z3Exception + **/ + public FuncDecl[][] Accessors() throws Z3Exception + { + + int n = NumConstructors(); + FuncDecl[][] res = new FuncDecl[n][]; + for (int i = 0; i < n; i++) + { + FuncDecl fd = new FuncDecl(Context(), + Native.getDatatypeSortConstructor(Context().nCtx(), + NativeObject(), i)); + int ds = fd.DomainSize(); + FuncDecl[] tmp = new FuncDecl[ds]; + for (int j = 0; j < ds; j++) + tmp[j] = new FuncDecl(Context(), + Native.getDatatypeSortConstructorAccessor(Context() + .nCtx(), NativeObject(), i, j)); + res[i] = tmp; + } + return res; + } + + DatatypeSort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + DatatypeSort(Context ctx, Symbol name, Constructor[] constructors) + throws Z3Exception + { + super(ctx, Native.mkDatatype(ctx.nCtx(), name.NativeObject(), + (int) constructors.length, ArrayToNative(constructors))); + + } +}; diff --git a/src/api/java/EnumSort.java b/src/api/java/EnumSort.java new file mode 100644 index 000000000..0c4468b9c --- /dev/null +++ b/src/api/java/EnumSort.java @@ -0,0 +1,64 @@ +/** + * This file was automatically generated from EnumSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Enumeration sorts. + **/ +public class EnumSort extends Sort +{ + /** + * The function declarations of the constants in the enumeration. + **/ + public FuncDecl[] ConstDecls() + { + + return _constdecls; + } + + /** + * The constants in the enumeration. + **/ + public Expr[] Consts() + { + + return _consts; + } + + /** + * The test predicates for the constants in the enumeration. + **/ + public FuncDecl[] TesterDecls() + { + + return _testerdecls; + } + + private FuncDecl[] _constdecls = null, _testerdecls = null; + private Expr[] _consts = null; + + EnumSort(Context ctx, Symbol name, Symbol[] enumNames) throws Z3Exception + { + super(ctx); + + int n = enumNames.length; + long[] n_constdecls = new long[n]; + long[] n_testers = new long[n]; + setNativeObject(Native.mkEnumerationSort(ctx.nCtx(), + name.NativeObject(), (int) n, Symbol.ArrayToNative(enumNames), + n_constdecls, n_testers)); + _constdecls = new FuncDecl[n]; + for (int i = 0; i < n; i++) + _constdecls[i] = new FuncDecl(ctx, n_constdecls[i]); + _testerdecls = new FuncDecl[n]; + for (int i = 0; i < n; i++) + _testerdecls[i] = new FuncDecl(ctx, n_testers[i]); + _consts = new Expr[n]; + for (int i = 0; i < n; i++) + _consts[i] = ctx.MkApp(_constdecls[i], null); + } +}; diff --git a/src/api/java/Enumerations/Z3_ast_kind.java b/src/api/java/Enumerations/Z3_ast_kind.java new file mode 100644 index 000000000..931d70f62 --- /dev/null +++ b/src/api/java/Enumerations/Z3_ast_kind.java @@ -0,0 +1,33 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_ast_kind + **/ +public enum Z3_ast_kind { + Z3_VAR_AST (2), + Z3_SORT_AST (4), + Z3_QUANTIFIER_AST (3), + Z3_UNKNOWN_AST (1000), + Z3_FUNC_DECL_AST (5), + Z3_NUMERAL_AST (0), + Z3_APP_AST (1); + + private final int intValue; + + Z3_ast_kind(int v) { + this.intValue = v; + } + + public static final Z3_ast_kind fromInt(int v) { + for (Z3_ast_kind k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Enumerations/Z3_ast_print_mode.java b/src/api/java/Enumerations/Z3_ast_print_mode.java new file mode 100644 index 000000000..37da961d7 --- /dev/null +++ b/src/api/java/Enumerations/Z3_ast_print_mode.java @@ -0,0 +1,30 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_ast_print_mode + **/ +public enum Z3_ast_print_mode { + Z3_PRINT_SMTLIB2_COMPLIANT (3), + Z3_PRINT_SMTLIB_COMPLIANT (2), + Z3_PRINT_SMTLIB_FULL (0), + Z3_PRINT_LOW_LEVEL (1); + + private final int intValue; + + Z3_ast_print_mode(int v) { + this.intValue = v; + } + + public static final Z3_ast_print_mode fromInt(int v) { + for (Z3_ast_print_mode k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Enumerations/Z3_decl_kind.java b/src/api/java/Enumerations/Z3_decl_kind.java new file mode 100644 index 000000000..dd701c1e1 --- /dev/null +++ b/src/api/java/Enumerations/Z3_decl_kind.java @@ -0,0 +1,178 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_decl_kind + **/ +public enum Z3_decl_kind { + Z3_OP_LABEL (1792), + Z3_OP_PR_REWRITE (1294), + Z3_OP_UNINTERPRETED (2051), + Z3_OP_SUB (519), + Z3_OP_ZERO_EXT (1058), + Z3_OP_ADD (518), + Z3_OP_IS_INT (528), + Z3_OP_BREDOR (1061), + Z3_OP_BNOT (1051), + Z3_OP_BNOR (1054), + Z3_OP_PR_CNF_STAR (1315), + Z3_OP_RA_JOIN (1539), + Z3_OP_LE (514), + Z3_OP_SET_UNION (773), + Z3_OP_PR_UNDEF (1280), + Z3_OP_BREDAND (1062), + Z3_OP_LT (516), + Z3_OP_RA_UNION (1540), + Z3_OP_BADD (1028), + Z3_OP_BUREM0 (1039), + Z3_OP_OEQ (267), + Z3_OP_PR_MODUS_PONENS (1284), + Z3_OP_RA_CLONE (1548), + Z3_OP_REPEAT (1060), + Z3_OP_RA_NEGATION_FILTER (1544), + Z3_OP_BSMOD0 (1040), + Z3_OP_BLSHR (1065), + Z3_OP_BASHR (1066), + Z3_OP_PR_UNIT_RESOLUTION (1304), + Z3_OP_ROTATE_RIGHT (1068), + Z3_OP_ARRAY_DEFAULT (772), + Z3_OP_PR_PULL_QUANT (1296), + Z3_OP_PR_APPLY_DEF (1310), + Z3_OP_PR_REWRITE_STAR (1295), + Z3_OP_IDIV (523), + Z3_OP_PR_GOAL (1283), + Z3_OP_PR_IFF_TRUE (1305), + Z3_OP_LABEL_LIT (1793), + Z3_OP_BOR (1050), + Z3_OP_PR_SYMMETRY (1286), + Z3_OP_TRUE (256), + Z3_OP_SET_COMPLEMENT (776), + Z3_OP_CONCAT (1056), + Z3_OP_PR_NOT_OR_ELIM (1293), + Z3_OP_IFF (263), + Z3_OP_BSHL (1064), + Z3_OP_PR_TRANSITIVITY (1287), + Z3_OP_SGT (1048), + Z3_OP_RA_WIDEN (1541), + Z3_OP_PR_DEF_INTRO (1309), + Z3_OP_NOT (265), + Z3_OP_PR_QUANT_INTRO (1290), + Z3_OP_UGT (1047), + Z3_OP_DT_RECOGNISER (2049), + Z3_OP_SET_INTERSECT (774), + Z3_OP_BSREM (1033), + Z3_OP_RA_STORE (1536), + Z3_OP_SLT (1046), + Z3_OP_ROTATE_LEFT (1067), + Z3_OP_PR_NNF_NEG (1313), + Z3_OP_PR_REFLEXIVITY (1285), + Z3_OP_ULEQ (1041), + Z3_OP_BIT1 (1025), + Z3_OP_BIT0 (1026), + Z3_OP_EQ (258), + Z3_OP_BMUL (1030), + Z3_OP_ARRAY_MAP (771), + Z3_OP_STORE (768), + Z3_OP_PR_HYPOTHESIS (1302), + Z3_OP_RA_RENAME (1545), + Z3_OP_AND (261), + Z3_OP_TO_REAL (526), + Z3_OP_PR_NNF_POS (1312), + Z3_OP_PR_AND_ELIM (1292), + Z3_OP_MOD (525), + Z3_OP_BUDIV0 (1037), + Z3_OP_PR_TRUE (1281), + Z3_OP_BNAND (1053), + Z3_OP_PR_ELIM_UNUSED_VARS (1299), + Z3_OP_RA_FILTER (1543), + Z3_OP_FD_LT (1549), + Z3_OP_RA_EMPTY (1537), + Z3_OP_DIV (522), + Z3_OP_ANUM (512), + Z3_OP_MUL (521), + Z3_OP_UGEQ (1043), + Z3_OP_BSREM0 (1038), + Z3_OP_PR_TH_LEMMA (1318), + Z3_OP_BXOR (1052), + Z3_OP_DISTINCT (259), + Z3_OP_PR_IFF_FALSE (1306), + Z3_OP_BV2INT (1072), + Z3_OP_EXT_ROTATE_LEFT (1069), + Z3_OP_PR_PULL_QUANT_STAR (1297), + Z3_OP_BSUB (1029), + Z3_OP_PR_ASSERTED (1282), + Z3_OP_BXNOR (1055), + Z3_OP_EXTRACT (1059), + Z3_OP_PR_DER (1300), + Z3_OP_DT_CONSTRUCTOR (2048), + Z3_OP_GT (517), + Z3_OP_BUREM (1034), + Z3_OP_IMPLIES (266), + Z3_OP_SLEQ (1042), + Z3_OP_GE (515), + Z3_OP_BAND (1049), + Z3_OP_ITE (260), + Z3_OP_AS_ARRAY (778), + Z3_OP_RA_SELECT (1547), + Z3_OP_CONST_ARRAY (770), + Z3_OP_BSDIV (1031), + Z3_OP_OR (262), + Z3_OP_PR_HYPER_RESOLVE (1319), + Z3_OP_AGNUM (513), + Z3_OP_PR_PUSH_QUANT (1298), + Z3_OP_BSMOD (1035), + Z3_OP_PR_IFF_OEQ (1311), + Z3_OP_PR_LEMMA (1303), + Z3_OP_SET_SUBSET (777), + Z3_OP_SELECT (769), + Z3_OP_RA_PROJECT (1542), + Z3_OP_BNEG (1027), + Z3_OP_UMINUS (520), + Z3_OP_REM (524), + Z3_OP_TO_INT (527), + Z3_OP_PR_QUANT_INST (1301), + Z3_OP_SGEQ (1044), + Z3_OP_POWER (529), + Z3_OP_XOR3 (1074), + Z3_OP_RA_IS_EMPTY (1538), + Z3_OP_CARRY (1073), + Z3_OP_DT_ACCESSOR (2050), + Z3_OP_PR_TRANSITIVITY_STAR (1288), + Z3_OP_PR_NNF_STAR (1314), + Z3_OP_PR_COMMUTATIVITY (1307), + Z3_OP_ULT (1045), + Z3_OP_BSDIV0 (1036), + Z3_OP_SET_DIFFERENCE (775), + Z3_OP_INT2BV (1071), + Z3_OP_XOR (264), + Z3_OP_PR_MODUS_PONENS_OEQ (1317), + Z3_OP_BNUM (1024), + Z3_OP_BUDIV (1032), + Z3_OP_PR_MONOTONICITY (1289), + Z3_OP_PR_DEF_AXIOM (1308), + Z3_OP_FALSE (257), + Z3_OP_EXT_ROTATE_RIGHT (1070), + Z3_OP_PR_DISTRIBUTIVITY (1291), + Z3_OP_SIGN_EXT (1057), + Z3_OP_PR_SKOLEMIZE (1316), + Z3_OP_BCOMP (1063), + Z3_OP_RA_COMPLEMENT (1546); + + private final int intValue; + + Z3_decl_kind(int v) { + this.intValue = v; + } + + public static final Z3_decl_kind fromInt(int v) { + for (Z3_decl_kind k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Enumerations/Z3_error_code.java b/src/api/java/Enumerations/Z3_error_code.java new file mode 100644 index 000000000..2672c9325 --- /dev/null +++ b/src/api/java/Enumerations/Z3_error_code.java @@ -0,0 +1,39 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_error_code + **/ +public enum Z3_error_code { + Z3_INVALID_PATTERN (6), + Z3_MEMOUT_FAIL (7), + Z3_NO_PARSER (5), + Z3_OK (0), + Z3_INVALID_ARG (3), + Z3_EXCEPTION (12), + Z3_IOB (2), + Z3_INTERNAL_FATAL (9), + Z3_INVALID_USAGE (10), + Z3_FILE_ACCESS_ERROR (8), + Z3_SORT_ERROR (1), + Z3_PARSER_ERROR (4), + Z3_DEC_REF_ERROR (11); + + private final int intValue; + + Z3_error_code(int v) { + this.intValue = v; + } + + public static final Z3_error_code fromInt(int v) { + for (Z3_error_code k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Enumerations/Z3_goal_prec.java b/src/api/java/Enumerations/Z3_goal_prec.java new file mode 100644 index 000000000..f16fe51ec --- /dev/null +++ b/src/api/java/Enumerations/Z3_goal_prec.java @@ -0,0 +1,30 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_goal_prec + **/ +public enum Z3_goal_prec { + Z3_GOAL_UNDER (1), + Z3_GOAL_PRECISE (0), + Z3_GOAL_UNDER_OVER (3), + Z3_GOAL_OVER (2); + + private final int intValue; + + Z3_goal_prec(int v) { + this.intValue = v; + } + + public static final Z3_goal_prec fromInt(int v) { + for (Z3_goal_prec k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Enumerations/Z3_lbool.java b/src/api/java/Enumerations/Z3_lbool.java new file mode 100644 index 000000000..55d5d7e17 --- /dev/null +++ b/src/api/java/Enumerations/Z3_lbool.java @@ -0,0 +1,29 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_lbool + **/ +public enum Z3_lbool { + Z3_L_TRUE (1), + Z3_L_UNDEF (0), + Z3_L_FALSE (-1); + + private final int intValue; + + Z3_lbool(int v) { + this.intValue = v; + } + + public static final Z3_lbool fromInt(int v) { + for (Z3_lbool k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Enumerations/Z3_param_kind.java b/src/api/java/Enumerations/Z3_param_kind.java new file mode 100644 index 000000000..086622e95 --- /dev/null +++ b/src/api/java/Enumerations/Z3_param_kind.java @@ -0,0 +1,33 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_param_kind + **/ +public enum Z3_param_kind { + Z3_PK_BOOL (1), + Z3_PK_SYMBOL (3), + Z3_PK_OTHER (5), + Z3_PK_INVALID (6), + Z3_PK_UINT (0), + Z3_PK_STRING (4), + Z3_PK_DOUBLE (2); + + private final int intValue; + + Z3_param_kind(int v) { + this.intValue = v; + } + + public static final Z3_param_kind fromInt(int v) { + for (Z3_param_kind k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Enumerations/Z3_parameter_kind.java b/src/api/java/Enumerations/Z3_parameter_kind.java new file mode 100644 index 000000000..021157183 --- /dev/null +++ b/src/api/java/Enumerations/Z3_parameter_kind.java @@ -0,0 +1,33 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_parameter_kind + **/ +public enum Z3_parameter_kind { + Z3_PARAMETER_FUNC_DECL (6), + Z3_PARAMETER_DOUBLE (1), + Z3_PARAMETER_SYMBOL (3), + Z3_PARAMETER_INT (0), + Z3_PARAMETER_AST (5), + Z3_PARAMETER_SORT (4), + Z3_PARAMETER_RATIONAL (2); + + private final int intValue; + + Z3_parameter_kind(int v) { + this.intValue = v; + } + + public static final Z3_parameter_kind fromInt(int v) { + for (Z3_parameter_kind k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Enumerations/Z3_sort_kind.java b/src/api/java/Enumerations/Z3_sort_kind.java new file mode 100644 index 000000000..91559a58a --- /dev/null +++ b/src/api/java/Enumerations/Z3_sort_kind.java @@ -0,0 +1,36 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_sort_kind + **/ +public enum Z3_sort_kind { + Z3_BV_SORT (4), + Z3_FINITE_DOMAIN_SORT (8), + Z3_ARRAY_SORT (5), + Z3_UNKNOWN_SORT (1000), + Z3_RELATION_SORT (7), + Z3_REAL_SORT (3), + Z3_INT_SORT (2), + Z3_UNINTERPRETED_SORT (0), + Z3_BOOL_SORT (1), + Z3_DATATYPE_SORT (6); + + private final int intValue; + + Z3_sort_kind(int v) { + this.intValue = v; + } + + public static final Z3_sort_kind fromInt(int v) { + for (Z3_sort_kind k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Enumerations/Z3_symbol_kind.java b/src/api/java/Enumerations/Z3_symbol_kind.java new file mode 100644 index 000000000..0866dc786 --- /dev/null +++ b/src/api/java/Enumerations/Z3_symbol_kind.java @@ -0,0 +1,28 @@ +/** + * Automatically generated file + **/ + +package com.Microsoft.Z3.Enumerations; + +/** + * Z3_symbol_kind + **/ +public enum Z3_symbol_kind { + Z3_INT_SYMBOL (0), + Z3_STRING_SYMBOL (1); + + private final int intValue; + + Z3_symbol_kind(int v) { + this.intValue = v; + } + + public static final Z3_symbol_kind fromInt(int v) { + for (Z3_symbol_kind k: values()) + if (k.intValue == v) return k; + return values()[0]; + } + + public final int toInt() { return this.intValue; } +} + diff --git a/src/api/java/Expr.java b/src/api/java/Expr.java new file mode 100644 index 000000000..8442acf6a --- /dev/null +++ b/src/api/java/Expr.java @@ -0,0 +1,1807 @@ +/** + * This file was automatically generated from Expr.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/* using System; */ + +/** + * Expressions are terms. + **/ +public class Expr extends AST +{ + /** + * Returns a simplified version of the expression. A set of + * parameters to configure the simplifier + **/ + public Expr Simplify(Params p) throws Z3Exception + { + + if (p == null) + return Expr.Create(Context(), + Native.simplify(Context().nCtx(), NativeObject())); + else + return Expr.Create( + Context(), + Native.simplifyEx(Context().nCtx(), NativeObject(), + p.NativeObject())); + } + + /** + * The function declaration of the function that is applied in this + * expression. + **/ + public FuncDecl FuncDecl() throws Z3Exception + { + + return new FuncDecl(Context(), Native.getAppDecl(Context().nCtx(), + NativeObject())); + } + + /** + * Indicates whether the expression is the true or false expression or + * something else (Z3_L_UNDEF). + **/ + public Z3_lbool BoolValue() throws Z3Exception + { + return Z3_lbool.fromInt(Native.getBoolValue(Context().nCtx(), + NativeObject())); + } + + /** + * The number of arguments of the expression. + **/ + public int NumArgs() throws Z3Exception + { + return Native.getAppNumArgs(Context().nCtx(), NativeObject()); + } + + /** + * The arguments of the expression. + **/ + public Expr[] Args() throws Z3Exception + { + + int n = NumArgs(); + Expr[] res = new Expr[n]; + for (int i = 0; i < n; i++) + res[i] = Expr.Create(Context(), + Native.getAppArg(Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * Update the arguments of the expression using the arguments The number of new arguments should coincide with the + * current number of arguments. + **/ + public void Update(Expr[] args) throws Z3Exception + { + + Context().CheckContextMatch(args); + if (args.length != NumArgs()) + throw new Z3Exception("Number of arguments does not match"); + setNativeObject(Native.updateTerm(Context().nCtx(), NativeObject(), + (int) args.length, Expr.ArrayToNative(args))); + } + + /** + * Substitute every occurrence of from[i] in the expression + * with to[i], for i smaller than + * num_exprs. The result is the new expression. The + * arrays from and to must have size + * num_exprs. For every i smaller than + * num_exprs, we must have that sort of from[i] + * must be equal to sort of to[i]. + **/ + public Expr Substitute(Expr[] from, Expr[] to) throws Z3Exception + { + + Context().CheckContextMatch(from); + Context().CheckContextMatch(to); + if (from.length != to.length) + throw new Z3Exception("Argument sizes do not match"); + return Expr.Create(Context(), Native.substitute(Context().nCtx(), + NativeObject(), (int) from.length, Expr.ArrayToNative(from), + Expr.ArrayToNative(to))); + } + + /** + * Substitute every occurrence of from in the expression with + * to. + **/ + public Expr Substitute(Expr from, Expr to) throws Z3Exception + { + + return Substitute(new Expr[] { from }, new Expr[] { to }); + } + + /** + * Substitute the free variables in the expression with the expressions in + * For every i smaller than + * num_exprs, the variable with de-Bruijn index i + * is replaced with term to[i]. + **/ + public Expr SubstituteVars(Expr[] to) throws Z3Exception + { + + Context().CheckContextMatch(to); + return Expr.Create(Context(), Native.substituteVars(Context().nCtx(), + NativeObject(), (int) to.length, Expr.ArrayToNative(to))); + } + + /** + * Translates (copies) the term to the Context . + * A context + * + * @return A copy of the term which is associated with + **/ + public Expr Translate(Context ctx) throws Z3Exception + { + + if (Context() == ctx) + return this; + else + return Expr.Create( + ctx, + Native.translate(Context().nCtx(), NativeObject(), + ctx.nCtx())); + } + + /** + * Returns a string representation of the expression. + **/ + public String toString() + { + return super.toString(); + } + + /** + * Indicates whether the term is a numeral + **/ + public boolean IsNumeral() throws Z3Exception + { + return Native.isNumeralAst(Context().nCtx(), NativeObject()); + } + + /** + * Indicates whether the term is well-sorted. + * + * @return True if the term is well-sorted, false otherwise. + **/ + public boolean IsWellSorted() throws Z3Exception + { + return Native.isWellSorted(Context().nCtx(), NativeObject()); + } + + /** + * The Sort of the term. + **/ + public Sort Sort() throws Z3Exception + { + return Sort.Create(Context(), + Native.getSort(Context().nCtx(), NativeObject())); + } + + /** + * Indicates whether the term represents a constant. + **/ + public boolean IsConst() throws Z3Exception + { + return IsExpr() && NumArgs() == 0 && FuncDecl().DomainSize() == 0; + } + + /** + * Indicates whether the term is an integer numeral. + **/ + public boolean IsIntNum() throws Z3Exception + { + return IsNumeral() && IsInt(); + } + + /** + * Indicates whether the term is a real numeral. + **/ + public boolean IsRatNum() throws Z3Exception + { + return IsNumeral() && IsReal(); + } + + /** + * Indicates whether the term is an algebraic number + **/ + public boolean IsAlgebraicNumber() throws Z3Exception + { + return Native.isAlgebraicNumber(Context().nCtx(), NativeObject()); + } + + /** + * Indicates whether the term has Boolean sort. + **/ + public boolean IsBool() throws Z3Exception + { + return (IsExpr() && Native.isEqSort(Context().nCtx(), + Native.mkBoolSort(Context().nCtx()), + Native.getSort(Context().nCtx(), NativeObject()))); + } + + /** + * Indicates whether the term is the constant true. + **/ + public boolean IsTrue() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_TRUE; + } + + /** + * Indicates whether the term is the constant false. + **/ + public boolean IsFalse() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_FALSE; + } + + /** + * Indicates whether the term is an equality predicate. + **/ + public boolean IsEq() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_EQ; + } + + /** + * Indicates whether the term is an n-ary distinct predicate (every argument + * is mutually distinct). + **/ + public boolean IsDistinct() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_DISTINCT; + } + + /** + * Indicates whether the term is a ternary if-then-else term + **/ + public boolean IsITE() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ITE; + } + + /** + * Indicates whether the term is an n-ary conjunction + **/ + public boolean IsAnd() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_AND; + } + + /** + * Indicates whether the term is an n-ary disjunction + **/ + public boolean IsOr() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_OR; + } + + /** + * Indicates whether the term is an if-and-only-if (Boolean equivalence, + * binary) + **/ + public boolean IsIff() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_IFF; + } + + /** + * Indicates whether the term is an exclusive or + **/ + public boolean IsXor() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_XOR; + } + + /** + * Indicates whether the term is a negation + **/ + public boolean IsNot() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_NOT; + } + + /** + * Indicates whether the term is an implication + **/ + public boolean IsImplies() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_IMPLIES; + } + + /** + * Indicates whether the term is of integer sort. + **/ + public boolean IsInt() throws Z3Exception + { + return (Native.isNumeralAst(Context().nCtx(), NativeObject()) && Native + .getSortKind(Context().nCtx(), + Native.getSort(Context().nCtx(), NativeObject())) == Z3_sort_kind.Z3_INT_SORT + .toInt()); + } + + /** + * Indicates whether the term is of sort real. + **/ + public boolean IsReal() throws Z3Exception + { + return Native.getSortKind(Context().nCtx(), + Native.getSort(Context().nCtx(), NativeObject())) == Z3_sort_kind.Z3_REAL_SORT + .toInt(); + } + + /** + * Indicates whether the term is an arithmetic numeral. + **/ + public boolean IsArithmeticNumeral() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ANUM; + } + + /** + * Indicates whether the term is a less-than-or-equal + **/ + public boolean IsLE() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_LE; + } + + /** + * Indicates whether the term is a greater-than-or-equal + **/ + public boolean IsGE() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_GE; + } + + /** + * Indicates whether the term is a less-than + **/ + public boolean IsLT() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_LT; + } + + /** + * Indicates whether the term is a greater-than + **/ + public boolean IsGT() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_GT; + } + + /** + * Indicates whether the term is addition (binary) + **/ + public boolean IsAdd() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ADD; + } + + /** + * Indicates whether the term is subtraction (binary) + **/ + public boolean IsSub() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SUB; + } + + /** + * Indicates whether the term is a unary minus + **/ + public boolean IsUMinus() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_UMINUS; + } + + /** + * Indicates whether the term is multiplication (binary) + **/ + public boolean IsMul() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_MUL; + } + + /** + * Indicates whether the term is division (binary) + **/ + public boolean IsDiv() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_DIV; + } + + /** + * Indicates whether the term is integer division (binary) + **/ + public boolean IsIDiv() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_IDIV; + } + + /** + * Indicates whether the term is remainder (binary) + **/ + public boolean IsRemainder() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_REM; + } + + /** + * Indicates whether the term is modulus (binary) + **/ + public boolean IsModulus() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_MOD; + } + + /** + * Indicates whether the term is a coercion of integer to real (unary) + **/ + public boolean IsIntToReal() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_TO_REAL; + } + + /** + * Indicates whether the term is a coercion of real to integer (unary) + **/ + public boolean IsRealToInt() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_TO_INT; + } + + /** + * Indicates whether the term is a check that tests whether a real is + * integral (unary) + **/ + public boolean IsRealIsInt() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_IS_INT; + } + + /** + * Indicates whether the term is of an array sort. + **/ + public boolean IsArray() throws Z3Exception + { + return (Native.isApp(Context().nCtx(), NativeObject()) && Z3_sort_kind + .fromInt(Native.getSortKind(Context().nCtx(), + Native.getSort(Context().nCtx(), NativeObject()))) == Z3_sort_kind.Z3_ARRAY_SORT); + } + + /** + * Indicates whether the term is an array store. It satisfies + * select(store(a,i,v),j) = if i = j then v else select(a,j). Array store + * takes at least 3 arguments. + **/ + public boolean IsStore() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_STORE; + } + + /** + * Indicates whether the term is an array select. + **/ + public boolean IsSelect() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SELECT; + } + + /** + * Indicates whether the term is a constant array. For example, + * select(const(v),i) = v holds for every v and i. The function is + * unary. + **/ + public boolean IsConstantArray() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_CONST_ARRAY; + } + + /** + * Indicates whether the term is a default array. For example + * default(const(v)) = v. The function is unary. + **/ + public boolean IsDefaultArray() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ARRAY_DEFAULT; + } + + /** + * Indicates whether the term is an array map. It satisfies + * map[f](a1,..,a_n)[i] = f(a1[i],...,a_n[i]) for every i. + **/ + public boolean IsArrayMap() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ARRAY_MAP; + } + + /** + * Indicates whether the term is an as-array term. An as-array term + * is n array value that behaves as the function graph of the function + * passed as parameter. + **/ + public boolean IsAsArray() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_AS_ARRAY; + } + + /** + * Indicates whether the term is set union + **/ + public boolean IsSetUnion() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SET_UNION; + } + + /** + * Indicates whether the term is set intersection + **/ + public boolean IsSetIntersect() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SET_INTERSECT; + } + + /** + * Indicates whether the term is set difference + **/ + public boolean IsSetDifference() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SET_DIFFERENCE; + } + + /** + * Indicates whether the term is set complement + **/ + public boolean IsSetComplement() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SET_COMPLEMENT; + } + + /** + * Indicates whether the term is set subset + **/ + public boolean IsSetSubset() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SET_SUBSET; + } + + /** + * Indicates whether the terms is of bit-vector sort. + **/ + public boolean IsBV() throws Z3Exception + { + return Native.getSortKind(Context().nCtx(), + Native.getSort(Context().nCtx(), NativeObject())) == Z3_sort_kind.Z3_BV_SORT + .toInt(); + } + + /** + * Indicates whether the term is a bit-vector numeral + **/ + public boolean IsBVNumeral() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BNUM; + } + + /** + * Indicates whether the term is a one-bit bit-vector with value one + **/ + public boolean IsBVBitOne() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BIT1; + } + + /** + * Indicates whether the term is a one-bit bit-vector with value zero + **/ + public boolean IsBVBitZero() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BIT0; + } + + /** + * Indicates whether the term is a bit-vector unary minus + **/ + public boolean IsBVUMinus() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BNEG; + } + + /** + * Indicates whether the term is a bit-vector addition (binary) + **/ + public boolean IsBVAdd() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BADD; + } + + /** + * Indicates whether the term is a bit-vector subtraction (binary) + **/ + public boolean IsBVSub() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BSUB; + } + + /** + * Indicates whether the term is a bit-vector multiplication (binary) + **/ + public boolean IsBVMul() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BMUL; + } + + /** + * Indicates whether the term is a bit-vector signed division (binary) + **/ + public boolean IsBVSDiv() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BSDIV; + } + + /** + * Indicates whether the term is a bit-vector unsigned division (binary) + **/ + public boolean IsBVUDiv() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BUDIV; + } + + /** + * Indicates whether the term is a bit-vector signed remainder (binary) + **/ + public boolean IsBVSRem() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BSREM; + } + + /** + * Indicates whether the term is a bit-vector unsigned remainder (binary) + **/ + public boolean IsBVURem() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BUREM; + } + + /** + * Indicates whether the term is a bit-vector signed modulus + **/ + public boolean IsBVSMod() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BSMOD; + } + + /** + * Indicates whether the term is a bit-vector signed division by zero + **/ + boolean IsBVSDiv0() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BSDIV0; + } + + /** + * Indicates whether the term is a bit-vector unsigned division by zero + **/ + boolean IsBVUDiv0() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BUDIV0; + } + + /** + * Indicates whether the term is a bit-vector signed remainder by zero + **/ + boolean IsBVSRem0() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BSREM0; + } + + /** + * Indicates whether the term is a bit-vector unsigned remainder by zero + **/ + boolean IsBVURem0() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BUREM0; + } + + /** + * Indicates whether the term is a bit-vector signed modulus by zero + **/ + boolean IsBVSMod0() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BSMOD0; + } + + /** + * Indicates whether the term is an unsigned bit-vector less-than-or-equal + **/ + public boolean IsBVULE() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ULEQ; + } + + /** + * Indicates whether the term is a signed bit-vector less-than-or-equal + **/ + public boolean IsBVSLE() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SLEQ; + } + + /** + * Indicates whether the term is an unsigned bit-vector + * greater-than-or-equal + **/ + public boolean IsBVUGE() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_UGEQ; + } + + /** + * Indicates whether the term is a signed bit-vector greater-than-or-equal + **/ + public boolean IsBVSGE() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SGEQ; + } + + /** + * Indicates whether the term is an unsigned bit-vector less-than + **/ + public boolean IsBVULT() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ULT; + } + + /** + * Indicates whether the term is a signed bit-vector less-than + **/ + public boolean IsBVSLT() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SLT; + } + + /** + * Indicates whether the term is an unsigned bit-vector greater-than + **/ + public boolean IsBVUGT() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_UGT; + } + + /** + * Indicates whether the term is a signed bit-vector greater-than + **/ + public boolean IsBVSGT() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SGT; + } + + /** + * Indicates whether the term is a bit-wise AND + **/ + public boolean IsBVAND() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BAND; + } + + /** + * Indicates whether the term is a bit-wise OR + **/ + public boolean IsBVOR() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BOR; + } + + /** + * Indicates whether the term is a bit-wise NOT + **/ + public boolean IsBVNOT() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BNOT; + } + + /** + * Indicates whether the term is a bit-wise XOR + **/ + public boolean IsBVXOR() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BXOR; + } + + /** + * Indicates whether the term is a bit-wise NAND + **/ + public boolean IsBVNAND() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BNAND; + } + + /** + * Indicates whether the term is a bit-wise NOR + **/ + public boolean IsBVNOR() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BNOR; + } + + /** + * Indicates whether the term is a bit-wise XNOR + **/ + public boolean IsBVXNOR() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BXNOR; + } + + /** + * Indicates whether the term is a bit-vector concatenation (binary) + **/ + public boolean IsBVConcat() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_CONCAT; + } + + /** + * Indicates whether the term is a bit-vector sign extension + **/ + public boolean IsBVSignExtension() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_SIGN_EXT; + } + + /** + * Indicates whether the term is a bit-vector zero extension + **/ + public boolean IsBVZeroExtension() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ZERO_EXT; + } + + /** + * Indicates whether the term is a bit-vector extraction + **/ + public boolean IsBVExtract() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_EXTRACT; + } + + /** + * Indicates whether the term is a bit-vector repetition + **/ + public boolean IsBVRepeat() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_REPEAT; + } + + /** + * Indicates whether the term is a bit-vector reduce OR + **/ + public boolean IsBVReduceOR() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BREDOR; + } + + /** + * Indicates whether the term is a bit-vector reduce AND + **/ + public boolean IsBVReduceAND() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BREDAND; + } + + /** + * Indicates whether the term is a bit-vector comparison + **/ + public boolean IsBVComp() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BCOMP; + } + + /** + * Indicates whether the term is a bit-vector shift left + **/ + public boolean IsBVShiftLeft() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BSHL; + } + + /** + * Indicates whether the term is a bit-vector logical shift right + **/ + public boolean IsBVShiftRightLogical() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BLSHR; + } + + /** + * Indicates whether the term is a bit-vector arithmetic shift left + **/ + public boolean IsBVShiftRightArithmetic() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BASHR; + } + + /** + * Indicates whether the term is a bit-vector rotate left + **/ + public boolean IsBVRotateLeft() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ROTATE_LEFT; + } + + /** + * Indicates whether the term is a bit-vector rotate right + **/ + public boolean IsBVRotateRight() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_ROTATE_RIGHT; + } + + /** + * Indicates whether the term is a bit-vector rotate left (extended) + * Similar to Z3_OP_ROTATE_LEFT, but it is a binary operator + * instead of a parametric one. + **/ + public boolean IsBVRotateLeftExtended() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_EXT_ROTATE_LEFT; + } + + /** + * Indicates whether the term is a bit-vector rotate right (extended) + * Similar to Z3_OP_ROTATE_RIGHT, but it is a binary operator + * instead of a parametric one. + **/ + public boolean IsBVRotateRightExtended() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_EXT_ROTATE_RIGHT; + } + + /** + * Indicates whether the term is a coercion from integer to bit-vector + * This function is not supported by the decision procedures. Only + * the most rudimentary simplification rules are applied to this + * function. + **/ + public boolean IsIntToBV() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_INT2BV; + } + + /** + * Indicates whether the term is a coercion from bit-vector to integer + * This function is not supported by the decision procedures. Only + * the most rudimentary simplification rules are applied to this + * function. + **/ + public boolean IsBVToInt() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_BV2INT; + } + + /** + * Indicates whether the term is a bit-vector carry Compute the + * carry bit in a full-adder. The meaning is given by the equivalence (carry + * l1 l2 l3) <=> (or (and l1 l2) (and l1 l3) (and l2 l3))) + **/ + public boolean IsBVCarry() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_CARRY; + } + + /** + * Indicates whether the term is a bit-vector ternary XOR The + * meaning is given by the equivalence (xor3 l1 l2 l3) <=> (xor (xor + * l1 l2) l3) + **/ + public boolean IsBVXOR3() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_XOR3; + } + + /** + * Indicates whether the term is a label (used by the Boogie Verification + * condition generator). The label has two parameters, a string and + * a Boolean polarity. It takes one argument, a formula. + **/ + public boolean IsLabel() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_LABEL; + } + + /** + * Indicates whether the term is a label literal (used by the Boogie + * Verification condition generator). A label literal has a set of + * string parameters. It takes no arguments. + **/ + public boolean IsLabelLit() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_LABEL_LIT; + } + + /** + * Indicates whether the term is a binary equivalence modulo namings. + * This binary predicate is used in proof terms. It captures + * equisatisfiability and equivalence modulo renamings. + **/ + public boolean IsOEQ() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_OEQ; + } + + /** + * Indicates whether the term is a Proof for the expression 'true'. + **/ + public boolean IsProofTrue() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_TRUE; + } + + /** + * Indicates whether the term is a proof for a fact asserted by the user. + **/ + public boolean IsProofAsserted() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_ASSERTED; + } + + /** + * Indicates whether the term is a proof for a fact (tagged as goal) + * asserted by the user. + **/ + public boolean IsProofGoal() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_GOAL; + } + + /** + * Indicates whether the term is proof via modus ponens Given a + * proof for p and a proof for (implies p q), produces a proof for q. T1: p + * T2: (implies p q) [mp T1 T2]: q The second antecedents may also be a + * proof for (iff p q). + **/ + public boolean IsProofModusPonens() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_MODUS_PONENS; + } + + /** + * Indicates whether the term is a proof for (R t t), where R is a reflexive + * relation. This proof object has no antecedents. The only + * reflexive relations that are used are equivalence modulo namings, + * equality and equivalence. That is, R is either '~', '=' or + * 'iff'. + **/ + public boolean IsProofReflexivity() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_REFLEXIVITY; + } + + /** + * Indicates whether the term is proof by symmetricity of a relation + * Given an symmetric relation R and a proof for (R t s), produces + * a proof for (R s t). T1: (R t s) [symmetry T1]: (R s t) T1 is the + * antecedent of this proof object. + **/ + public boolean IsProofSymmetry() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_SYMMETRY; + } + + /** + * Indicates whether the term is a proof by transitivity of a relation + * Given a transitive relation R, and proofs for (R t s) and (R s + * u), produces a proof for (R t u). T1: (R t s) T2: (R s u) [trans T1 T2]: + * (R t u) + **/ + public boolean IsProofTransitivity() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_TRANSITIVITY; + } + + /** + * Indicates whether the term is a proof by condensed transitivity of a + * relation Condensed transitivity proof. This proof object is + * only used if the parameter PROOF_MODE is 1. It combines several symmetry + * and transitivity proofs. Example: T1: (R a b) T2: (R c b) T3: (R c d) + * [trans* T1 T2 T3]: (R a d) R must be a symmetric and transitive relation. + * + * Assuming that this proof object is a proof for (R s t), then a proof + * checker must check if it is possible to prove (R s t) using the + * antecedents, symmetry and transitivity. That is, if there is a path from + * s to t, if we view every antecedent (R a b) as an edge between a and b. + * + **/ + public boolean IsProofTransitivityStar() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_TRANSITIVITY_STAR; + } + + /** + * Indicates whether the term is a monotonicity proof object. T1: + * (R t_1 s_1) ... Tn: (R t_n s_n) [monotonicity T1 ... Tn]: (R (f t_1 ... + * t_n) (f s_1 ... s_n)) Remark: if t_i == s_i, then the antecedent Ti is + * suppressed. That is, reflexivity proofs are supressed to save space. + * + **/ + public boolean IsProofMonotonicity() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_MONOTONICITY; + } + + /** + * Indicates whether the term is a quant-intro proof Given a proof + * for (~ p q), produces a proof for (~ (forall (x) p) (forall (x) q)). T1: + * (~ p q) [quant-intro T1]: (~ (forall (x) p) (forall (x) q)) + **/ + public boolean IsProofQuantIntro() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_QUANT_INTRO; + } + + /** + * Indicates whether the term is a distributivity proof object. + * Given that f (= or) distributes over g (= and), produces a proof for (= + * (f a (g c d)) (g (f a c) (f a d))) If f and g are associative, this proof + * also justifies the following equality: (= (f (g a b) (g c d)) (g (f a c) + * (f a d) (f b c) (f b d))) where each f and g can have arbitrary number of + * arguments. + * + * This proof object has no antecedents. Remark. This rule is used by the + * CNF conversion pass and instantiated by f = or, and g = and. + **/ + public boolean IsProofDistributivity() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_DISTRIBUTIVITY; + } + + /** + * Indicates whether the term is a proof by elimination of AND + * Given a proof for (and l_1 ... l_n), produces a proof for l_i T1: (and + * l_1 ... l_n) [and-elim T1]: l_i + **/ + public boolean IsProofAndElimination() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_AND_ELIM; + } + + /** + * Indicates whether the term is a proof by eliminiation of not-or + * Given a proof for (not (or l_1 ... l_n)), produces a proof for (not l_i). + * T1: (not (or l_1 ... l_n)) [not-or-elim T1]: (not l_i) + **/ + public boolean IsProofOrElimination() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_NOT_OR_ELIM; + } + + /** + * Indicates whether the term is a proof by rewriting A proof for + * a local rewriting step (= t s). The head function symbol of t is + * interpreted. + * + * This proof object has no antecedents. The conclusion of a rewrite rule is + * either an equality (= t s), an equivalence (iff t s), or + * equi-satisfiability (~ t s). Remark: if f is bool, then = is iff. + * + * Examples: (= (+ x 0) x) (= (+ x 1 2) (+ 3 x)) (iff (or x false) x) + * + **/ + public boolean IsProofRewrite() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_REWRITE; + } + + /** + * Indicates whether the term is a proof by rewriting A proof for + * rewriting an expression t into an expression s. This proof object is used + * if the parameter PROOF_MODE is 1. This proof object can have n + * antecedents. The antecedents are proofs for equalities used as + * substitution rules. The object is also used in a few cases if the + * parameter PROOF_MODE is 2. The cases are: - When applying contextual + * simplification (CONTEXT_SIMPLIFIER=true) - When converting bit-vectors to + * Booleans (BIT2BOOL=true) - When pulling ite expression up + * (PULL_CHEAP_ITE_TREES=true) + **/ + public boolean IsProofRewriteStar() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_REWRITE_STAR; + } + + /** + * Indicates whether the term is a proof for pulling quantifiers out. + * A proof for (iff (f (forall (x) q(x)) r) (forall (x) (f (q x) + * r))). This proof object has no antecedents. + **/ + public boolean IsProofPullQuant() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_PULL_QUANT; + } + + /** + * Indicates whether the term is a proof for pulling quantifiers out. + * A proof for (iff P Q) where Q is in prenex normal form. This + * proof object is only used if the parameter PROOF_MODE is 1. This proof + * object has no antecedents + **/ + public boolean IsProofPullQuantStar() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_PULL_QUANT_STAR; + } + + /** + * Indicates whether the term is a proof for pushing quantifiers in. + * A proof for: (iff (forall (x_1 ... x_m) (and p_1[x_1 ... x_m] + * ... p_n[x_1 ... x_m])) (and (forall (x_1 ... x_m) p_1[x_1 ... x_m]) ... + * (forall (x_1 ... x_m) p_n[x_1 ... x_m]))) This proof object has no + * antecedents + **/ + public boolean IsProofPushQuant() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_PUSH_QUANT; + } + + /** + * Indicates whether the term is a proof for elimination of unused + * variables. A proof for (iff (forall (x_1 ... x_n y_1 ... y_m) + * p[x_1 ... x_n]) (forall (x_1 ... x_n) p[x_1 ... x_n])) + * + * It is used to justify the elimination of unused variables. This proof + * object has no antecedents. + **/ + public boolean IsProofElimUnusedVars() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_ELIM_UNUSED_VARS; + } + + /** + * Indicates whether the term is a proof for destructive equality resolution + * A proof for destructive equality resolution: (iff (forall (x) + * (or (not (= x t)) P[x])) P[t]) if x does not occur in t. + * + * This proof object has no antecedents. + * + * Several variables can be eliminated simultaneously. + **/ + public boolean IsProofDER() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_DER; + } + + /** + * Indicates whether the term is a proof for quantifier instantiation + * A proof of (or (not (forall (x) (P x))) (P a)) + **/ + public boolean IsProofQuantInst() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_QUANT_INST; + } + + /** + * Indicates whether the term is a hypthesis marker. Mark a + * hypothesis in a natural deduction style proof. + **/ + public boolean IsProofHypothesis() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_HYPOTHESIS; + } + + /** + * Indicates whether the term is a proof by lemma T1: false [lemma + * T1]: (or (not l_1) ... (not l_n)) + * + * This proof object has one antecedent: a hypothetical proof for false. It + * converts the proof in a proof for (or (not l_1) ... (not l_n)), when T1 + * contains the hypotheses: l_1, ..., l_n. + **/ + public boolean IsProofLemma() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_LEMMA; + } + + /** + * Indicates whether the term is a proof by unit resolution T1: + * (or l_1 ... l_n l_1' ... l_m') T2: (not l_1) ... T(n+1): (not l_n) + * [unit-resolution T1 ... T(n+1)]: (or l_1' ... l_m') + **/ + public boolean IsProofUnitResolution() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_UNIT_RESOLUTION; + } + + /** + * Indicates whether the term is a proof by iff-true T1: p + * [iff-true T1]: (iff p true) + **/ + public boolean IsProofIFFTrue() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_IFF_TRUE; + } + + /** + * Indicates whether the term is a proof by iff-false T1: (not p) + * [iff-false T1]: (iff p false) + **/ + public boolean IsProofIFFFalse() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_IFF_FALSE; + } + + /** + * Indicates whether the term is a proof by commutativity [comm]: + * (= (f a b) (f b a)) + * + * f is a commutative operator. + * + * This proof object has no antecedents. Remark: if f is bool, then = is + * iff. + **/ + public boolean IsProofCommutativity() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_COMMUTATIVITY; + } + + /** + * Indicates whether the term is a proof for Tseitin-like axioms + * Proof object used to justify Tseitin's like axioms: + * + * (or (not (and p q)) p) (or (not (and p q)) q) (or (not (and p q r)) p) + * (or (not (and p q r)) q) (or (not (and p q r)) r) ... (or (and p q) (not + * p) (not q)) (or (not (or p q)) p q) (or (or p q) (not p)) (or (or p q) + * (not q)) (or (not (iff p q)) (not p) q) (or (not (iff p q)) p (not q)) + * (or (iff p q) (not p) (not q)) (or (iff p q) p q) (or (not (ite a b c)) + * (not a) b) (or (not (ite a b c)) a c) (or (ite a b c) (not a) (not b)) + * (or (ite a b c) a (not c)) (or (not (not a)) (not a)) (or (not a) a) + * + * This proof object has no antecedents. Note: all axioms are propositional + * tautologies. Note also that 'and' and 'or' can take multiple arguments. + * You can recover the propositional tautologies by unfolding the Boolean + * connectives in the axioms a small bounded number of steps (=3). + * + **/ + public boolean IsProofDefAxiom() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_DEF_AXIOM; + } + + /** + * Indicates whether the term is a proof for introduction of a name + * Introduces a name for a formula/term. Suppose e is an + * expression with free variables x, and def-intro introduces the name n(x). + * The possible cases are: + * + * When e is of Boolean type: [def-intro]: (and (or n (not e)) (or (not n) + * e)) + * + * or: [def-intro]: (or (not n) e) when e only occurs positively. + * + * When e is of the form (ite cond th el): [def-intro]: (and (or (not cond) + * (= n th)) (or cond (= n el))) + * + * Otherwise: [def-intro]: (= n e) + **/ + public boolean IsProofDefIntro() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_DEF_INTRO; + } + + /** + * Indicates whether the term is a proof for application of a definition + * [apply-def T1]: F ~ n F is 'equivalent' to n, given that T1 is + * a proof that n is a name for F. + **/ + public boolean IsProofApplyDef() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_APPLY_DEF; + } + + /** + * Indicates whether the term is a proof iff-oeq T1: (iff p q) + * [iff~ T1]: (~ p q) + **/ + public boolean IsProofIFFOEQ() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_IFF_OEQ; + } + + /** + * Indicates whether the term is a proof for a positive NNF step + * Proof for a (positive) NNF step. Example: + * + * T1: (not s_1) ~ r_1 T2: (not s_2) ~ r_2 T3: s_1 ~ r_1' T4: s_2 ~ r_2' + * [nnf-pos T1 T2 T3 T4]: (~ (iff s_1 s_2) (and (or r_1 r_2') (or r_1' + * r_2))) + * + * The negation normal form steps NNF_POS and NNF_NEG are used in the + * following cases: (a) When creating the NNF of a positive force + * quantifier. The quantifier is retained (unless the bound variables are + * eliminated). Example T1: q ~ q_new [nnf-pos T1]: (~ (forall (x T) q) + * (forall (x T) q_new)) + * + * (b) When recursively creating NNF over Boolean formulas, where the + * top-level connective is changed during NNF conversion. The relevant + * Boolean connectives for NNF_POS are 'implies', 'iff', 'xor', 'ite'. + * NNF_NEG furthermore handles the case where negation is pushed over + * Boolean connectives 'and' and 'or'. + **/ + public boolean IsProofNNFPos() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_NNF_POS; + } + + /** + * Indicates whether the term is a proof for a negative NNF step + * Proof for a (negative) NNF step. Examples: + * + * T1: (not s_1) ~ r_1 ... Tn: (not s_n) ~ r_n [nnf-neg T1 ... Tn]: (not + * (and s_1 ... s_n)) ~ (or r_1 ... r_n) and T1: (not s_1) ~ r_1 ... Tn: + * (not s_n) ~ r_n [nnf-neg T1 ... Tn]: (not (or s_1 ... s_n)) ~ (and r_1 + * ... r_n) and T1: (not s_1) ~ r_1 T2: (not s_2) ~ r_2 T3: s_1 ~ r_1' T4: + * s_2 ~ r_2' [nnf-neg T1 T2 T3 T4]: (~ (not (iff s_1 s_2)) (and (or r_1 + * r_2) (or r_1' r_2'))) + **/ + public boolean IsProofNNFNeg() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_NNF_NEG; + } + + /** + * Indicates whether the term is a proof for (~ P Q) here Q is in negation + * normal form. A proof for (~ P Q) where Q is in negation normal + * form. + * + * This proof object is only used if the parameter PROOF_MODE is 1. + * + * This proof object may have n antecedents. Each antecedent is a + * PR_DEF_INTRO. + **/ + public boolean IsProofNNFStar() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_NNF_STAR; + } + + /** + * Indicates whether the term is a proof for (~ P Q) where Q is in + * conjunctive normal form. A proof for (~ P Q) where Q is in + * conjunctive normal form. This proof object is only used if the parameter + * PROOF_MODE is 1. This proof object may have n antecedents. Each + * antecedent is a PR_DEF_INTRO. + **/ + public boolean IsProofCNFStar() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_CNF_STAR; + } + + /** + * Indicates whether the term is a proof for a Skolemization step + * Proof for: + * + * [sk]: (~ (not (forall x (p x y))) (not (p (sk y) y))) [sk]: (~ (exists x + * (p x y)) (p (sk y) y)) + * + * This proof object has no antecedents. + **/ + public boolean IsProofSkolemize() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_SKOLEMIZE; + } + + /** + * Indicates whether the term is a proof by modus ponens for + * equi-satisfiability. Modus ponens style rule for + * equi-satisfiability. T1: p T2: (~ p q) [mp~ T1 T2]: q + **/ + public boolean IsProofModusPonensOEQ() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_MODUS_PONENS_OEQ; + } + + /** + * Indicates whether the term is a proof for theory lemma Generic + * proof for theory lemmas. + * + * The theory lemma function comes with one or more parameters. The first + * parameter indicates the name of the theory. For the theory of arithmetic, + * additional parameters provide hints for checking the theory lemma. The + * hints for arithmetic are: - farkas - followed by rational coefficients. + * Multiply the coefficients to the inequalities in the lemma, add the + * (negated) inequalities and obtain a contradiction. - triangle-eq - + * Indicates a lemma related to the equivalence: (iff (= t1 t2) (and (<= + * t1 t2) (<= t2 t1))) - gcd-test - Indicates an integer linear + * arithmetic lemma that uses a gcd test. + **/ + public boolean IsProofTheoryLemma() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_PR_TH_LEMMA; + } + + /** + * Indicates whether the term is of an array sort. + **/ + public boolean IsRelation() throws Z3Exception + { + return (Native.isApp(Context().nCtx(), NativeObject()) && Native + .getSortKind(Context().nCtx(), + Native.getSort(Context().nCtx(), NativeObject())) == Z3_sort_kind.Z3_RELATION_SORT + .toInt()); + } + + /** + * Indicates whether the term is an relation store Insert a record + * into a relation. The function takes n+1 arguments, where the + * first argument is the relation and the remaining n elements + * correspond to the n columns of the relation. + **/ + public boolean IsRelationStore() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_STORE; + } + + /** + * Indicates whether the term is an empty relation + **/ + public boolean IsEmptyRelation() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_EMPTY; + } + + /** + * Indicates whether the term is a test for the emptiness of a relation + **/ + public boolean IsIsEmptyRelation() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_IS_EMPTY; + } + + /** + * Indicates whether the term is a relational join + **/ + public boolean IsRelationalJoin() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_JOIN; + } + + /** + * Indicates whether the term is the union or convex hull of two relations. + * The function takes two arguments. + **/ + public boolean IsRelationUnion() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_UNION; + } + + /** + * Indicates whether the term is the widening of two relations The + * function takes two arguments. + **/ + public boolean IsRelationWiden() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_WIDEN; + } + + /** + * Indicates whether the term is a projection of columns (provided as + * numbers in the parameters). The function takes one + * argument. + **/ + public boolean IsRelationProject() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_PROJECT; + } + + /** + * Indicates whether the term is a relation filter Filter + * (restrict) a relation with respect to a predicate. The first argument is + * a relation. The second argument is a predicate with free de-Brujin + * indices corresponding to the columns of the relation. So the first column + * in the relation has index 0. + **/ + public boolean IsRelationFilter() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_FILTER; + } + + /** + * Indicates whether the term is an intersection of a relation with the + * negation of another. Intersect the first relation with respect + * to negation of the second relation (the function takes two arguments). + * Logically, the specification can be described by a function + * + * target = filter_by_negation(pos, neg, columns) + * + * where columns are pairs c1, d1, .., cN, dN of columns from pos and neg, + * such that target are elements in x in pos, such that there is no y in neg + * that agrees with x on the columns c1, d1, .., cN, dN. + **/ + public boolean IsRelationNegationFilter() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_NEGATION_FILTER; + } + + /** + * Indicates whether the term is the renaming of a column in a relation + * The function takes one argument. The parameters contain the + * renaming as a cycle. + **/ + public boolean IsRelationRename() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_RENAME; + } + + /** + * Indicates whether the term is the complement of a relation + **/ + public boolean IsRelationComplement() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_COMPLEMENT; + } + + /** + * Indicates whether the term is a relational select Check if a + * record is an element of the relation. The function takes n+1 + * arguments, where the first argument is a relation, and the remaining + * n arguments correspond to a record. + **/ + public boolean IsRelationSelect() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_SELECT; + } + + /** + * Indicates whether the term is a relational clone (copy) Create + * a fresh copy (clone) of a relation. The function is logically the + * identity, but in the context of a register machine allows for terms of + * kind to perform destructive updates to + * the first argument. + **/ + public boolean IsRelationClone() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_RA_CLONE; + } + + /** + * Indicates whether the term is of an array sort. + **/ + public boolean IsFiniteDomain() throws Z3Exception + { + return (Native.isApp(Context().nCtx(), NativeObject()) && Native + .getSortKind(Context().nCtx(), + Native.getSort(Context().nCtx(), NativeObject())) == Z3_sort_kind.Z3_FINITE_DOMAIN_SORT + .toInt()); + } + + /** + * Indicates whether the term is a less than predicate over a finite domain. + **/ + public boolean IsFiniteDomainLT() throws Z3Exception + { + return FuncDecl().DeclKind() == Z3_decl_kind.Z3_OP_FD_LT; + } + + /** + * The de-Burijn index of a bound variable. Bound variables are + * indexed by de-Bruijn indices. It is perhaps easiest to explain the + * meaning of de-Bruijn indices by indicating the compilation process from + * non-de-Bruijn formulas to de-Bruijn format. + * abs(forall (x1) phi) = forall (x1) abs1(phi, x1, 0) + * abs(forall (x1, x2) phi) = abs(forall (x1) abs(forall (x2) phi)) + * abs1(x, x, n) = b_n + * abs1(y, x, n) = y + * abs1(f(t1,...,tn), x, n) = f(abs1(t1,x,n), ..., abs1(tn,x,n)) + * abs1(forall (x1) phi, x, n) = forall (x1) (abs1(phi, x, n+1)) + * The last line is significant: the index of a bound variable is + * different depending on the scope in which it appears. The deeper x + * appears, the higher is its index. + **/ + public int Index() throws Z3Exception + { + if (!IsVar()) + throw new Z3Exception("Term is not a bound variable."); + + return Native.getIndexValue(Context().nCtx(), NativeObject()); + } + + /** + * Constructor for Expr + **/ + protected Expr(Context ctx) + { + super(ctx); + { + } + } + + /** + * Constructor for Expr + **/ + protected Expr(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + { + } + } + + void CheckNativeObject(long obj) throws Z3Exception + { + if (Native.isApp(Context().nCtx(), obj) + ^ true + && Native.getAstKind(Context().nCtx(), obj) != Z3_ast_kind.Z3_VAR_AST + .toInt() + && Native.getAstKind(Context().nCtx(), obj) != Z3_ast_kind.Z3_QUANTIFIER_AST + .toInt()) + throw new Z3Exception("Underlying object is not a term"); + super.CheckNativeObject(obj); + } + + static Expr Create(Context ctx, FuncDecl f, Expr[] arguments) + throws Z3Exception + { + + long obj = Native.mkApp(ctx.nCtx(), f.NativeObject(), + AST.ArrayLength(arguments), AST.ArrayToNative(arguments)); + return Create(ctx, obj); + } + + static Expr Create(Context ctx, long obj) throws Z3Exception + { + + Z3_ast_kind k = Z3_ast_kind.fromInt(Native.getAstKind(ctx.nCtx(), obj)); + if (k == Z3_ast_kind.Z3_QUANTIFIER_AST) + return new Quantifier(ctx, obj); + long s = Native.getSort(ctx.nCtx(), obj); + Z3_sort_kind sk = Z3_sort_kind + .fromInt(Native.getSortKind(ctx.nCtx(), s)); + + if (Native.isAlgebraicNumber(ctx.nCtx(), obj)) // is this a numeral ast? + return new AlgebraicNum(ctx, obj); + + if (Native.isNumeralAst(ctx.nCtx(), obj)) + { + switch (sk) + { + case Z3_INT_SORT: + return new IntNum(ctx, obj); + case Z3_REAL_SORT: + return new RatNum(ctx, obj); + case Z3_BV_SORT: + return new BitVecNum(ctx, obj); + case Z3_UNKNOWN_SORT: + throw new Z3Exception("Unknown Sort"); + default: ; + } + } + + switch (sk) + { + case Z3_BOOL_SORT: + return new BoolExpr(ctx, obj); + case Z3_INT_SORT: + return new IntExpr(ctx, obj); + case Z3_REAL_SORT: + return new RealExpr(ctx, obj); + case Z3_BV_SORT: + return new BitVecExpr(ctx, obj); + case Z3_ARRAY_SORT: + return new ArrayExpr(ctx, obj); + case Z3_DATATYPE_SORT: + return new DatatypeExpr(ctx, obj); + case Z3_UNKNOWN_SORT: + throw new Z3Exception("Unknown Sort"); + default: ; + } + + return new Expr(ctx, obj); + } +} diff --git a/src/api/java/FiniteDomainSort.java b/src/api/java/FiniteDomainSort.java new file mode 100644 index 000000000..f9f3820af --- /dev/null +++ b/src/api/java/FiniteDomainSort.java @@ -0,0 +1,34 @@ +/** + * This file was automatically generated from FiniteDomainSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Finite domain sorts. + **/ +public class FiniteDomainSort extends Sort +{ + /** + * The size of the finite domain sort. + **/ + public long Size() + { + Native.LongPtr res = new Native.LongPtr(); + Native.getFiniteDomainSortSize(Context().nCtx(), NativeObject(), res); + return res.value; + } + + FiniteDomainSort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + FiniteDomainSort(Context ctx, Symbol name, long size) throws Z3Exception + { + super(ctx, Native.mkFiniteDomainSort(ctx.nCtx(), name.NativeObject(), + size)); + } +} diff --git a/src/api/java/Fixedpoint.java b/src/api/java/Fixedpoint.java new file mode 100644 index 000000000..3ad42c0e9 --- /dev/null +++ b/src/api/java/Fixedpoint.java @@ -0,0 +1,327 @@ +/** + * This file was automatically generated from Fixedpoint.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * Object for managing fixedpoints + **/ +public class Fixedpoint extends Z3Object +{ + + /** + * A string that describes all available fixedpoint solver parameters. + **/ + public String Help() + { + + return Native.fixedpointGetHelp(Context().nCtx(), NativeObject()); + } + + /** + * Sets the fixedpoint solver parameters. + * + * @throws Z3Exception + **/ + public void setParameters(Params value) throws Z3Exception + { + + Context().CheckContextMatch(value); + Native.fixedpointSetParams(Context().nCtx(), NativeObject(), + value.NativeObject()); + } + + /** + * Retrieves parameter descriptions for Fixedpoint solver. + * @throws Z3Exception + **/ + public ParamDescrs ParameterDescriptions() throws Z3Exception + { + return new ParamDescrs(Context(), Native.fixedpointGetParamDescrs( + Context().nCtx(), NativeObject())); + } + + /** + * Assert a constraint (or multiple) into the fixedpoint solver. + * + * @throws Z3Exception + **/ + public void Assert(BoolExpr[] constraints) throws Z3Exception + { + + Context().CheckContextMatch(constraints); + for (BoolExpr a : constraints) + { + Native.fixedpointAssert(Context().nCtx(), NativeObject(), + a.NativeObject()); + } + } + + /** + * Register predicate as recursive relation. + * + * @throws Z3Exception + **/ + public void RegisterRelation(FuncDecl f) throws Z3Exception + { + + Context().CheckContextMatch(f); + Native.fixedpointRegisterRelation(Context().nCtx(), NativeObject(), + f.NativeObject()); + } + + /** + * Add rule into the fixedpoint solver. + * + * @throws Z3Exception + **/ + public void AddRule(BoolExpr rule, Symbol name) throws Z3Exception + { + + Context().CheckContextMatch(rule); + Native.fixedpointAddRule(Context().nCtx(), NativeObject(), + rule.NativeObject(), AST.GetNativeObject(name)); + } + + /** + * Add table fact to the fixedpoint solver. + * + * @throws Z3Exception + **/ + public void AddFact(FuncDecl pred, int[] args) throws Z3Exception + { + + Context().CheckContextMatch(pred); + Native.fixedpointAddFact(Context().nCtx(), NativeObject(), + pred.NativeObject(), (int) args.length, args); + } + + /** + * Query the fixedpoint solver. A query is a conjunction of constraints. The + * constraints may include the recursively defined relations. The query is + * satisfiable if there is an instance of the query variables and a + * derivation for it. The query is unsatisfiable if there are no derivations + * satisfying the query variables. + * + * @throws Z3Exception + **/ + public Status Query(BoolExpr query) throws Z3Exception + { + + Context().CheckContextMatch(query); + Z3_lbool r = Z3_lbool.fromInt(Native.fixedpointQuery(Context().nCtx(), + NativeObject(), query.NativeObject())); + switch (r) + { + case Z3_L_TRUE: + return Status.SATISFIABLE; + case Z3_L_FALSE: + return Status.UNSATISFIABLE; + default: + return Status.UNKNOWN; + } + } + + /** + * Query the fixedpoint solver. A query is an array of relations. The query + * is satisfiable if there is an instance of some relation that is + * non-empty. The query is unsatisfiable if there are no derivations + * satisfying any of the relations. + * + * @throws Z3Exception + **/ + public Status Query(FuncDecl[] relations) throws Z3Exception + { + + Context().CheckContextMatch(relations); + Z3_lbool r = Z3_lbool.fromInt(Native.fixedpointQueryRelations(Context() + .nCtx(), NativeObject(), AST.ArrayLength(relations), AST + .ArrayToNative(relations))); + switch (r) + { + case Z3_L_TRUE: + return Status.SATISFIABLE; + case Z3_L_FALSE: + return Status.UNSATISFIABLE; + default: + return Status.UNKNOWN; + } + } + + /** + * Creates a backtracking point. + **/ + public void Push() + { + Native.fixedpointPush(Context().nCtx(), NativeObject()); + } + + /** + * Backtrack one backtracking point. Note that an exception is + * thrown if Pop is called without a corresponding Push + * + **/ + public void Pop() + { + Native.fixedpointPop(Context().nCtx(), NativeObject()); + } + + /** + * Update named rule into in the fixedpoint solver. + * + * @throws Z3Exception + **/ + public void UpdateRule(BoolExpr rule, Symbol name) throws Z3Exception + { + + Context().CheckContextMatch(rule); + Native.fixedpointUpdateRule(Context().nCtx(), NativeObject(), + rule.NativeObject(), AST.GetNativeObject(name)); + } + + /** + * Retrieve satisfying instance or instances of solver, or definitions for + * the recursive predicates that show unsatisfiability. + * + * @throws Z3Exception + **/ + public Expr GetAnswer() throws Z3Exception + { + long ans = Native.fixedpointGetAnswer(Context().nCtx(), NativeObject()); + return (ans == 0) ? null : Expr.Create(Context(), ans); + } + + /** + * Retrieve explanation why fixedpoint engine returned status Unknown. + **/ + public String GetReasonUnknown() + { + + return Native.fixedpointGetReasonUnknown(Context().nCtx(), + NativeObject()); + } + + /** + * Retrieve the number of levels explored for a given predicate. + **/ + public int GetNumLevels(FuncDecl predicate) + { + return Native.fixedpointGetNumLevels(Context().nCtx(), NativeObject(), + predicate.NativeObject()); + } + + /** + * Retrieve the cover of a predicate. + * + * @throws Z3Exception + **/ + public Expr GetCoverDelta(int level, FuncDecl predicate) throws Z3Exception + { + long res = Native.fixedpointGetCoverDelta(Context().nCtx(), + NativeObject(), level, predicate.NativeObject()); + return (res == 0) ? null : Expr.Create(Context(), res); + } + + /** + * Add property about the predicate. The property is added + * at level. + **/ + public void AddCover(int level, FuncDecl predicate, Expr property) + { + Native.fixedpointAddCover(Context().nCtx(), NativeObject(), level, + predicate.NativeObject(), property.NativeObject()); + } + + /** + * Retrieve internal string representation of fixedpoint object. + **/ + public String toString() + { + return Native.fixedpointToString(Context().nCtx(), NativeObject(), 0, + null); + } + + /** + * Instrument the Datalog engine on which table representation to use for + * recursive predicate. + **/ + public void SetPredicateRepresentation(FuncDecl f, Symbol[] kinds) + { + + Native.fixedpointSetPredicateRepresentation(Context().nCtx(), + NativeObject(), f.NativeObject(), AST.ArrayLength(kinds), + Symbol.ArrayToNative(kinds)); + + } + + /** + * Convert benchmark given as set of axioms, rules and queries to a string. + **/ + public String toString(BoolExpr[] queries) + { + + return Native.fixedpointToString(Context().nCtx(), NativeObject(), + AST.ArrayLength(queries), AST.ArrayToNative(queries)); + } + + /** + * Retrieve set of rules added to fixedpoint context. + * + * @throws Z3Exception + **/ + public BoolExpr[] Rules() throws Z3Exception + { + + ASTVector v = new ASTVector(Context(), Native.fixedpointGetRules( + Context().nCtx(), NativeObject())); + int n = v.Size(); + BoolExpr[] res = new BoolExpr[n]; + for (int i = 0; i < n; i++) + res[i] = new BoolExpr(Context(), v.get(i).NativeObject()); + return res; + } + + /** + * Retrieve set of assertions added to fixedpoint context. + * + * @throws Z3Exception + **/ + public BoolExpr[] Assertions() throws Z3Exception + { + + ASTVector v = new ASTVector(Context(), Native.fixedpointGetAssertions( + Context().nCtx(), NativeObject())); + int n = v.Size(); + BoolExpr[] res = new BoolExpr[n]; + for (int i = 0; i < n; i++) + res[i] = new BoolExpr(Context(), v.get(i).NativeObject()); + return res; + } + + Fixedpoint(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + Fixedpoint(Context ctx) throws Z3Exception + { + super(ctx, Native.mkFixedpoint(ctx.nCtx())); + } + + void IncRef(long o) throws Z3Exception + { + Context().Fixedpoint_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().Fixedpoint_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/FixedpointDecRefQueue.java b/src/api/java/FixedpointDecRefQueue.java new file mode 100644 index 000000000..7ed457bed --- /dev/null +++ b/src/api/java/FixedpointDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class FixedpointDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.fixedpointIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.fixedpointDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/FuncDecl.java b/src/api/java/FuncDecl.java new file mode 100644 index 000000000..79fc457f8 --- /dev/null +++ b/src/api/java/FuncDecl.java @@ -0,0 +1,379 @@ +/** + * This file was automatically generated from FuncDecl.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * Function declarations. + **/ +public class FuncDecl extends AST +{ + /** + * Comparison operator. + * + * @return True if and share the + * same context and are equal, false otherwise. + **/ + /* Overloaded operators are not translated. */ + + /** + * Comparison operator. + * + * @return True if and do not + * share the same context or are not equal, false otherwise. + **/ + /* Overloaded operators are not translated. */ + + /** + * Object comparison. + **/ + public boolean Equals(Object o) + { + FuncDecl casted = (FuncDecl) o; + if (casted == null) + return false; + return this == casted; + } + + /** + * A hash code. + **/ + public int GetHashCode() throws Z3Exception + { + return super.GetHashCode(); + } + + /** + * A string representations of the function declaration. + **/ + public String toString() + { + return Native.funcDeclToString(Context().nCtx(), NativeObject()); + } + + /** + * Returns a unique identifier for the function declaration. + **/ + public int Id() throws Z3Exception + { + return Native.getFuncDeclId(Context().nCtx(), NativeObject()); + } + + /** + * The arity of the function declaration + **/ + public int Arity() throws Z3Exception + { + return Native.getArity(Context().nCtx(), NativeObject()); + } + + /** + * The size of the domain of the function declaration + **/ + public int DomainSize() + { + return Native.getDomainSize(Context().nCtx(), NativeObject()); + } + + /** + * The domain of the function declaration + **/ + public Sort[] Domain() throws Z3Exception + { + + int n = DomainSize(); + + Sort[] res = new Sort[n]; + for (int i = 0; i < n; i++) + res[i] = Sort.Create(Context(), + Native.getDomain(Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * The range of the function declaration + **/ + public Sort Range() throws Z3Exception + { + + return Sort.Create(Context(), + Native.getRange(Context().nCtx(), NativeObject())); + } + + /** + * The kind of the function declaration. + **/ + public Z3_decl_kind DeclKind() throws Z3Exception + { + return Z3_decl_kind.fromInt(Native.getDeclKind(Context().nCtx(), + NativeObject())); + } + + /** + * The name of the function declaration + **/ + public Symbol Name() throws Z3Exception + { + + return Symbol.Create(Context(), + Native.getDeclName(Context().nCtx(), NativeObject())); + } + + /** + * The number of parameters of the function declaration + **/ + public int NumParameters() throws Z3Exception + { + return Native.getDeclNumParameters(Context().nCtx(), NativeObject()); + } + + /** + * The parameters of the function declaration + **/ + public Parameter[] Parameters() throws Z3Exception + { + + int num = NumParameters(); + Parameter[] res = new Parameter[num]; + for (int i = 0; i < num; i++) + { + Z3_parameter_kind k = Z3_parameter_kind.fromInt(Native + .getDeclParameterKind(Context().nCtx(), NativeObject(), i)); + switch (k) + { + case Z3_PARAMETER_INT: + res[i] = new Parameter(k, Native.getDeclIntParameter(Context() + .nCtx(), NativeObject(), i)); + break; + case Z3_PARAMETER_DOUBLE: + res[i] = new Parameter(k, Native.getDeclDoubleParameter( + Context().nCtx(), NativeObject(), i)); + break; + case Z3_PARAMETER_SYMBOL: + res[i] = new Parameter(k, Symbol.Create(Context(), Native + .getDeclSymbolParameter(Context().nCtx(), + NativeObject(), i))); + break; + case Z3_PARAMETER_SORT: + res[i] = new Parameter(k, Sort.Create(Context(), Native + .getDeclSortParameter(Context().nCtx(), NativeObject(), + i))); + break; + case Z3_PARAMETER_AST: + res[i] = new Parameter(k, new AST(Context(), + Native.getDeclAstParameter(Context().nCtx(), + NativeObject(), i))); + break; + case Z3_PARAMETER_FUNC_DECL: + res[i] = new Parameter(k, new FuncDecl(Context(), + Native.getDeclFuncDeclParameter(Context().nCtx(), + NativeObject(), i))); + break; + case Z3_PARAMETER_RATIONAL: + res[i] = new Parameter(k, Native.getDeclRationalParameter( + Context().nCtx(), NativeObject(), i)); + break; + default: + throw new Z3Exception( + "Unknown function declaration parameter kind encountered"); + } + } + return res; + } + + /** + * Function declarations can have Parameters associated with them. + **/ + public class Parameter + { + private Z3_parameter_kind kind; + private int i; + private double d; + private Symbol sym; + private Sort srt; + private AST ast; + private FuncDecl fd; + private String r; + + /** + * The int value of the parameter. + **/ + public int Int() throws Z3Exception + { + if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_INT) + throw new Z3Exception("parameter is not an int"); + return i; + } + + /** + * The double value of the parameter. + **/ + public double Double() throws Z3Exception + { + if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_DOUBLE) + throw new Z3Exception("parameter is not a double "); + return d; + } + + /** + * The Symbol value of the parameter. + **/ + public Symbol Symbol() throws Z3Exception + { + if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_SYMBOL) + throw new Z3Exception("parameter is not a Symbol"); + return sym; + } + + /** + * The Sort value of the parameter. + **/ + public Sort Sort() throws Z3Exception + { + if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_SORT) + throw new Z3Exception("parameter is not a Sort"); + return srt; + } + + /** + * The AST value of the parameter. + **/ + public AST AST() throws Z3Exception + { + if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_AST) + throw new Z3Exception("parameter is not an AST"); + return ast; + } + + /** + * The FunctionDeclaration value of the parameter. + **/ + public FuncDecl FuncDecl() throws Z3Exception + { + if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_FUNC_DECL) + throw new Z3Exception("parameter is not a function declaration"); + return fd; + } + + /** + * The rational string value of the parameter. + **/ + public String Rational() throws Z3Exception + { + if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_RATIONAL) + throw new Z3Exception("parameter is not a rational String"); + return r; + } + + /** + * The kind of the parameter. + **/ + public Z3_parameter_kind ParameterKind() throws Z3Exception + { + return kind; + } + + Parameter(Z3_parameter_kind k, int i) + { + this.kind = k; + this.i = i; + } + + Parameter(Z3_parameter_kind k, double d) + { + this.kind = k; + this.d = d; + } + + Parameter(Z3_parameter_kind k, Symbol s) + { + this.kind = k; + this.sym = s; + } + + Parameter(Z3_parameter_kind k, Sort s) + { + this.kind = k; + this.srt = s; + } + + Parameter(Z3_parameter_kind k, AST a) + { + this.kind = k; + this.ast = a; + } + + Parameter(Z3_parameter_kind k, FuncDecl fd) + { + this.kind = k; + this.fd = fd; + } + + Parameter(Z3_parameter_kind k, String r) + { + this.kind = k; + this.r = r; + } + } + + FuncDecl(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + + } + + FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range) + throws Z3Exception + { + super(ctx, Native.mkFuncDecl(ctx.nCtx(), name.NativeObject(), + AST.ArrayLength(domain), AST.ArrayToNative(domain), + range.NativeObject())); + + } + + FuncDecl(Context ctx, String prefix, Sort[] domain, Sort range) + throws Z3Exception + { + super(ctx, Native.mkFreshFuncDecl(ctx.nCtx(), prefix, + AST.ArrayLength(domain), AST.ArrayToNative(domain), + range.NativeObject())); + + } + + void CheckNativeObject(long obj) throws Z3Exception + { + if (Native.getAstKind(Context().nCtx(), obj) != Z3_ast_kind.Z3_FUNC_DECL_AST + .toInt()) + throw new Z3Exception( + "Underlying object is not a function declaration"); + super.CheckNativeObject(obj); + } + + /** + * Create expression that applies function to arguments. + * + * @return + **/ + /* operator this[] not translated */ + + /** + * Create expression that applies function to arguments. + * + * @return + **/ + public Expr Apply(Expr[] args) throws Z3Exception + { + + Context().CheckContextMatch(args); + return Expr.Create(Context(), this, args); + } + +} diff --git a/src/api/java/FuncInterp.java b/src/api/java/FuncInterp.java new file mode 100644 index 000000000..8c25508e7 --- /dev/null +++ b/src/api/java/FuncInterp.java @@ -0,0 +1,185 @@ +/** + * This file was automatically generated from FuncInterp.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * A function interpretation is represented as a finite map and an 'else' value. + * Each entry in the finite map represents the value of a function given a set + * of arguments. + **/ +public class FuncInterp extends Z3Object +{ + /** + * An Entry object represents an element in the finite map used to encode a + * function interpretation. + **/ + public class Entry extends Z3Object + { + /** + * Return the (symbolic) value of this entry. + * + * @throws Z3Exception + **/ + public Expr Value() throws Z3Exception + { + return Expr.Create(Context(), + Native.funcEntryGetValue(Context().nCtx(), NativeObject())); + } + + /** + * The number of arguments of the entry. + **/ + public int NumArgs() + { + return Native.funcEntryGetNumArgs(Context().nCtx(), NativeObject()); + } + + /** + * The arguments of the function entry. + * + * @throws Z3Exception + **/ + public Expr[] Args() throws Z3Exception + { + int n = NumArgs(); + Expr[] res = new Expr[n]; + for (int i = 0; i < n; i++) + res[i] = Expr.Create(Context(), Native.funcEntryGetArg( + Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * A string representation of the function entry. + **/ + public String toString() + { + try + { + int n = NumArgs(); + String res = "["; + Expr[] args = Args(); + for (int i = 0; i < n; i++) + res += args[i] + ", "; + return res + Value() + "]"; + } catch (Z3Exception e) + { + return new String("Z3Exception: " + e.getMessage()); + } + } + + Entry(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + void IncRef(long o) throws Z3Exception + { + Context().FuncEntry_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().FuncEntry_DRQ().Add(o); + super.DecRef(o); + } + }; + + /** + * The number of entries in the function interpretation. + **/ + public int NumEntries() + { + return Native.funcInterpGetNumEntries(Context().nCtx(), NativeObject()); + } + + /** + * The entries in the function interpretation + * + * @throws Z3Exception + **/ + public Entry[] Entries() throws Z3Exception + { + int n = NumEntries(); + Entry[] res = new Entry[n]; + for (int i = 0; i < n; i++) + res[i] = new Entry(Context(), Native.funcInterpGetEntry(Context() + .nCtx(), NativeObject(), i)); + return res; + } + + /** + * The (symbolic) `else' value of the function interpretation. + * + * @throws Z3Exception + **/ + public Expr Else() throws Z3Exception + { + return Expr.Create(Context(), + Native.funcInterpGetElse(Context().nCtx(), NativeObject())); + } + + /** + * The arity of the function interpretation + **/ + public int Arity() + { + return Native.funcInterpGetArity(Context().nCtx(), NativeObject()); + } + + /** + * A string representation of the function interpretation. + **/ + public String toString() + { + try + { + String res = ""; + res += "["; + for (Entry e : Entries()) + { + int n = e.NumArgs(); + if (n > 1) + res += "["; + Expr[] args = e.Args(); + for (int i = 0; i < n; i++) + { + if (i != 0) + res += ", "; + res += args[i]; + } + if (n > 1) + res += "]"; + res += " -> " + e.Value() + ", "; + } + res += "else -> " + Else(); + res += "]"; + return res; + } catch (Z3Exception e) + { + return new String("Z3Exception: " + e.getMessage()); + } + } + + FuncInterp(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + void IncRef(long o) throws Z3Exception + { + Context().FuncInterp_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().FuncInterp_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/FuncInterpDecRefQueue.java b/src/api/java/FuncInterpDecRefQueue.java new file mode 100644 index 000000000..968a642c8 --- /dev/null +++ b/src/api/java/FuncInterpDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class FuncInterpDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.funcInterpIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.funcInterpDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/FuncInterpEntryDecRefQueue.java b/src/api/java/FuncInterpEntryDecRefQueue.java new file mode 100644 index 000000000..8d76f597c --- /dev/null +++ b/src/api/java/FuncInterpEntryDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class FuncInterpEntryDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.funcEntryIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.funcEntryDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/Goal.java b/src/api/java/Goal.java new file mode 100644 index 000000000..f5d853fd5 --- /dev/null +++ b/src/api/java/Goal.java @@ -0,0 +1,211 @@ +/** + * This file was automatically generated from Goal.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * A goal (aka problem). A goal is essentially a set of formulas, that can be + * solved and/or transformed using tactics and solvers. + **/ +public class Goal extends Z3Object +{ + /** + * The precision of the goal. Goals can be transformed using over + * and under approximations. An under approximation is applied when the + * objective is to find a model for a given goal. An over approximation is + * applied when the objective is to find a proof for a given goal. + * + **/ + public Z3_goal_prec Precision() + { + return Z3_goal_prec.fromInt(Native.goalPrecision(Context().nCtx(), + NativeObject())); + } + + /** + * Indicates whether the goal is precise. + **/ + public boolean IsPrecise() + { + return Precision() == Z3_goal_prec.Z3_GOAL_PRECISE; + } + + /** + * Indicates whether the goal is an under-approximation. + **/ + public boolean IsUnderApproximation() + { + return Precision() == Z3_goal_prec.Z3_GOAL_UNDER; + } + + /** + * Indicates whether the goal is an over-approximation. + **/ + public boolean IsOverApproximation() + { + return Precision() == Z3_goal_prec.Z3_GOAL_OVER; + } + + /** + * Indicates whether the goal is garbage (i.e., the product of over- and + * under-approximations). + **/ + public boolean IsGarbage() + { + return Precision() == Z3_goal_prec.Z3_GOAL_UNDER_OVER; + } + + /** + * Adds the to the given goal. + * @throws Z3Exception + **/ + public void Assert(BoolExpr[] constraints) throws Z3Exception + { + Context().CheckContextMatch(constraints); + for (BoolExpr c : constraints) + { + // It was an assume, now made an assert just to be sure we do not + // regress + Native.goalAssert(Context().nCtx(), NativeObject(), + c.NativeObject()); + } + } + + /** + * Indicates whether the goal contains `false'. + **/ + public boolean Inconsistent() + { + return Native.goalInconsistent(Context().nCtx(), NativeObject()); + } + + /** + * The depth of the goal. This tracks how many transformations + * were applied to it. + **/ + public int Depth() + { + return Native.goalDepth(Context().nCtx(), NativeObject()); + } + + /** + * Erases all formulas from the given goal. + **/ + public void Reset() + { + Native.goalReset(Context().nCtx(), NativeObject()); + } + + /** + * The number of formulas in the goal. + **/ + public int Size() + { + return Native.goalSize(Context().nCtx(), NativeObject()); + } + + /** + * The formulas in the goal. + * @throws Z3Exception + **/ + public BoolExpr[] Formulas() throws Z3Exception + { + int n = Size(); + BoolExpr[] res = new BoolExpr[n]; + for (int i = 0; i < n; i++) + res[i] = new BoolExpr(Context(), Native.goalFormula(Context() + .nCtx(), NativeObject(), i)); + return res; + } + + /** + * The number of formulas, subformulas and terms in the goal. + **/ + public int NumExprs() + { + return Native.goalNumExprs(Context().nCtx(), NativeObject()); + } + + /** + * Indicates whether the goal is empty, and it is precise or the product of + * an under approximation. + **/ + public boolean IsDecidedSat() + { + return Native.goalIsDecidedSat(Context().nCtx(), NativeObject()); + } + + /** + * Indicates whether the goal contains `false', and it is precise or the + * product of an over approximation. + **/ + public boolean IsDecidedUnsat() + { + return Native.goalIsDecidedUnsat(Context().nCtx(), NativeObject()); + } + + /** + * Translates (copies) the Goal to the target Context . + * @throws Z3Exception + **/ + public Goal Translate(Context ctx) throws Z3Exception + { + return new Goal(ctx, Native.goalTranslate(Context().nCtx(), + NativeObject(), ctx.nCtx())); + } + + /** + * Simplifies the goal. Essentially invokes the `simplify' tactic + * on the goal. + **/ + public Goal Simplify(Params p) throws Z3Exception + { + Tactic t = Context().MkTactic("simplify"); + ApplyResult res = t.Apply(this, p); + + if (res.NumSubgoals() == 0) + throw new Z3Exception("No subgoals"); + else + return res.Subgoals()[0]; + } + + /** + * Goal to string conversion. + * + * @return A string representation of the Goal. + **/ + public String toString() + { + return Native.goalToString(Context().nCtx(), NativeObject()); + } + + Goal(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + Goal(Context ctx, boolean models, boolean unsatCores, boolean proofs) throws Z3Exception + { + super(ctx, Native.mkGoal(ctx.nCtx(), (models) ? true : false, + (unsatCores) ? true : false, (proofs) ? true : false)); + } + + void IncRef(long o) throws Z3Exception + { + Context().Goal_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().Goal_DRQ().Add(o); + super.DecRef(o); + } + +} diff --git a/src/api/java/GoalDecRefQueue.java b/src/api/java/GoalDecRefQueue.java new file mode 100644 index 000000000..ac49d2484 --- /dev/null +++ b/src/api/java/GoalDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class GoalDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.goalIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.goalDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/IDecRefQueue.java b/src/api/java/IDecRefQueue.java new file mode 100644 index 000000000..1d1ef2c04 --- /dev/null +++ b/src/api/java/IDecRefQueue.java @@ -0,0 +1,48 @@ +/** + * This file was automatically generated from IDecRefQueue.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import java.util.*; + +abstract class IDecRefQueue +{ + protected Object m_lock = new Object(); + protected LinkedList m_queue = new LinkedList(); + final int m_move_limit = 1024; + + public abstract void IncRef(Context ctx, long obj); + + public abstract void DecRef(Context ctx, long obj); + + public void IncAndClear(Context ctx, long o) + { + IncRef(ctx, o); + if (m_queue.size() >= m_move_limit) + Clear(ctx); + } + + public void Add(long o) + { + if (o == 0) + return; + + synchronized (m_lock) + { + m_queue.add(o); + } + } + + public void Clear(Context ctx) + { + synchronized (m_lock) + { + for (Long o : m_queue) + DecRef(ctx, o); + m_queue.clear(); + } + } +} diff --git a/src/api/java/com/Microsoft/Z3/IDisposable.java b/src/api/java/IDisposable.java similarity index 84% rename from src/api/java/com/Microsoft/Z3/IDisposable.java rename to src/api/java/IDisposable.java index 03885d1e7..ffae8ee33 100644 --- a/src/api/java/com/Microsoft/Z3/IDisposable.java +++ b/src/api/java/IDisposable.java @@ -21,5 +21,7 @@ package com.Microsoft.Z3; public class IDisposable { - public void Dispose() {} + public void Dispose() throws Z3Exception + { + } } diff --git a/src/api/java/IntExpr.java b/src/api/java/IntExpr.java new file mode 100644 index 000000000..4b9df2b99 --- /dev/null +++ b/src/api/java/IntExpr.java @@ -0,0 +1,26 @@ +/** + * This file was automatically generated from IntExpr.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Int expressions + **/ +public class IntExpr extends ArithExpr +{ + /** + * Constructor for IntExpr + **/ + protected IntExpr(Context ctx) throws Z3Exception + { + super(ctx); + } + + IntExpr(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/IntNum.java b/src/api/java/IntNum.java new file mode 100644 index 000000000..7db80c7d9 --- /dev/null +++ b/src/api/java/IntNum.java @@ -0,0 +1,59 @@ +/** + * This file was automatically generated from IntNum.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import java.math.BigInteger; + +/** + * Integer Numerals + **/ +public class IntNum extends IntExpr +{ + + IntNum(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + /** + * Retrieve the int value. + **/ + public int Int() throws Z3Exception + { + Native.IntPtr res = new Native.IntPtr(); + if (Native.getNumeralInt(Context().nCtx(), NativeObject(), res) ^ true) + throw new Z3Exception("Numeral is not an int"); + return res.value; + } + + /** + * Retrieve the 64-bit int value. + **/ + public long Int64() throws Z3Exception + { + Native.LongPtr res = new Native.LongPtr(); + if (Native.getNumeralInt64(Context().nCtx(), NativeObject(), res) ^ true) + throw new Z3Exception("Numeral is not an int64"); + return res.value; + } + + /** + * Retrieve the BigInteger value. + **/ + public BigInteger BigInteger() throws Z3Exception + { + return new BigInteger(this.toString()); + } + + /** + * Returns a string representation of the numeral. + **/ + public String toString() + { + return Native.getNumeralString(Context().nCtx(), NativeObject()); + } +} diff --git a/src/api/java/IntSort.java b/src/api/java/IntSort.java new file mode 100644 index 000000000..c07696216 --- /dev/null +++ b/src/api/java/IntSort.java @@ -0,0 +1,23 @@ +/** + * This file was automatically generated from IntSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * An Integer sort + **/ +public class IntSort extends ArithSort +{ + IntSort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + IntSort(Context ctx) throws Z3Exception + { + super(ctx, Native.mkIntSort(ctx.nCtx())); + } +} diff --git a/src/api/java/IntSymbol.java b/src/api/java/IntSymbol.java new file mode 100644 index 000000000..ca5653b4b --- /dev/null +++ b/src/api/java/IntSymbol.java @@ -0,0 +1,44 @@ +/** + * This file was automatically generated from IntSymbol.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * Numbered symbols + **/ +public class IntSymbol extends Symbol +{ + /** + * The int value of the symbol. Throws an exception if the symbol + * is not of int kind. + **/ + public int Int() throws Z3Exception + { + if (!IsIntSymbol()) + throw new Z3Exception("Int requested from non-Int symbol"); + return Native.getSymbolInt(Context().nCtx(), NativeObject()); + } + + IntSymbol(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + IntSymbol(Context ctx, int i) throws Z3Exception + { + super(ctx, Native.mkIntSymbol(ctx.nCtx(), i)); + } + + void CheckNativeObject(long obj) throws Z3Exception + { + if (Native.getSymbolKind(Context().nCtx(), obj) != Z3_symbol_kind.Z3_INT_SYMBOL + .toInt()) + throw new Z3Exception("Symbol is not of integer kind"); + super.CheckNativeObject(obj); + } +} diff --git a/src/api/java/ListSort.java b/src/api/java/ListSort.java new file mode 100644 index 000000000..e00d185ac --- /dev/null +++ b/src/api/java/ListSort.java @@ -0,0 +1,101 @@ +/** + * This file was automatically generated from ListSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * List sorts. + **/ +public class ListSort extends Sort +{ + /** + * The declaration of the nil function of this list sort. + **/ + public FuncDecl NilDecl() + { + + return nilDecl; + } + + /** + * The empty list. + **/ + public Expr Nil() + { + + return nilConst; + } + + /** + * The declaration of the isNil function of this list sort. + **/ + public FuncDecl IsNilDecl() + { + + return isNilDecl; + } + + /** + * The declaration of the cons function of this list sort. + **/ + public FuncDecl ConsDecl() + { + + return consDecl; + } + + /** + * The declaration of the isCons function of this list sort. + * + **/ + public FuncDecl IsConsDecl() + { + + return isConsDecl; + } + + /** + * The declaration of the head function of this list sort. + **/ + public FuncDecl HeadDecl() + { + + return headDecl; + } + + /** + * The declaration of the tail function of this list sort. + **/ + public FuncDecl TailDecl() + { + + return tailDecl; + } + + private FuncDecl nilDecl, isNilDecl, consDecl, isConsDecl, headDecl, + tailDecl; + private Expr nilConst; + + ListSort(Context ctx, Symbol name, Sort elemSort) throws Z3Exception + { + super(ctx); + + Native.LongPtr inil = new Native.LongPtr(), iisnil = new Native.LongPtr(); + Native.LongPtr icons = new Native.LongPtr(), iiscons = new Native.LongPtr(); + Native.LongPtr ihead = new Native.LongPtr(), itail = new Native.LongPtr(); + + setNativeObject(Native.mkListSort(ctx.nCtx(), name.NativeObject(), + elemSort.NativeObject(), inil, iisnil, icons, iiscons, ihead, + itail)); + nilDecl = new FuncDecl(ctx, inil.value); + isNilDecl = new FuncDecl(ctx, iisnil.value); + consDecl = new FuncDecl(ctx, icons.value); + isConsDecl = new FuncDecl(ctx, iiscons.value); + headDecl = new FuncDecl(ctx, ihead.value); + tailDecl = new FuncDecl(ctx, itail.value); + nilConst = ctx.MkConst(nilDecl); + } +}; diff --git a/src/api/java/Log.java b/src/api/java/Log.java new file mode 100644 index 000000000..388bc836f --- /dev/null +++ b/src/api/java/Log.java @@ -0,0 +1,60 @@ +/** + * This file was automatically generated from Log.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Interaction logging for Z3. Note that this is a global, static log + * and if multiple Context objects are created, it logs the interaction with all + * of them. + **/ +public final class Log +{ + private boolean m_is_open = false; + + /** + * Open an interaction log file. the name of the file + * to open + * + * @return True if opening the log file succeeds, false otherwise. + **/ + public boolean Open(String filename) + { + m_is_open = true; + return Native.openLog(filename) == 1; + } + + /** + * Closes the interaction log. + **/ + public void Close() + { + m_is_open = false; + Native.closeLog(); + } + + /** + * Appends the user-provided string to the interaction + * log. + * @throws Z3Exception + **/ + public void Append(String s) throws Z3Exception + { + if (!m_is_open) + throw new Z3Exception("Log cannot be closed."); + Native.appendLog(s); + } + + /** + * Checks whether the interaction log is opened. + * + * @return True if the interaction log is open, false otherwise. + **/ + public boolean isOpen() + { + return m_is_open; + } +} diff --git a/src/api/java/Model.java b/src/api/java/Model.java new file mode 100644 index 000000000..e15af9d0f --- /dev/null +++ b/src/api/java/Model.java @@ -0,0 +1,291 @@ +/** + * This file was automatically generated from Model.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * A Model contains interpretations (assignments) of constants and functions. + **/ +public class Model extends Z3Object +{ + /** + * Retrieves the interpretation (the assignment) of in + * the model. A Constant + * + * @return An expression if the constant has an interpretation in the model, + * null otherwise. + * @throws Z3Exception + **/ + public Expr ConstInterp(Expr a) throws Z3Exception + { + Context().CheckContextMatch(a); + return ConstInterp(a.FuncDecl()); + } + + /** + * Retrieves the interpretation (the assignment) of in + * the model. A function declaration of zero arity + * + * @return An expression if the function has an interpretation in the model, + * null otherwise. + * @throws Z3Exception + **/ + public Expr ConstInterp(FuncDecl f) throws Z3Exception + { + Context().CheckContextMatch(f); + if (f.Arity() != 0 + || Native.getSortKind(Context().nCtx(), + Native.getRange(Context().nCtx(), f.NativeObject())) == Z3_sort_kind.Z3_ARRAY_SORT + .toInt()) + throw new Z3Exception( + "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp."); + + long n = Native.modelGetConstInterp(Context().nCtx(), NativeObject(), + f.NativeObject()); + if (n == 0) + return null; + else + return Expr.Create(Context(), n); + } + + /** + * Retrieves the interpretation (the assignment) of a non-constant in the model. A function declaration of + * non-zero arity + * + * @return A FunctionInterpretation if the function has an interpretation in + * the model, null otherwise. + * @throws Z3Exception + **/ + public FuncInterp FuncInterp(FuncDecl f) throws Z3Exception + { + Context().CheckContextMatch(f); + + Z3_sort_kind sk = Z3_sort_kind.fromInt(Native.getSortKind(Context() + .nCtx(), Native.getRange(Context().nCtx(), f.NativeObject()))); + + if (f.Arity() == 0) + { + long n = Native.modelGetConstInterp(Context().nCtx(), + NativeObject(), f.NativeObject()); + + if (sk == Z3_sort_kind.Z3_ARRAY_SORT) + { + if (n == 0) + return null; + else + { + if (Native.isAsArray(Context().nCtx(), n) ^ true) + throw new Z3Exception( + "Argument was not an array constant"); + long fd = Native.getAsArrayFuncDecl(Context().nCtx(), n); + return FuncInterp(new FuncDecl(Context(), fd)); + } + } else + { + throw new Z3Exception( + "Constant functions do not have a function interpretation; use ConstInterp"); + } + } else + { + long n = Native.modelGetFuncInterp(Context().nCtx(), + NativeObject(), f.NativeObject()); + if (n == 0) + return null; + else + return new FuncInterp(Context(), n); + } + } + + /** + * The number of constants that have an interpretation in the model. + **/ + public int NumConsts() + { + return Native.modelGetNumConsts(Context().nCtx(), NativeObject()); + } + + /** + * The function declarations of the constants in the model. + * @throws Z3Exception + **/ + public FuncDecl[] ConstDecls() throws Z3Exception + { + int n = NumConsts(); + FuncDecl[] res = new FuncDecl[n]; + for (int i = 0; i < n; i++) + res[i] = new FuncDecl(Context(), Native.modelGetConstDecl(Context() + .nCtx(), NativeObject(), i)); + return res; + } + + /** + * The number of function interpretations in the model. + **/ + public int NumFuncs() + { + return Native.modelGetNumFuncs(Context().nCtx(), NativeObject()); + } + + /** + * The function declarations of the function interpretations in the model. + * @throws Z3Exception + **/ + public FuncDecl[] FuncDecls() throws Z3Exception + { + int n = NumFuncs(); + FuncDecl[] res = new FuncDecl[n]; + for (int i = 0; i < n; i++) + res[i] = new FuncDecl(Context(), Native.modelGetFuncDecl(Context() + .nCtx(), NativeObject(), i)); + return res; + } + + /** + * All symbols that have an interpretation in the model. + * @throws Z3Exception + **/ + public FuncDecl[] Decls() throws Z3Exception + { + int nFuncs = NumFuncs(); + int nConsts = NumConsts(); + int n = nFuncs + nConsts; + FuncDecl[] res = new FuncDecl[n]; + for (int i = 0; i < nConsts; i++) + res[i] = new FuncDecl(Context(), Native.modelGetConstDecl(Context() + .nCtx(), NativeObject(), i)); + for (int i = 0; i < nFuncs; i++) + res[nConsts + i] = new FuncDecl(Context(), Native.modelGetFuncDecl( + Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * A ModelEvaluationFailedException is thrown when an expression cannot be + * evaluated by the model. + **/ + @SuppressWarnings("serial") + public class ModelEvaluationFailedException extends Z3Exception + { + /** + * An exception that is thrown when model evaluation fails. + **/ + public ModelEvaluationFailedException() + { + super(); + } + } + + /** + * Evaluates the expression in the current model. + * This function may fail if contains + * quantifiers, is partial (MODEL_PARTIAL enabled), or if is not well-sorted. In this case a + * ModelEvaluationFailedException is thrown. An expression When this flag + * is enabled, a model value will be assigned to any constant or function + * that does not have an interpretation in the model. + * + * @return The evaluation of in the model. + * @throws Z3Exception + **/ + public Expr Eval(Expr t, boolean completion) throws Z3Exception + { + Native.LongPtr v = new Native.LongPtr(); + if (Native.modelEval(Context().nCtx(), NativeObject(), + t.NativeObject(), (completion) ? true : false, v) ^ true) + throw new ModelEvaluationFailedException(); + else + return Expr.Create(Context(), v.value); + } + + /** + * Alias for Eval. + * @throws Z3Exception + **/ + public Expr Evaluate(Expr t, boolean completion) throws Z3Exception + { + return Eval(t, completion); + } + + /** + * The number of uninterpreted sorts that the model has an interpretation + * for. + **/ + public int NumSorts() + { + return Native.modelGetNumSorts(Context().nCtx(), NativeObject()); + } + + /** + * The uninterpreted sorts that the model has an interpretation for. + * Z3 also provides an intepretation for uninterpreted sorts used + * in a formula. The interpretation for a sort is a finite set of distinct + * values. We say this finite set is the "universe" of the sort. + * + * @throws Z3Exception + **/ + public Sort[] Sorts() throws Z3Exception + { + + int n = NumSorts(); + Sort[] res = new Sort[n]; + for (int i = 0; i < n; i++) + res[i] = Sort.Create(Context(), + Native.modelGetSort(Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * The finite set of distinct values that represent the interpretation for + * sort . An + * uninterpreted sort + * + * @return An array of expressions, where each is an element of the universe + * of + * @throws Z3Exception + **/ + public Expr[] SortUniverse(Sort s) throws Z3Exception + { + + ASTVector nUniv = new ASTVector(Context(), Native.modelGetSortUniverse( + Context().nCtx(), NativeObject(), s.NativeObject())); + int n = nUniv.Size(); + Expr[] res = new Expr[n]; + for (int i = 0; i < n; i++) + res[i] = Expr.Create(Context(), nUniv.get(i).NativeObject()); + return res; + } + + /** + * Conversion of models to strings. + * + * @return A string representation of the model. + **/ + public String toString() + { + return Native.modelToString(Context().nCtx(), NativeObject()); + } + + Model(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + void IncRef(long o) throws Z3Exception + { + Context().Model_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().Model_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/ModelDecRefQueue.java b/src/api/java/ModelDecRefQueue.java new file mode 100644 index 000000000..52c035914 --- /dev/null +++ b/src/api/java/ModelDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class ModelDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.modelIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.modelDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/com/Microsoft/Z3/Native.c b/src/api/java/Native.cpp similarity index 100% rename from src/api/java/com/Microsoft/Z3/Native.c rename to src/api/java/Native.cpp diff --git a/src/api/java/com/Microsoft/Z3/Native.java b/src/api/java/Native.java similarity index 97% rename from src/api/java/com/Microsoft/Z3/Native.java rename to src/api/java/Native.java index 31ca6f4bc..fa326f5cf 100644 --- a/src/api/java/com/Microsoft/Z3/Native.java +++ b/src/api/java/Native.java @@ -4,7 +4,8 @@ public final class Native { public static class IntPtr { public int value; } public static class LongPtr { public long value; } public static class StringPtr { public String value; } - static { System.loadLibrary(""); } + public static class errorHandler { public long ptr; } + static { System.loadLibrary(""); } public static native long mkConfig(); public static native void delConfig(long a0); public static native void setParamValue(long a0, String a1, String a2); @@ -14,7 +15,7 @@ public final class Native { public static native void incRef(long a0, long a1); public static native void decRef(long a0, long a1); public static native void updateParamValue(long a0, String a1, String a2); - public static native boolean getParamValue(long a0, String a1, String a2); + public static native boolean getParamValue(long a0, String a1, StringPtr a2); public static native void interrupt(long a0); public static native long mkParams(long a0); public static native void paramsIncRef(long a0, long a1); @@ -40,16 +41,16 @@ public final class Native { public static native long mkBvSort(long a0, int a1); public static native long mkFiniteDomainSort(long a0, long a1, long a2); public static native long mkArraySort(long a0, long a1, long a2); - public static native long mkTupleSort(long a0, long a1, int a2, long[] a3, long[] a4, Long a5, long[] a6); + public static native long mkTupleSort(long a0, long a1, int a2, long[] a3, long[] a4, LongPtr a5, long[] a6); public static native long mkEnumerationSort(long a0, long a1, int a2, long[] a3, long[] a4, long[] a5); - public static native long mkListSort(long a0, long a1, long a2, Long a3, Long a4, Long a5, Long a6, Long a7, Long a8); + public static native long mkListSort(long a0, long a1, long a2, LongPtr a3, LongPtr a4, LongPtr a5, LongPtr a6, LongPtr a7, LongPtr a8); public static native long mkConstructor(long a0, long a1, long a2, int a3, long[] a4, long[] a5, int[] a6); public static native void delConstructor(long a0, long a1); public static native long mkDatatype(long a0, long a1, int a2, long[] a3); public static native long mkConstructorList(long a0, int a1, long[] a2); public static native void delConstructorList(long a0, long a1); public static native void mkDatatypes(long a0, int a1, long[] a2, long[] a3, long[] a4); - public static native void queryConstructor(long a0, long a1, int a2, Long a3, Long a4, long[] a5); + public static native void queryConstructor(long a0, long a1, int a2, LongPtr a3, LongPtr a4, long[] a5); public static native long mkFuncDecl(long a0, long a1, int a2, long[] a3, long a4); public static native long mkApp(long a0, long a1, int a2, long[] a3); public static native long mkConst(long a0, long a1, long a2); @@ -170,7 +171,7 @@ public final class Native { public static native boolean isEqSort(long a0, long a1, long a2); public static native int getSortKind(long a0, long a1); public static native int getBvSortSize(long a0, long a1); - public static native boolean getFiniteDomainSortSize(long a0, long a1, Long a2); + public static native boolean getFiniteDomainSortSize(long a0, long a1, LongPtr a2); public static native long getArraySortDomain(long a0, long a1); public static native long getArraySortRange(long a0, long a1); public static native long getTupleSortMkDecl(long a0, long a1); @@ -220,12 +221,12 @@ public final class Native { public static native String getNumeralDecimalString(long a0, long a1, int a2); public static native long getNumerator(long a0, long a1); public static native long getDenominator(long a0, long a1); - public static native boolean getNumeralSmall(long a0, long a1, Long a2, Long a3); - public static native boolean getNumeralInt(long a0, long a1, Integer a2); - public static native boolean getNumeralUint(long a0, long a1, Integer a2); - public static native boolean getNumeralUint64(long a0, long a1, Long a2); - public static native boolean getNumeralInt64(long a0, long a1, Long a2); - public static native boolean getNumeralRationalInt64(long a0, long a1, Long a2, Long a3); + public static native boolean getNumeralSmall(long a0, long a1, LongPtr a2, LongPtr a3); + public static native boolean getNumeralInt(long a0, long a1, IntPtr a2); + public static native boolean getNumeralUint(long a0, long a1, IntPtr a2); + public static native boolean getNumeralUint64(long a0, long a1, LongPtr a2); + public static native boolean getNumeralInt64(long a0, long a1, LongPtr a2); + public static native boolean getNumeralRationalInt64(long a0, long a1, LongPtr a2, LongPtr a3); public static native long getAlgebraicNumberLower(long a0, long a1, int a2); public static native long getAlgebraicNumberUpper(long a0, long a1, int a2); public static native long patternToAst(long a0, long a1); @@ -252,7 +253,7 @@ public final class Native { public static native long translate(long a0, long a1, long a2); public static native void modelIncRef(long a0, long a1); public static native void modelDecRef(long a0, long a1); - public static native boolean modelEval(long a0, long a1, long a2, boolean a3, Long a4); + public static native boolean modelEval(long a0, long a1, long a2, boolean a3, LongPtr a4); public static native long modelGetConstInterp(long a0, long a1, long a2); public static native long modelGetFuncInterp(long a0, long a1, long a2); public static native int modelGetNumConsts(long a0, long a1); @@ -303,7 +304,7 @@ public final class Native { public static native void setError(long a0, int a1); public static native String getErrorMsg(int a0); public static native String getErrorMsgEx(long a0, int a1); - public static native void getVersion(Integer a0, Integer a1, Integer a2, Integer a3); + public static native void getVersion(IntPtr a0, IntPtr a1, IntPtr a2, IntPtr a3); public static native void enableTrace(String a0); public static native void disableTrace(String a0); public static native void resetMemory(); @@ -455,9 +456,9 @@ public final class Native { public static native int getNumScopes(long a0); public static native void persistAst(long a0, long a1, int a2); public static native void assertCnstr(long a0, long a1); - public static native int checkAndGetModel(long a0, Long a1); + public static native int checkAndGetModel(long a0, LongPtr a1); public static native int check(long a0); - public static native int checkAssumptions(long a0, int a1, long[] a2, Long a3, Long a4, Integer a5, long[] a6); + public static native int checkAssumptions(long a0, int a1, long[] a2, LongPtr a3, LongPtr a4, IntPtr a5, long[] a6); public static native int getImpliedEqualities(long a0, int a1, long[] a2, int[] a3); public static native void delModel(long a0, long a1); public static native void softCheckCancel(long a0); @@ -476,16 +477,16 @@ public final class Native { public static native long getModelConstant(long a0, long a1, int a2); public static native int getModelNumFuncs(long a0, long a1); public static native long getModelFuncDecl(long a0, long a1, int a2); - public static native boolean evalFuncDecl(long a0, long a1, long a2, Long a3); - public static native boolean isArrayValue(long a0, long a1, long a2, Integer a3); - public static native void getArrayValue(long a0, long a1, long a2, int a3, long[] a4, long[] a5, Long a6); + public static native boolean evalFuncDecl(long a0, long a1, long a2, LongPtr a3); + public static native boolean isArrayValue(long a0, long a1, long a2, IntPtr a3); + public static native void getArrayValue(long a0, long a1, long a2, int a3, long[] a4, long[] a5, LongPtr a6); public static native long getModelFuncElse(long a0, long a1, int a2); public static native int getModelFuncNumEntries(long a0, long a1, int a2); public static native int getModelFuncEntryNumArgs(long a0, long a1, int a2, int a3); public static native long getModelFuncEntryArg(long a0, long a1, int a2, int a3, int a4); public static native long getModelFuncEntryValue(long a0, long a1, int a2, int a3); - public static native boolean eval(long a0, long a1, long a2, Long a3); - public static native boolean evalDecl(long a0, long a1, long a2, int a3, long[] a4, Long a5); + public static native boolean eval(long a0, long a1, long a2, LongPtr a3); + public static native boolean evalDecl(long a0, long a1, long a2, int a3, long[] a4, LongPtr a5); public static native String contextToString(long a0); public static native String statisticsToString(long a0); public static native long getContextAssignment(long a0); diff --git a/src/api/java/ParamDescrs.java b/src/api/java/ParamDescrs.java new file mode 100644 index 000000000..ba2ed6e94 --- /dev/null +++ b/src/api/java/ParamDescrs.java @@ -0,0 +1,85 @@ +/** + * This file was automatically generated from ParamDescrs.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * A ParamDescrs describes a set of parameters. + **/ +public class ParamDescrs extends Z3Object +{ + /** + * validate a set of parameters. + **/ + public void Validate(Params p) + { + + Native.paramsValidate(Context().nCtx(), p.NativeObject(), + NativeObject()); + } + + /** + * Retrieve kind of parameter. + **/ + public Z3_param_kind GetKind(Symbol name) + { + + return Z3_param_kind.fromInt(Native.paramDescrsGetKind( + Context().nCtx(), NativeObject(), name.NativeObject())); + } + + /** + * Retrieve all names of parameters. + * + * @throws Z3Exception + **/ + public Symbol[] Names() throws Z3Exception + { + int sz = Native.paramDescrsSize(Context().nCtx(), NativeObject()); + Symbol[] names = new Symbol[sz]; + for (int i = 0; i < sz; ++i) + { + names[i] = Symbol.Create(Context(), Native.paramDescrsGetName( + Context().nCtx(), NativeObject(), i)); + } + return names; + } + + /** + * The size of the ParamDescrs. + **/ + public int Size() + { + return Native.paramDescrsSize(Context().nCtx(), NativeObject()); + } + + /** + * Retrieves a string representation of the ParamDescrs. + **/ + public String toString() + { + return Native.paramDescrsToString(Context().nCtx(), NativeObject()); + } + + ParamDescrs(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + void IncRef(long o) throws Z3Exception + { + Context().ParamDescrs_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().ParamDescrs_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/ParamDescrsDecRefQueue.java b/src/api/java/ParamDescrsDecRefQueue.java new file mode 100644 index 000000000..82d76c843 --- /dev/null +++ b/src/api/java/ParamDescrsDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class ParamDescrsDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.paramDescrsIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.paramDescrsDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/Params.java b/src/api/java/Params.java new file mode 100644 index 000000000..b1bfdd516 --- /dev/null +++ b/src/api/java/Params.java @@ -0,0 +1,102 @@ +/** + * This file was automatically generated from Params.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * A ParameterSet represents a configuration in the form of Symbol/value pairs. + **/ +public class Params extends Z3Object +{ + /** + * Adds a parameter setting. + **/ + public void Add(Symbol name, boolean value) throws Z3Exception + { + Native.paramsSetBool(Context().nCtx(), NativeObject(), + name.NativeObject(), (value) ? true : false); + } + + /** + * Adds a parameter setting. + **/ + public void Add(Symbol name, double value) throws Z3Exception + { + Native.paramsSetDouble(Context().nCtx(), NativeObject(), + name.NativeObject(), value); + } + + /** + * Adds a parameter setting. + **/ + public void Add(Symbol name, Symbol value) throws Z3Exception + { + + Native.paramsSetSymbol(Context().nCtx(), NativeObject(), + name.NativeObject(), value.NativeObject()); + } + + /** + * Adds a parameter setting. + **/ + public void Add(String name, boolean value) throws Z3Exception + { + Native.paramsSetBool(Context().nCtx(), NativeObject(), Context() + .MkSymbol(name).NativeObject(), (value) ? true : false); + } + + /** + * Adds a parameter setting. + **/ + public void Add(String name, int value) throws Z3Exception + { + Native.paramsSetUint(Context().nCtx(), NativeObject(), Context() + .MkSymbol(name).NativeObject(), value); + } + + /** + * Adds a parameter setting. + **/ + public void Add(String name, double value) throws Z3Exception + { + Native.paramsSetDouble(Context().nCtx(), NativeObject(), Context() + .MkSymbol(name).NativeObject(), value); + } + + /** + * Adds a parameter setting. + **/ + public void Add(String name, Symbol value) throws Z3Exception + { + Native.paramsSetSymbol(Context().nCtx(), NativeObject(), Context() + .MkSymbol(name).NativeObject(), value.NativeObject()); + } + + /** + * A string representation of the parameter set. + **/ + public String toString() + { + return Native.paramsToString(Context().nCtx(), NativeObject()); + } + + Params(Context ctx) throws Z3Exception + { + super(ctx, Native.mkParams(ctx.nCtx())); + } + + void IncRef(long o) throws Z3Exception + { + Context().Params_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().Params_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/ParamsDecRefQueue.java b/src/api/java/ParamsDecRefQueue.java new file mode 100644 index 000000000..88e40fb23 --- /dev/null +++ b/src/api/java/ParamsDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class ParamsDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.paramsIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.paramsDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/Pattern.java b/src/api/java/Pattern.java new file mode 100644 index 000000000..017aead97 --- /dev/null +++ b/src/api/java/Pattern.java @@ -0,0 +1,51 @@ +/** + * This file was automatically generated from Pattern.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Patterns comprise a list of terms. The list should be non-empty. If the list + * comprises of more than one term, it is also called a multi-pattern. + **/ +public class Pattern extends AST +{ + /** + * The number of terms in the pattern. + **/ + public int NumTerms() + { + return Native.getPatternNumTerms(Context().nCtx(), NativeObject()); + } + + /** + * The terms in the pattern. + * + * @throws Z3Exception + **/ + public Expr[] Terms() throws Z3Exception + { + + int n = NumTerms(); + Expr[] res = new Expr[n]; + for (int i = 0; i < n; i++) + res[i] = Expr.Create(Context(), + Native.getPattern(Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * A string representation of the pattern. + **/ + public String toString() + { + return Native.patternToString(Context().nCtx(), NativeObject()); + } + + Pattern(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/Probe.java b/src/api/java/Probe.java new file mode 100644 index 000000000..a0fcfd3db --- /dev/null +++ b/src/api/java/Probe.java @@ -0,0 +1,63 @@ +/** + * This file was automatically generated from Probe.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Probes are used to inspect a goal (aka problem) and collect information that + * may be used to decide which solver and/or preprocessing step will be used. + * The complete list of probes may be obtained using the procedures + * Context.NumProbes and Context.ProbeNames. It may + * also be obtained using the command (help-tactics) in the SMT 2.0 + * front-end. + **/ +public class Probe extends Z3Object +{ + /** + * Execute the probe over the goal. + * + * @return A probe always produce a double value. "Boolean" probes return + * 0.0 for false, and a value different from 0.0 for true. + * @throws Z3Exception + **/ + public double Apply(Goal g) throws Z3Exception + { + Context().CheckContextMatch(g); + return Native.probeApply(Context().nCtx(), NativeObject(), + g.NativeObject()); + } + + /** + * Apply the probe to a goal. + * @throws Z3Exception + **/ + public double get(Goal g) throws Z3Exception + { + return Apply(g); + } + + Probe(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + Probe(Context ctx, String name) throws Z3Exception + { + super(ctx, Native.mkProbe(ctx.nCtx(), name)); + } + + void IncRef(long o) throws Z3Exception + { + Context().Probe_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().Probe_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/ProbeDecRefQueue.java b/src/api/java/ProbeDecRefQueue.java new file mode 100644 index 000000000..2c3cd9783 --- /dev/null +++ b/src/api/java/ProbeDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class ProbeDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.probeIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.probeDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/Quantifier.java b/src/api/java/Quantifier.java new file mode 100644 index 000000000..2b7eba0d9 --- /dev/null +++ b/src/api/java/Quantifier.java @@ -0,0 +1,213 @@ +/** + * This file was automatically generated from Quantifier.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * Quantifier expressions. + **/ +public class Quantifier extends BoolExpr +{ + /** + * Indicates whether the quantifier is universal. + **/ + public boolean IsUniversal() + { + return Native.isQuantifierForall(Context().nCtx(), NativeObject()); + } + + /** + * Indicates whether the quantifier is existential. + **/ + public boolean IsExistential() + { + return !IsUniversal(); + } + + /** + * The weight of the quantifier. + **/ + public int Weight() + { + return Native.getQuantifierWeight(Context().nCtx(), NativeObject()); + } + + /** + * The number of patterns. + **/ + public int NumPatterns() + { + return Native + .getQuantifierNumPatterns(Context().nCtx(), NativeObject()); + } + + /** + * The patterns. + * + * @throws Z3Exception + **/ + public Pattern[] Patterns() throws Z3Exception + { + int n = NumPatterns(); + Pattern[] res = new Pattern[n]; + for (int i = 0; i < n; i++) + res[i] = new Pattern(Context(), Native.getQuantifierPatternAst( + Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * The number of no-patterns. + **/ + public int NumNoPatterns() + { + return Native.getQuantifierNumNoPatterns(Context().nCtx(), + NativeObject()); + } + + /** + * The no-patterns. + * + * @throws Z3Exception + **/ + public Pattern[] NoPatterns() throws Z3Exception + { + int n = NumNoPatterns(); + Pattern[] res = new Pattern[n]; + for (int i = 0; i < n; i++) + res[i] = new Pattern(Context(), Native.getQuantifierNoPatternAst( + Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * The number of bound variables. + **/ + public int NumBound() + { + return Native.getQuantifierNumBound(Context().nCtx(), NativeObject()); + } + + /** + * The symbols for the bound variables. + * + * @throws Z3Exception + **/ + public Symbol[] BoundVariableNames() throws Z3Exception + { + int n = NumBound(); + Symbol[] res = new Symbol[n]; + for (int i = 0; i < n; i++) + res[i] = Symbol.Create(Context(), Native.getQuantifierBoundName( + Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * The sorts of the bound variables. + * + * @throws Z3Exception + **/ + public Sort[] BoundVariableSorts() throws Z3Exception + { + int n = NumBound(); + Sort[] res = new Sort[n]; + for (int i = 0; i < n; i++) + res[i] = Sort.Create(Context(), Native.getQuantifierBoundSort( + Context().nCtx(), NativeObject(), i)); + return res; + } + + /** + * The body of the quantifier. + * + * @throws Z3Exception + **/ + public BoolExpr Body() throws Z3Exception + { + return new BoolExpr(Context(), Native.getQuantifierBody(Context() + .nCtx(), NativeObject())); + } + + Quantifier(Context ctx, boolean isForall, Sort[] sorts, Symbol[] names, + Expr body, int weight, Pattern[] patterns, Expr[] noPatterns, + Symbol quantifierID, Symbol skolemID) throws Z3Exception + { + super(ctx); + + Context().CheckContextMatch(patterns); + Context().CheckContextMatch(noPatterns); + Context().CheckContextMatch(sorts); + Context().CheckContextMatch(names); + Context().CheckContextMatch(body); + + if (sorts.length != names.length) + throw new Z3Exception( + "Number of sorts does not match number of names"); + + if (noPatterns == null && quantifierID == null && skolemID == null) + { + setNativeObject(Native.mkQuantifier(ctx.nCtx(), (isForall) ? true + : false, weight, AST.ArrayLength(patterns), AST + .ArrayToNative(patterns), AST.ArrayLength(sorts), AST + .ArrayToNative(sorts), Symbol.ArrayToNative(names), body + .NativeObject())); + } else + { + setNativeObject(Native.mkQuantifierEx(ctx.nCtx(), (isForall) ? true + : false, weight, AST.GetNativeObject(quantifierID), AST + .GetNativeObject(skolemID), AST.ArrayLength(patterns), AST + .ArrayToNative(patterns), AST.ArrayLength(noPatterns), AST + .ArrayToNative(noPatterns), AST.ArrayLength(sorts), AST + .ArrayToNative(sorts), Symbol.ArrayToNative(names), body + .NativeObject())); + } + } + + Quantifier(Context ctx, boolean isForall, Expr[] bound, Expr body, + int weight, Pattern[] patterns, Expr[] noPatterns, + Symbol quantifierID, Symbol skolemID) throws Z3Exception + { + super(ctx); + + Context().CheckContextMatch(noPatterns); + Context().CheckContextMatch(patterns); + // Context().CheckContextMatch(bound); + Context().CheckContextMatch(body); + + if (noPatterns == null && quantifierID == null && skolemID == null) + { + setNativeObject(Native.mkQuantifierConst(ctx.nCtx(), + (isForall) ? true : false, weight, AST.ArrayLength(bound), + AST.ArrayToNative(bound), AST.ArrayLength(patterns), + AST.ArrayToNative(patterns), body.NativeObject())); + } else + { + setNativeObject(Native.mkQuantifierConstEx(ctx.nCtx(), + (isForall) ? true : false, weight, + AST.GetNativeObject(quantifierID), + AST.GetNativeObject(skolemID), AST.ArrayLength(bound), + AST.ArrayToNative(bound), AST.ArrayLength(patterns), + AST.ArrayToNative(patterns), AST.ArrayLength(noPatterns), + AST.ArrayToNative(noPatterns), body.NativeObject())); + } + } + + Quantifier(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + void CheckNativeObject(long obj) throws Z3Exception + { + if (Native.getAstKind(Context().nCtx(), obj) != Z3_ast_kind.Z3_QUANTIFIER_AST + .toInt()) + throw new Z3Exception("Underlying object is not a quantifier"); + super.CheckNativeObject(obj); + } +} diff --git a/src/api/java/RatNum.java b/src/api/java/RatNum.java new file mode 100644 index 000000000..7a762b361 --- /dev/null +++ b/src/api/java/RatNum.java @@ -0,0 +1,73 @@ +/** + * This file was automatically generated from RatNum.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import java.math.BigInteger; +/** + * Rational Numerals + **/ +public class RatNum extends RealExpr +{ + /** + * The numerator of a rational numeral. + **/ + public IntNum Numerator() throws Z3Exception + { + return new IntNum(Context(), Native.getNumerator(Context().nCtx(), + NativeObject())); + } + + /** + * The denominator of a rational numeral. + **/ + public IntNum Denominator() throws Z3Exception + { + return new IntNum(Context(), Native.getDenominator(Context().nCtx(), + NativeObject())); + } + + /** + * Converts the numerator of the rational to a BigInteger + **/ + public BigInteger BigIntNumerator() throws Z3Exception + { + IntNum n = Numerator(); + return new BigInteger(n.toString()); + } + + /** + * Converts the denominator of the rational to a BigInteger + **/ + public BigInteger BigIntDenominator() throws Z3Exception + { + IntNum n = Denominator(); + return new BigInteger(n.toString()); + } + + /** + * Returns a string representation in decimal notation. The result + * has at most decimal places. + **/ + public String ToDecimalString(int precision) throws Z3Exception + { + return Native.getNumeralDecimalString(Context().nCtx(), NativeObject(), + precision); + } + + /** + * Returns a string representation of the numeral. + **/ + public String toString() + { + return Native.getNumeralString(Context().nCtx(), NativeObject()); + } + + RatNum(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/RealExpr.java b/src/api/java/RealExpr.java new file mode 100644 index 000000000..9f2590fe1 --- /dev/null +++ b/src/api/java/RealExpr.java @@ -0,0 +1,26 @@ +/** + * This file was automatically generated from RealExpr.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Real expressions + **/ +public class RealExpr extends ArithExpr +{ + /** + * Constructor for RealExpr + **/ + protected RealExpr(Context ctx) + { + super(ctx); + } + + RealExpr(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/RealSort.java b/src/api/java/RealSort.java new file mode 100644 index 000000000..0b7f600b2 --- /dev/null +++ b/src/api/java/RealSort.java @@ -0,0 +1,23 @@ +/** + * This file was automatically generated from RealSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * A real sort + **/ +public class RealSort extends ArithSort +{ + RealSort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + RealSort(Context ctx) throws Z3Exception + { + super(ctx, Native.mkRealSort(ctx.nCtx())); + } +} diff --git a/src/api/java/RelationSort.java b/src/api/java/RelationSort.java new file mode 100644 index 000000000..1d0371fd1 --- /dev/null +++ b/src/api/java/RelationSort.java @@ -0,0 +1,46 @@ +/** + * This file was automatically generated from RelationSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Relation sorts. + **/ +public class RelationSort extends Sort +{ + /** + * The arity of the relation sort. + **/ + public int Arity() + { + return Native.getRelationArity(Context().nCtx(), NativeObject()); + } + + /** + * The sorts of the columns of the relation sort. + * @throws Z3Exception + **/ + public Sort[] ColumnSorts() throws Z3Exception + { + + if (m_columnSorts != null) + return m_columnSorts; + + int n = Arity(); + Sort[] res = new Sort[n]; + for (int i = 0; i < n; i++) + res[i] = Sort.Create(Context(), Native.getRelationColumn(Context() + .nCtx(), NativeObject(), i)); + return res; + } + + private Sort[] m_columnSorts = null; + + RelationSort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } +} diff --git a/src/api/java/SetSort.java b/src/api/java/SetSort.java new file mode 100644 index 000000000..c211a597d --- /dev/null +++ b/src/api/java/SetSort.java @@ -0,0 +1,23 @@ +/** + * This file was automatically generated from SetSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Set sorts. + **/ +public class SetSort extends Sort +{ + SetSort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + SetSort(Context ctx, Sort ty) throws Z3Exception + { + super(ctx, Native.mkSetSort(ctx.nCtx(), ty.NativeObject())); + } +} diff --git a/src/api/java/Solver.java b/src/api/java/Solver.java new file mode 100644 index 000000000..613479053 --- /dev/null +++ b/src/api/java/Solver.java @@ -0,0 +1,242 @@ +/** + * This file was automatically generated from Solver.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * Solvers. + **/ +public class Solver extends Z3Object +{ + /** + * A string that describes all available solver parameters. + **/ + public String Help() + { + return Native.solverGetHelp(Context().nCtx(), NativeObject()); + } + + /** + * Sets the solver parameters. + * @throws Z3Exception + **/ + public void setParameters(Params value) throws Z3Exception + { + Context().CheckContextMatch(value); + Native.solverSetParams(Context().nCtx(), NativeObject(), + value.NativeObject()); + } + + /** + * Retrieves parameter descriptions for solver. + * @throws Z3Exception + **/ + public ParamDescrs ParameterDescriptions() throws Z3Exception + { + return new ParamDescrs(Context(), Native.solverGetParamDescrs(Context() + .nCtx(), NativeObject())); + } + + /** + * The current number of backtracking points (scopes). + * + **/ + public int NumScopes() + { + return Native.solverGetNumScopes(Context().nCtx(), NativeObject()); + } + + /** + * Creates a backtracking point. + **/ + public void Push() + { + Native.solverPush(Context().nCtx(), NativeObject()); + } + + /** + * Backtracks backtracking points. Note that + * an exception is thrown if is not smaller than + * NumScopes + **/ + public void Pop(int n) + { + Native.solverPop(Context().nCtx(), NativeObject(), n); + } + + /** + * Resets the Solver. This removes all assertions from the + * solver. + **/ + public void Reset() + { + Native.solverReset(Context().nCtx(), NativeObject()); + } + + /** + * Assert a constraint (or multiple) into the solver. + * @throws Z3Exception + **/ + public void Assert(BoolExpr[] constraints) throws Z3Exception + { + Context().CheckContextMatch(constraints); + for (BoolExpr a : constraints) + { + Native.solverAssert(Context().nCtx(), NativeObject(), + a.NativeObject()); + } + } + + /** + * The number of assertions in the solver. + * @throws Z3Exception + **/ + public int NumAssertions() throws Z3Exception + { + ASTVector ass = new ASTVector(Context(), Native.solverGetAssertions( + Context().nCtx(), NativeObject())); + return ass.Size(); + } + + /** + * The set of asserted formulas. + * @throws Z3Exception + **/ + public BoolExpr[] Assertions() throws Z3Exception + { + ASTVector ass = new ASTVector(Context(), Native.solverGetAssertions( + Context().nCtx(), NativeObject())); + int n = ass.Size(); + BoolExpr[] res = new BoolExpr[n]; + for (int i = 0; i < n; i++) + res[i] = new BoolExpr(Context(), ass.get(i).NativeObject()); + return res; + } + + /** + * Checks whether the assertions in the solver are consistent or not. + * + **/ + public Status Check(Expr[] assumptions) + { + Z3_lbool r; + if (assumptions == null) + r = Z3_lbool.fromInt(Native.solverCheck(Context().nCtx(), + NativeObject())); + else + r = Z3_lbool.fromInt(Native.solverCheckAssumptions( + Context().nCtx(), NativeObject(), (int) assumptions.length, + AST.ArrayToNative(assumptions))); + switch (r) + { + case Z3_L_TRUE: + return Status.SATISFIABLE; + case Z3_L_FALSE: + return Status.UNSATISFIABLE; + default: + return Status.UNKNOWN; + } + } + + /** + * The model of the last Check. The result is + * null if Check was not invoked before, if its + * results was not SATISFIABLE, or if model production is not + * enabled. + * @throws Z3Exception + **/ + public Model Model() throws Z3Exception + { + long x = Native.solverGetModel(Context().nCtx(), NativeObject()); + if (x == 0) + return null; + else + return new Model(Context(), x); + } + + /** + * The proof of the last Check. The result is + * null if Check was not invoked before, if its + * results was not UNSATISFIABLE, or if proof production is + * disabled. + * @throws Z3Exception + **/ + public Expr Proof() throws Z3Exception + { + long x = Native.solverGetProof(Context().nCtx(), NativeObject()); + if (x == 0) + return null; + else + return Expr.Create(Context(), x); + } + + /** + * The unsat core of the last Check. The unsat core + * is a subset of Assertions The result is empty if + * Check was not invoked before, if its results was not + * UNSATISFIABLE, or if core production is disabled. + * @throws Z3Exception + **/ + public Expr[] UnsatCore() throws Z3Exception + { + + ASTVector core = new ASTVector(Context(), Native.solverGetUnsatCore( + Context().nCtx(), NativeObject())); + int n = core.Size(); + Expr[] res = new Expr[n]; + for (int i = 0; i < n; i++) + res[i] = Expr.Create(Context(), core.get(i).NativeObject()); + return res; + } + + /** + * A brief justification of why the last call to Check returned + * UNKNOWN. + **/ + public String ReasonUnknown() + { + + return Native.solverGetReasonUnknown(Context().nCtx(), NativeObject()); + } + + /** + * Solver statistics. + * @throws Z3Exception + **/ + public Statistics Statistics() throws Z3Exception + { + return new Statistics(Context(), Native.solverGetStatistics(Context() + .nCtx(), NativeObject())); + } + + /** + * A string representation of the solver. + **/ + public String toString() + { + return Native.solverToString(Context().nCtx(), NativeObject()); + } + + Solver(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + void IncRef(long o) throws Z3Exception + { + Context().Solver_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().Solver_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/SolverDecRefQueue.java b/src/api/java/SolverDecRefQueue.java new file mode 100644 index 000000000..337c41898 --- /dev/null +++ b/src/api/java/SolverDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class SolverDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.solverIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.solverDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/Sort.java b/src/api/java/Sort.java new file mode 100644 index 000000000..5cb76e17a --- /dev/null +++ b/src/api/java/Sort.java @@ -0,0 +1,143 @@ +/** + * This file was automatically generated from Sort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * The Sort class implements type information for ASTs. + **/ +public class Sort extends AST +{ + /** + * Comparison operator. A Sort A + * Sort + * + * @return True if and are from + * the same context and represent the same sort; false otherwise. + **/ + /* Overloaded operators are not translated. */ + + /** + * Comparison operator. A Sort A + * Sort + * + * @return True if and are not + * from the same context or represent different sorts; false + * otherwise. + **/ + /* Overloaded operators are not translated. */ + + /** + * Equality operator for objects of type Sort. + * + * @return + **/ + public boolean Equals(Object o) + { + Sort casted = (Sort) o; + if (casted == null) + return false; + return this == casted; + } + + /** + * Hash code generation for Sorts + * + * @return A hash code + **/ + public int GetHashCode() throws Z3Exception + { + return super.GetHashCode(); + } + + /** + * Returns a unique identifier for the sort. + **/ + public int Id() throws Z3Exception + { + return Native.getSortId(Context().nCtx(), NativeObject()); + } + + /** + * The kind of the sort. + **/ + public Z3_sort_kind SortKind() throws Z3Exception + { + return Z3_sort_kind.fromInt(Native.getSortKind(Context().nCtx(), + NativeObject())); + } + + /** + * The name of the sort + **/ + public Symbol Name() throws Z3Exception + { + return Symbol.Create(Context(), + Native.getSortName(Context().nCtx(), NativeObject())); + } + + /** + * A string representation of the sort. + **/ + public String toString() + { + return Native.sortToString(Context().nCtx(), NativeObject()); + } + + /** + * Sort constructor + **/ + protected Sort(Context ctx) throws Z3Exception + { + super(ctx); + { + } + } + + Sort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + { + } + } + + void CheckNativeObject(long obj) throws Z3Exception + { + if (Native.getAstKind(Context().nCtx(), obj) != Z3_ast_kind.Z3_SORT_AST + .toInt()) + throw new Z3Exception("Underlying object is not a sort"); + super.CheckNativeObject(obj); + } + + static Sort Create(Context ctx, long obj) throws Z3Exception + { + switch (Z3_sort_kind.fromInt(Native.getSortKind(ctx.nCtx(), obj))) + { + case Z3_ARRAY_SORT: + return new ArraySort(ctx, obj); + case Z3_BOOL_SORT: + return new BoolSort(ctx, obj); + case Z3_BV_SORT: + return new BitVecSort(ctx, obj); + case Z3_DATATYPE_SORT: + return new DatatypeSort(ctx, obj); + case Z3_INT_SORT: + return new IntSort(ctx, obj); + case Z3_REAL_SORT: + return new RealSort(ctx, obj); + case Z3_UNINTERPRETED_SORT: + return new UninterpretedSort(ctx, obj); + case Z3_FINITE_DOMAIN_SORT: + return new FiniteDomainSort(ctx, obj); + case Z3_RELATION_SORT: + return new RelationSort(ctx, obj); + default: + throw new Z3Exception("Unknown sort kind"); + } + } +} diff --git a/src/api/java/Statistics.java b/src/api/java/Statistics.java new file mode 100644 index 000000000..81a75fd48 --- /dev/null +++ b/src/api/java/Statistics.java @@ -0,0 +1,190 @@ +/** + * This file was automatically generated from Statistics.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Objects of this class track statistical information about solvers. + **/ +public class Statistics extends Z3Object +{ + /** + * Statistical data is organized into pairs of [Key, Entry], where every + * Entry is either a DoubleEntry or a UIntEntry + **/ + public class Entry + { + /** + * The key of the entry. + **/ + public String Key; + + /** + * The uint-value of the entry. + **/ + public int UIntValue() + { + return m_int; + } + + /** + * The double-value of the entry. + **/ + public double DoubleValue() + { + return m_double; + } + + /** + * True if the entry is uint-valued. + **/ + public boolean IsUInt() + { + return m_is_int; + } + + /** + * True if the entry is double-valued. + **/ + public boolean IsDouble() + { + return m_is_double; + } + + /** + * The string representation of the the entry's value. + * @throws Z3Exception + **/ + public String Value() throws Z3Exception + { + if (IsUInt()) + return Integer.toString(m_int); + else if (IsDouble()) + return Double.toString(m_double); + else + throw new Z3Exception("Unknown statistical entry type"); + } + + /** + * The string representation of the Entry. + **/ + public String toString() + { + try + { + return Key + ": " + Value(); + } catch (Z3Exception e) + { + return new String("Z3Exception: " + e.getMessage()); + } + } + + private boolean m_is_int = false; + private boolean m_is_double = false; + private int m_int = 0; + private double m_double = 0.0; + + Entry(String k, int v) + { + Key = k; + m_is_int = true; + m_int = v; + } + + Entry(String k, double v) + { + Key = k; + m_is_double = true; + m_double = v; + } + } + + /** + * A string representation of the statistical data. + **/ + public String toString() + { + return Native.statsToString(Context().nCtx(), NativeObject()); + } + + /** + * The number of statistical data. + **/ + public int Size() + { + return Native.statsSize(Context().nCtx(), NativeObject()); + } + + /** + * The data entries. + * @throws Z3Exception + **/ + public Entry[] Entries() throws Z3Exception + { + + int n = Size(); + Entry[] res = new Entry[n]; + for (int i = 0; i < n; i++) + { + Entry e; + String k = Native.statsGetKey(Context().nCtx(), NativeObject(), i); + if (Native.statsIsUint(Context().nCtx(), NativeObject(), i)) + e = new Entry(k, Native.statsGetUintValue(Context().nCtx(), + NativeObject(), i)); + else if (Native.statsIsDouble(Context().nCtx(), NativeObject(), i)) + e = new Entry(k, Native.statsGetDoubleValue(Context().nCtx(), + NativeObject(), i)); + else + throw new Z3Exception("Unknown data entry value"); + res[i] = e; + } + return res; + } + + /** + * The statistical counters. + **/ + public String[] Keys() + { + int n = Size(); + String[] res = new String[n]; + for (int i = 0; i < n; i++) + res[i] = Native.statsGetKey(Context().nCtx(), NativeObject(), i); + return res; + } + + /** + * The value of a particular statistical counter. Returns null if + * the key is unknown. + * @throws Z3Exception + **/ + public Entry get(String key) throws Z3Exception + { + int n = Size(); + Entry[] es = Entries(); + for (int i = 0; i < n; i++) + if (es[i].Key == key) + return es[i]; + return null; + } + + Statistics(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + void IncRef(long o) throws Z3Exception + { + Context().Statistics_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().Statistics_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/StatisticsDecRefQueue.java b/src/api/java/StatisticsDecRefQueue.java new file mode 100644 index 000000000..4337d366d --- /dev/null +++ b/src/api/java/StatisticsDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class StatisticsDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.statsIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.statsDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/Status.java b/src/api/java/Status.java new file mode 100644 index 000000000..4f2d44e9d --- /dev/null +++ b/src/api/java/Status.java @@ -0,0 +1,42 @@ +/** + * This file was automatically generated from Status.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Status values. + **/ +public enum Status +{ + // / Used to signify an unsatisfiable status. + UNSATISFIABLE(1), + + // / Used to signify an unknown status. + UNKNOWN(0), + + // / Used to signify a satisfiable status. + SATISFIABLE(1); + + private final int intValue; + + Status(int v) + { + this.intValue = v; + } + + public static final Status fromInt(int v) + { + for (Status k : values()) + if (k.intValue == v) + return k; + return values()[0]; + } + + public final int toInt() + { + return this.intValue; + } +} diff --git a/src/api/java/StringSymbol.java b/src/api/java/StringSymbol.java new file mode 100644 index 000000000..34e38c3c9 --- /dev/null +++ b/src/api/java/StringSymbol.java @@ -0,0 +1,43 @@ +/** + * This file was automatically generated from StringSymbol.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * Named symbols + **/ +public class StringSymbol extends Symbol +{ + /** + * The string value of the symbol. Throws an exception if the + * symbol is not of string kind. + **/ + public String String() throws Z3Exception + { + return Native.getSymbolString(Context().nCtx(), NativeObject()); + } + + StringSymbol(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + StringSymbol(Context ctx, String s) throws Z3Exception + { + super(ctx, Native.mkStringSymbol(ctx.nCtx(), s)); + } + + void CheckNativeObject(long obj) throws Z3Exception + { + if (Native.getSymbolKind(Context().nCtx(), obj) != Z3_symbol_kind.Z3_STRING_SYMBOL + .toInt()) + throw new Z3Exception("Symbol is not of String kind"); + + super.CheckNativeObject(obj); + } +} diff --git a/src/api/java/Symbol.java b/src/api/java/Symbol.java new file mode 100644 index 000000000..1576e17e1 --- /dev/null +++ b/src/api/java/Symbol.java @@ -0,0 +1,81 @@ +/** + * This file was automatically generated from Symbol.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import com.Microsoft.Z3.Enumerations.*; + +/** + * Symbols are used to name several term and type constructors. + **/ +public class Symbol extends Z3Object +{ + /** + * The kind of the symbol (int or string) + **/ + protected Z3_symbol_kind Kind() + { + return Z3_symbol_kind.fromInt(Native.getSymbolKind(Context().nCtx(), + NativeObject())); + } + + /** + * Indicates whether the symbol is of Int kind + **/ + public boolean IsIntSymbol() + { + return Kind() == Z3_symbol_kind.Z3_INT_SYMBOL; + } + + /** + * Indicates whether the symbol is of string kind. + **/ + public boolean IsStringSymbol() + { + return Kind() == Z3_symbol_kind.Z3_STRING_SYMBOL; + } + + /** + * A string representation of the symbol. + **/ + public String toString() + { + try + { + if (IsIntSymbol()) + return Integer.toString(((IntSymbol) this).Int()); + else if (IsStringSymbol()) + return ((StringSymbol) this).String(); + else + return new String( + "Z3Exception: Unknown symbol kind encountered."); + } catch (Z3Exception ex) + { + return new String("Z3Exception: " + ex.getMessage()); + } + } + + /** + * Symbol constructor + **/ + protected Symbol(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + static Symbol Create(Context ctx, long obj) throws Z3Exception + { + switch (Z3_symbol_kind.fromInt(Native.getSymbolKind(ctx.nCtx(), obj))) + { + case Z3_INT_SYMBOL: + return new IntSymbol(ctx, obj); + case Z3_STRING_SYMBOL: + return new StringSymbol(ctx, obj); + default: + throw new Z3Exception("Unknown symbol kind encountered"); + } + } +} diff --git a/src/api/java/Tactic.java b/src/api/java/Tactic.java new file mode 100644 index 000000000..78c19a298 --- /dev/null +++ b/src/api/java/Tactic.java @@ -0,0 +1,98 @@ +/** + * This file was automatically generated from Tactic.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Tactics are the basic building block for creating custom solvers for specific + * problem domains. The complete list of tactics may be obtained using + * Context.NumTactics and Context.TacticNames. It may + * also be obtained using the command (help-tactics) in the SMT 2.0 + * front-end. + **/ +public class Tactic extends Z3Object +{ + /** + * A string containing a description of parameters accepted by the tactic. + **/ + public String Help() + { + return Native.tacticGetHelp(Context().nCtx(), NativeObject()); + } + + /** + * Retrieves parameter descriptions for Tactics. + * @throws Z3Exception + **/ + public ParamDescrs ParameterDescriptions() throws Z3Exception + { + return new ParamDescrs(Context(), Native.tacticGetParamDescrs(Context() + .nCtx(), NativeObject())); + } + + /** + * Execute the tactic over the goal. + * @throws Z3Exception + **/ + public ApplyResult Apply(Goal g, Params p) throws Z3Exception + { + + Context().CheckContextMatch(g); + if (p == null) + return new ApplyResult(Context(), Native.tacticApply(Context() + .nCtx(), NativeObject(), g.NativeObject())); + else + { + Context().CheckContextMatch(p); + return new ApplyResult(Context(), + Native.tacticApplyEx(Context().nCtx(), NativeObject(), + g.NativeObject(), p.NativeObject())); + } + } + + /** + * Apply the tactic to a goal. + * @throws Z3Exception + **/ + public ApplyResult get(Goal g) throws Z3Exception + { + + return Apply(g, null); + } + + /** + * Creates a solver that is implemented using the given tactic. + * @throws Z3Exception + **/ + public Solver Solver() throws Z3Exception + { + + return Context().MkSolver(this); + } + + Tactic(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + Tactic(Context ctx, String name) throws Z3Exception + { + super(ctx, Native.mkTactic(ctx.nCtx(), name)); + } + + void IncRef(long o) throws Z3Exception + { + Context().Tactic_DRQ().IncAndClear(Context(), o); + super.IncRef(o); + } + + void DecRef(long o) throws Z3Exception + { + Context().Tactic_DRQ().Add(o); + super.DecRef(o); + } +} diff --git a/src/api/java/TacticDecRefQueue.java b/src/api/java/TacticDecRefQueue.java new file mode 100644 index 000000000..1b3bd5a03 --- /dev/null +++ b/src/api/java/TacticDecRefQueue.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012 Microsoft Corporation + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +class TacticDecRefQueue extends IDecRefQueue +{ + public void IncRef(Context ctx, long obj) + { + Native.tacticIncRef(ctx.nCtx(), obj); + } + + public void DecRef(Context ctx, long obj) + { + Native.tacticDecRef(ctx.nCtx(), obj); + } +}; diff --git a/src/api/java/TupleSort.java b/src/api/java/TupleSort.java new file mode 100644 index 000000000..d72d0b128 --- /dev/null +++ b/src/api/java/TupleSort.java @@ -0,0 +1,58 @@ +/** + * This file was automatically generated from TupleSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Tuple sorts. + **/ +public class TupleSort extends Sort +{ + /** + * The constructor function of the tuple. + * @throws Z3Exception + **/ + public FuncDecl MkDecl() throws Z3Exception + { + + return new FuncDecl(Context(), Native.getTupleSortMkDecl(Context() + .nCtx(), NativeObject())); + } + + /** + * The number of fields in the tuple. + **/ + public int NumFields() + { + return Native.getTupleSortNumFields(Context().nCtx(), NativeObject()); + } + + /** + * The field declarations. + * @throws Z3Exception + **/ + public FuncDecl[] FieldDecls() throws Z3Exception + { + + int n = NumFields(); + FuncDecl[] res = new FuncDecl[n]; + for (int i = 0; i < n; i++) + res[i] = new FuncDecl(Context(), Native.getTupleSortFieldDecl( + Context().nCtx(), NativeObject(), i)); + return res; + } + + TupleSort(Context ctx, Symbol name, int numFields, Symbol[] fieldNames, + Sort[] fieldSorts) throws Z3Exception + { + super(ctx); + + Native.LongPtr t = new Native.LongPtr(); + setNativeObject(Native.mkTupleSort(ctx.nCtx(), name.NativeObject(), + numFields, Symbol.ArrayToNative(fieldNames), + AST.ArrayToNative(fieldSorts), t, new long[numFields])); + } +}; diff --git a/src/api/java/UninterpretedSort.java b/src/api/java/UninterpretedSort.java new file mode 100644 index 000000000..4967b73f7 --- /dev/null +++ b/src/api/java/UninterpretedSort.java @@ -0,0 +1,23 @@ +/** + * This file was automatically generated from UninterpretedSort.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Uninterpreted Sorts + **/ +public class UninterpretedSort extends Sort +{ + UninterpretedSort(Context ctx, long obj) throws Z3Exception + { + super(ctx, obj); + } + + UninterpretedSort(Context ctx, Symbol s) throws Z3Exception + { + super(ctx, Native.mkUninterpretedSort(ctx.nCtx(), s.NativeObject())); + } +} diff --git a/src/api/java/Version.java b/src/api/java/Version.java new file mode 100644 index 000000000..7b20a5ff8 --- /dev/null +++ b/src/api/java/Version.java @@ -0,0 +1,68 @@ +/** + * This file was automatically generated from Version.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Version information. Note that this class is static. + **/ +public final class Version +{ + Version() + { + } + + /** + * The major version + **/ + public int Major() + { + Native.IntPtr major = new Native.IntPtr(), minor = new Native.IntPtr(), build = new Native.IntPtr(), revision = new Native.IntPtr(); + Native.getVersion(major, minor, build, revision); + return major.value; + } + + /** + * The minor version + **/ + public int Minor() + { + Native.IntPtr major = new Native.IntPtr(), minor = new Native.IntPtr(), build = new Native.IntPtr(), revision = new Native.IntPtr(); + Native.getVersion(major, minor, build, revision); + return minor.value; + } + + /** + * The build version + **/ + public int Build() + { + Native.IntPtr major = new Native.IntPtr(), minor = new Native.IntPtr(), build = new Native.IntPtr(), revision = new Native.IntPtr(); + Native.getVersion(major, minor, build, revision); + return build.value; + } + + /** + * The revision + **/ + public int Revision() + { + Native.IntPtr major = new Native.IntPtr(), minor = new Native.IntPtr(), build = new Native.IntPtr(), revision = new Native.IntPtr(); + Native.getVersion(major, minor, build, revision); + return revision.value; + } + + /** + * A string representation of the version information. + **/ + public String toString() + { + Native.IntPtr major = new Native.IntPtr(), minor = new Native.IntPtr(), build = new Native.IntPtr(), revision = new Native.IntPtr(); + Native.getVersion(major, minor, build, revision); + return Integer.toString(major.value) + "." + Integer.toString(minor.value) + "." + + Integer.toString(build.value) + "." + Integer.toString(revision.value); + } +} diff --git a/src/api/java/Z3Exception.java b/src/api/java/Z3Exception.java new file mode 100644 index 000000000..6de94a5cf --- /dev/null +++ b/src/api/java/Z3Exception.java @@ -0,0 +1,40 @@ +/** + * This file was automatically generated from Z3Exception.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +import java.lang.Exception; + +/** + * The exception base class for error reporting from Z3 + **/ +@SuppressWarnings("serial") +public class Z3Exception extends Exception +{ + /** + * Constructor. + **/ + public Z3Exception() + { + super(); + } + + /** + * Constructor. + **/ + public Z3Exception(String message) + { + super(message); + } + + /** + * Constructor. + **/ + public Z3Exception(String message, Exception inner) + { + super(message, inner); + } +} diff --git a/src/api/java/Z3Object.java b/src/api/java/Z3Object.java new file mode 100644 index 000000000..522423e01 --- /dev/null +++ b/src/api/java/Z3Object.java @@ -0,0 +1,116 @@ +/** + * This file was automatically generated from Z3Object.cs + * w/ further modifications by: + * @author Christoph M. Wintersteiger (cwinter) + **/ + +package com.Microsoft.Z3; + +/** + * Internal base class for interfacing with native Z3 objects. Should not be + * used externally. + **/ +public class Z3Object extends IDisposable +{ + /** + * Finalizer. + **/ + protected void finalize() throws Z3Exception + { + Dispose(); + } + + /** + * Disposes of the underlying native Z3 object. + **/ + public void Dispose() throws Z3Exception + { + if (m_n_obj != 0) + { + DecRef(m_n_obj); + m_n_obj = 0; + } + + if (m_ctx != null) + { + m_ctx.m_refCount--; + m_ctx = null; + } + } + + private Context m_ctx = null; + private long m_n_obj = 0; + + Z3Object(Context ctx) + { + ctx.m_refCount++; + m_ctx = ctx; + } + + Z3Object(Context ctx, long obj) throws Z3Exception + { + ctx.m_refCount++; + m_ctx = ctx; + IncRef(obj); + m_n_obj = obj; + } + + void IncRef(long o) throws Z3Exception + { + } + + void DecRef(long o) throws Z3Exception + { + } + + void CheckNativeObject(long obj) throws Z3Exception + { + } + + long NativeObject() + { + return m_n_obj; + } + + void setNativeObject(long value) throws Z3Exception + { + if (value != 0) + { + CheckNativeObject(value); + IncRef(value); + } + if (m_n_obj != 0) + { + DecRef(m_n_obj); + } + m_n_obj = value; + } + + static long GetNativeObject(Z3Object s) + { + if (s == null) + return 0; + return s.NativeObject(); + } + + Context Context() + { + return m_ctx; + } + + static long[] ArrayToNative(Z3Object[] a) + { + if (a == null) + return null; + long[] an = new long[a.length]; + for (int i = 0; i < a.length; i++) + if (a[i] != null) + an[i] = a[i].NativeObject(); + return an; + } + + static int ArrayLength(Z3Object[] a) + { + return (a == null) ? 0 : (int) a.length; + } +} diff --git a/src/api/java/com/Microsoft/Z3/AST.java b/src/api/java/com/Microsoft/Z3/AST.java deleted file mode 100644 index ad4c9d94a..000000000 --- a/src/api/java/com/Microsoft/Z3/AST.java +++ /dev/null @@ -1,209 +0,0 @@ -/** - * This file was automatically generated from AST.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ -/* using System.Collections; */ -/* using System.Collections.Generic; */ - - /** - * The abstract syntax tree (AST) class. - **/ - public class AST extends Z3Object - { - /** - * Comparison operator. - * An AST - * An AST - * @return True if and are from the same context - * and represent the same sort; false otherwise. - **/ - /* Overloaded operators are not translated. */ - - /** - * Comparison operator. - * An AST - * An AST - * @return True if and are not from the same context - * or represent different sorts; false otherwise. - **/ - /* Overloaded operators are not translated. */ - - /** - * Object comparison. - **/ - public boolean Equals(object o) - { - AST casted = (AST) o; - if (casted == null) return false; - return this == casted; - } - - /** - * Object Comparison. - * Another AST - * @return Negative if the object should be sorted before , positive if after else zero. - **/ - public int CompareTo(object other) - { - if (other == null) return 1; - AST oAST = (AST) other; - if (oAST == null) - return 1; - else - { - if (Id < oAST.Id) - return -1; - else if (Id > oAST.Id) - return +1; - else - return 0; - } - } - - /** - * The AST's hash code. - * @return A hash code - **/ - public int GetHashCode() - { - return (int)Native.getAstHash(Context.nCtx, NativeObject); - } - - /** - * A unique identifier for the AST (unique among all ASTs). - **/ - public long Id() { return Native.getAstId(Context.nCtx, NativeObject); } - - /** - * Translates (copies) the AST to the Context . - * A context - * @return A copy of the AST which is associated with - **/ - public AST Translate(Context ctx) - { - - - - if (ReferenceEquals(Context, ctx)) - return this; - else - return new AST(ctx, Native.translate(Context.nCtx, NativeObject, ctx.nCtx)); - } - - /** - * The kind of the AST. - **/ - public Z3_ast_kind ASTKind() { return (Z3_ast_kind)Native.getAstKind(Context.nCtx, NativeObject); } - - /** - * Indicates whether the AST is an Expr - **/ - public boolean IsExpr() - { - 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; - } - } - - /** - * Indicates whether the AST is a BoundVariable - **/ - public boolean IsVar() { return this.ASTKind == Z3_ast_kind.Z3_VAR_AST; } - - /** - * Indicates whether the AST is a Quantifier - **/ - public boolean IsQuantifier() { return this.ASTKind == Z3_ast_kind.Z3_QUANTIFIER_AST; } - - /** - * Indicates whether the AST is a Sort - **/ - public boolean IsSort() { return this.ASTKind == Z3_ast_kind.Z3_SORT_AST; } - - /** - * Indicates whether the AST is a FunctionDeclaration - **/ - public boolean IsFuncDecl() { return this.ASTKind == Z3_ast_kind.Z3_FUNC_DECL_AST; } - - /** - * A string representation of the AST. - **/ - public String toString() - { - return Native.asttoString(Context.nCtx, NativeObject); - } - - /** - * A string representation of the AST in s-expression notation. - **/ - public String SExpr() - { - - - return Native.asttoString(Context.nCtx, NativeObject); - } - - AST(Context ctx) { super(ctx); } - AST(Context ctx, IntPtr obj) { super(ctx, obj); } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.incRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.decRef(ctx.nCtx, obj); - } - }; - - 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); - super.IncRef(o); - } - - 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); - super.DecRef(o); - } - - static AST Create(Context ctx, IntPtr obj) - { - - - - switch ((Z3_ast_kind)Native.getAstKind(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"); - } - } - } diff --git a/src/api/java/com/Microsoft/Z3/ASTMap.java b/src/api/java/com/Microsoft/Z3/ASTMap.java deleted file mode 100644 index 7b95861b4..000000000 --- a/src/api/java/com/Microsoft/Z3/ASTMap.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * This file was automatically generated from ASTMap.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Map from AST to AST - **/ - class ASTMap extends Z3Object - { - /** - * Checks whether the map contains the key . - * An AST - * @return True if is a key in the map, false otherwise. - **/ - public boolean Contains(AST k) - { - - - return Native.astMapContains(Context.nCtx, NativeObject, k.NativeObject) != 0; - } - - /** - * Finds the value associated with the key . - * - * This function signs an error when is not a key in the map. - * - * An AST - **/ - public AST Find(AST k) - { - - - - return new AST(Context, Native.astMapFind(Context.nCtx, NativeObject, k.NativeObject)); - } - - /** - * Stores or replaces a new key/value pair in the map. - * The key AST - * The value AST - **/ - public void Insert(AST k, AST v) - { - - - - Native.astMapInsert(Context.nCtx, NativeObject, k.NativeObject, v.NativeObject); - } - - /** - * Erases the key from the map. - * An AST - **/ - public void Erase(AST k) - { - - - Native.astMapErase(Context.nCtx, NativeObject, k.NativeObject); - } - - /** - * Removes all keys from the map. - **/ - public void Reset() - { - Native.astMapReset(Context.nCtx, NativeObject); - } - - /** - * The size of the map - **/ - public long Size() { return Native.astMapSize(Context.nCtx, NativeObject); } - - /** - * The keys stored in the map. - **/ - public ASTVector Keys() - { - return new ASTVector(Context, Native.astMapKeys(Context.nCtx, NativeObject)); - } - - /** - * Retrieves a string representation of the map. - **/ - public String toString() - { - return Native.astMaptoString(Context.nCtx, NativeObject); - } - - ASTMap(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - ASTMap(Context ctx) - { super(ctx, Native.mkAstMap(ctx.nCtx)); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.astMapIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.astMapDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.ASTMap_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.ASTMap_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/ASTVector.java b/src/api/java/com/Microsoft/Z3/ASTVector.java deleted file mode 100644 index 0ae2ff20a..000000000 --- a/src/api/java/com/Microsoft/Z3/ASTVector.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * This file was automatically generated from ASTVector.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Vectors of ASTs. - **/ - class ASTVector extends Z3Object - { - /** - * The size of the vector - **/ - public long Size() { return Native.astVectorSize(Context.nCtx, NativeObject); } - - /** - * Retrieves the i-th object in the vector. - * May throw an IndexOutOfBoundsException when is out of range. - * Index - * @return An AST - **/ - public AST get(long i) - { - - - return new AST(Context, Native.astVectorGet(Context.nCtx, NativeObject, i)); - } - public void set(long i, AST value) - { - - - Native.astVectorSet(Context.nCtx, NativeObject, i, value.NativeObject); - } - - /** - * Resize the vector to . - * The new size of the vector. - **/ - public void Resize(long newSize) - { - Native.astVectorResize(Context.nCtx, NativeObject, newSize); - } - - /** - * Add the AST to the back of the vector. The size - * is increased by 1. - * An AST - **/ - public void Push(AST a) - { - - - Native.astVectorPush(Context.nCtx, NativeObject, a.NativeObject); - } - - /** - * Translates all ASTs in the vector to . - * A context - * @return A new ASTVector - **/ - public ASTVector Translate(Context ctx) - { - - - - return new ASTVector(Context, Native.astVectorTranslate(Context.nCtx, NativeObject, ctx.nCtx)); - } - - /** - * Retrieves a string representation of the vector. - **/ - public String toString() - { - return Native.astVectortoString(Context.nCtx, NativeObject); - } - - ASTVector(Context ctx, IntPtr obj) { super(ctx, obj); } - ASTVector(Context ctx) { super(ctx, Native.mkAstVector(ctx.nCtx)); } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.astVectorIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.astVectorDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.ASTVector_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.ASTVector_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/ApplyResult.java b/src/api/java/com/Microsoft/Z3/ApplyResult.java deleted file mode 100644 index 9bd613930..000000000 --- a/src/api/java/com/Microsoft/Z3/ApplyResult.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * This file was automatically generated from ApplyResult.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * ApplyResult objects represent the result of an application of a - * tactic to a goal. It contains the subgoals that were produced. - **/ - public class ApplyResult extends Z3Object - { - /** - * The number of Subgoals. - **/ - public long NumSubgoals() { return Native.applyResultGetNumSubgoals(Context.nCtx, NativeObject); } - - /** - * Retrieves the subgoals from the ApplyResult. - **/ - public Goal[] Subgoals() - { - - - - long n = NumSubgoals; - Goal[] res = new Goal[n]; - for (long i = 0; i < n; i++) - res[i] = new Goal(Context, Native.applyResultGetSubgoal(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * Convert a model for the subgoal into a model for the original - * goal g, that the ApplyResult was obtained from. - * @return A model for g - **/ - public Model ConvertModel(long i, Model m) - { - - - - return new Model(Context, Native.applyResultConvertModel(Context.nCtx, NativeObject, i, m.NativeObject)); - } - - /** - * A string representation of the ApplyResult. - **/ - public String toString() - { - return Native.applyResulttoString(Context.nCtx, NativeObject); - } - - ApplyResult(Context ctx, IntPtr obj) { super(ctx, obj); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.applyResultIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.applyResultDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.ApplyResult_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.ApplyResult_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Constructor.java b/src/api/java/com/Microsoft/Z3/Constructor.java deleted file mode 100644 index 7c9b2a85c..000000000 --- a/src/api/java/com/Microsoft/Z3/Constructor.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * This file was automatically generated from Constructor.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Constructors are used for datatype sorts. - **/ - public class Constructor extends Z3Object - { - /** - * The number of fields of the constructor. - **/ - public long NumFields() - { - init(); - return n; - } - - /** - * The function declaration of the constructor. - **/ - public FuncDecl ConstructorDecl() - { - - init(); - return m_constructorDecl; - } - - /** - * The function declaration of the tester. - **/ - public FuncDecl TesterDecl() - { - - init(); - return m_testerDecl; - } - - /** - * The function declarations of the accessors - **/ - public FuncDecl[] AccessorDecls() - { - - init(); - return m_accessorDecls; - } - - /** - * Destructor. - **/ - protected void finalize() - { - Native.delConstructor(Context.nCtx, NativeObject); - } - - - private void ObjectInvariant() - { - - - } - - - private long n = 0; - private FuncDecl m_testerDecl = null; - private FuncDecl m_constructorDecl = null; - private FuncDecl[] m_accessorDecls = null; - - Constructor(Context ctx, Symbol name, Symbol recognizer, Symbol[] fieldNames, - Sort[] sorts, long[] sortRefs) - { super(ctx); - - - - - 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 long[n]; - - NativeObject = Native.mkConstructor(ctx.nCtx, name.NativeObject, recognizer.NativeObject, - n, - Symbol.ArrayToNative(fieldNames), - Sort.ArrayToNative(sorts), - sortRefs); - - } - - private void init() - { - - - - - if (m_testerDecl != null) return; - IntPtr constructor = IntPtr.Zero; - IntPtr tester = IntPtr.Zero; - IntPtr[] accessors = new IntPtr[n]; - Native.queryConstructor(Context.nCtx, NativeObject, n, constructor, tester, accessors); - m_constructorDecl = new FuncDecl(Context, constructor); - m_testerDecl = new FuncDecl(Context, tester); - m_accessorDecls = new FuncDecl[n]; - for (long i = 0; i < n; i++) - m_accessorDecls[i] = new FuncDecl(Context, accessors[i]); - } - - } - - /** - * Lists of constructors - **/ - public class ConstructorList extends Z3Object - { - /** - * Destructor. - **/ - protected void finalize() - { - Native.delConstructorList(Context.nCtx, NativeObject); - } - - ConstructorList(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - - ConstructorList(Context ctx, Constructor[] constructors) - { super(ctx); - - - - NativeObject = Native.mkConstructorList(Context.nCtx, (long)constructors.Length, Constructor.ArrayToNative(constructors)); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Context.java b/src/api/java/com/Microsoft/Z3/Context.java deleted file mode 100644 index c18fb7414..000000000 --- a/src/api/java/com/Microsoft/Z3/Context.java +++ /dev/null @@ -1,3543 +0,0 @@ -/** - * This file was automatically generated from Context.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ -/* using System.Collections.Generic; */ -/* using System.Runtime.InteropServices; */ - - /** - * The main interaction with Z3 happens via the Context. - **/ - public class Context extends IDisposable - { - /** - * Constructor. - **/ - public Context() - { super(); - m_ctx = Native.mkContextRc(IntPtr.Zero); - InitContext(); - } - - /** - * Constructor. - **/ - public Context(Dictionary settings) - { super(); - - - IntPtr cfg = Native.mkConfig(); - for (KeyValuePair.Iterator kv = settings.iterator(); kv.hasNext(); ) - Native.setParamValue(cfg, kv.Key, kv.Value); - m_ctx = Native.mkContextRc(cfg); - Native.delConfig(cfg); - InitContext(); - } - - /** - * 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) - { - - - return new IntSymbol(this, i); - } - - /** - * Create a symbol using a string. - **/ - public StringSymbol MkSymbol(String name) - { - - - return new StringSymbol(this, name); - } - - /** - * Create an array of symbols. - **/ - Symbol[] MkSymbols(String[] names) - { - - - - - - if (names == null) return null; - Symbol[] result = new Symbol[names.Length]; - for (int i = 0; i < names.Length; ++i) result[i] = MkSymbol(names[i]); - return result; - } - - private BoolSort m_booleanSort = null; - private IntSort m_intSort = null; - private RealSort m_realSort = null; - - /** - * Retrieves the Boolean sort of the context. - **/ - public BoolSort BoolSort() - { - - - if (m_booleanSort == null) m_booleanSort = new BoolSort(this); return m_booleanSort; - } - - /** - * Retrieves the Integer sort of the context. - **/ - public IntSort IntSort() - { - - if (m_intSort == null) m_intSort = new IntSort(this); return m_intSort; - } - - - /** - * Retrieves the Real sort of the context. - **/ - public RealSort RealSort () { return m_realSort; } - - /** - * Create a new Boolean sort. - **/ - public BoolSort MkBoolSort() - { - - return new BoolSort(this); - } - - /** - * Create a new uninterpreted sort. - **/ - public UninterpretedSort MkUninterpretedSort(Symbol s) - { - - - - CheckContextMatch(s); - return new UninterpretedSort(this, s); - } - - /** - * Create a new uninterpreted sort. - **/ - public UninterpretedSort MkUninterpretedSort(String str) - { - - - return MkUninterpretedSort(MkSymbol(str)); - } - - /** - * Create a new integer sort. - **/ - public IntSort MkIntSort() - { - - - return new IntSort(this); - } - - /** - * Create a real sort. - **/ - public RealSort MkRealSort() - { - - return new RealSort(this); - } - - /** - * Create a new bit-vector sort. - **/ - public BitVecSort MkBitVecSort(long size) - { - - - return new BitVecSort(this, size); - } - - /** - * Create a new array sort. - **/ - public ArraySort MkArraySort(Sort domain, Sort range) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(range); - return new ArraySort(this, domain, range); - } - - /** - * Create a new tuple sort. - **/ - public TupleSort MkTupleSort(Symbol name, Symbol[] fieldNames, Sort[] fieldSorts) - { - - - - - - - CheckContextMatch(name); - CheckContextMatch(fieldNames); - CheckContextMatch(fieldSorts); - return new TupleSort(this, name, (long)fieldNames.Length, fieldNames, fieldSorts); - } - - /** - * Create a new enumeration sort. - **/ - public EnumSort MkEnumSort(Symbol name, Symbol[] enumNames) - { - - - - - - - CheckContextMatch(name); - CheckContextMatch(enumNames); - return new EnumSort(this, name, enumNames); - } - - /** - * Create a new enumeration sort. - **/ - public EnumSort MkEnumSort(String name, String[] enumNames) - { - - - - return new EnumSort(this, MkSymbol(name), MkSymbols(enumNames)); - } - - /** - * Create a new list sort. - **/ - public ListSort MkListSort(Symbol name, Sort elemSort) - { - - - - - CheckContextMatch(name); - CheckContextMatch(elemSort); - return new ListSort(this, name, elemSort); - } - - /** - * Create a new list sort. - **/ - public ListSort MkListSort(String name, Sort elemSort) - { - - - - CheckContextMatch(elemSort); - return new ListSort(this, MkSymbol(name), elemSort); - } - - /** - * Create a new finite domain sort. - **/ - public FiniteDomainSort MkFiniteDomainSort(Symbol name, ulong size) - { - - - - CheckContextMatch(name); - return new FiniteDomainSort(this, name, size); - } - - /** - * Create a new finite domain sort. - **/ - public FiniteDomainSort MkFiniteDomainSort(String name, ulong size) - { - - - return new FiniteDomainSort(this, MkSymbol(name), size); - } - - - /** - * 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, Sort[] sorts, long[] sortRefs) - { - - - - - return new Constructor(this, name, recognizer, fieldNames, sorts, sortRefs); - } - - /** - * Create a datatype constructor. - * - * - * - * - * - * @return - **/ - public Constructor MkConstructor(String name, String recognizer, String[] fieldNames, Sort[] sorts, long[] sortRefs) - { - - - return new Constructor(this, MkSymbol(name), MkSymbol(recognizer), MkSymbols(fieldNames), sorts, sortRefs); - } - - /** - * Create a new datatype sort. - **/ - public DatatypeSort MkDatatypeSort(Symbol name, Constructor[] constructors) - { - - - - - - - CheckContextMatch(name); - CheckContextMatch(constructors); - return new DatatypeSort(this, name, constructors); - } - - /** - * Create a new datatype sort. - **/ - public DatatypeSort MkDatatypeSort(String name, Constructor[] constructors) - { - - - - - 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) - { - - - - - - - - CheckContextMatch(names); - long n = (long)names.Length; - ConstructorList[] cla = new ConstructorList[n]; - IntPtr[] n_constr = new IntPtr[n]; - for (long i = 0; i < n; i++) - { - var constructor = c[i]; - - CheckContextMatch(constructor); - cla[i] = new ConstructorList(this, constructor); - n_constr[i] = cla[i].NativeObject; - } - IntPtr[] n_res = new IntPtr[n]; - Native.mkDatatypes(nCtx, n, Symbol.ArrayToNative(names), n_res, n_constr); - DatatypeSort[] res = new DatatypeSort[n]; - for (long i = 0; i < n; i++) - res[i] = new DatatypeSort(this, n_res[i]); - return res; - } - - /** - * Create mutually recursive data-types. - * - * - * @return - **/ - public DatatypeSort[] MkDatatypeSorts(String[] names, Constructor[][] c) - { - - - - - - - - return MkDatatypeSorts(MkSymbols(names), c); - } - - - /** - * Creates a new function declaration. - **/ - public FuncDecl MkFuncDecl(Symbol name, Sort[] domain, Sort range) - { - - - - - - 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) - { - - - - - - 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) - { - - - - - 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) - { - - - - - 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) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(range); - return new FuncDecl(this, prefix, domain, range); - } - - /** - * Creates a new constant function declaration. - **/ - public FuncDecl MkConstDecl(Symbol name, Sort range) - { - - - - - CheckContextMatch(name); - CheckContextMatch(range); - return new FuncDecl(this, name, null, range); - } - - /** - * Creates a new constant function declaration. - **/ - public FuncDecl MkConstDecl(String name, Sort range) - { - - - - 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) - { - - - - CheckContextMatch(range); - return new FuncDecl(this, prefix, null, range); - } - - /** - * Creates a new bound variable. - * The de-Bruijn index of the variable - * The sort of the variable - **/ - public Expr MkBound(long index, Sort ty) - { - - - - return Expr.Create(this, Native.mkBound(nCtx, index, ty.NativeObject)); - } - - /** - * Create a quantifier pattern. - **/ - public Pattern MkPattern(Expr[] terms) - { - - if (terms.Length == 0) - throw new Z3Exception("Cannot create a pattern from zero terms"); - - - - - - IntPtr[] termsNative = AST.ArrayToNative(terms); - return new Pattern(this, Native.mkPattern(nCtx, (long)terms.Length, termsNative)); - } - - /** - * Creates a new Constant of sort and named . - **/ - public Expr MkConst(Symbol name, Sort range) - { - - - - - CheckContextMatch(name); - CheckContextMatch(range); - - return Expr.Create(this, Native.mkConst(nCtx, name.NativeObject, range.NativeObject)); - } - - /** - * Creates a new Constant of sort and named . - **/ - public Expr MkConst(String name, Sort range) - { - - - - return MkConst(MkSymbol(name), range); - } - - /** - * Creates a fresh Constant of sort and a - * name prefixed with . - **/ - public Expr MkFreshConst(String prefix, Sort range) - { - - - - CheckContextMatch(range); - return Expr.Create(this, Native.mkFreshConst(nCtx, prefix, range.NativeObject)); - } - - /** - * Creates a fresh constant from the FuncDecl . - * A decl of a 0-arity function - **/ - public Expr MkConst(FuncDecl f) - { - - - - return MkApp(f); - } - - /** - * Create a Boolean constant. - **/ - public BoolExpr MkBoolConst(Symbol name) - { - - - - return (BoolExpr)MkConst(name, BoolSort); - } - - /** - * Create a Boolean constant. - **/ - public BoolExpr MkBoolConst(String name) - { - - - return (BoolExpr)MkConst(MkSymbol(name), BoolSort); - } - - /** - * Creates an integer constant. - **/ - public IntExpr MkIntConst(Symbol name) - { - - - - return (IntExpr)MkConst(name, IntSort); - } - - /** - * Creates an integer constant. - **/ - public IntExpr MkIntConst(String name) - { - - - - return (IntExpr)MkConst(name, IntSort); - } - - /** - * Creates a real constant. - **/ - public RealExpr MkRealConst(Symbol name) - { - - - - return (RealExpr)MkConst(name, RealSort); - } - - /** - * Creates a real constant. - **/ - public RealExpr MkRealConst(String name) - { - - - return (RealExpr)MkConst(name, RealSort); - } - - /** - * Creates a bit-vector constant. - **/ - public BitVecExpr MkBVConst(Symbol name, long size) - { - - - - return (BitVecExpr)MkConst(name, MkBitVecSort(size)); - } - - /** - * Creates a bit-vector constant. - **/ - public BitVecExpr MkBVConst(String name, long size) - { - - - return (BitVecExpr)MkConst(name, MkBitVecSort(size)); - } - - /** - * Create a new function application. - **/ - public Expr MkApp(FuncDecl f, Expr[] args) - { - - - - - CheckContextMatch(f); - CheckContextMatch(args); - return Expr.Create(this, f, args); - } - - /** - * The true Term. - **/ - public BoolExpr MkTrue() - { - - - return new BoolExpr(this, Native.mkTrue(nCtx)); - } - - /** - * The false Term. - **/ - public BoolExpr MkFalse() - { - - - return new BoolExpr(this, Native.mkFalse(nCtx)); - } - - /** - * Creates a Boolean value. - **/ - public BoolExpr MkBool(boolean value) - { - - - return value ? MkTrue() : MkFalse(); - } - - /** - * Creates the equality = . - **/ - public BoolExpr MkEq(Expr x, Expr y) - { - - - - - CheckContextMatch(x); - CheckContextMatch(y); - return new BoolExpr(this, Native.mkEq(nCtx, x.NativeObject, y.NativeObject)); - } - - /** - * Creates a distinct term. - **/ - public BoolExpr MkDistinct(Expr[] args) - { - - - - - - CheckContextMatch(args); - return new BoolExpr(this, Native.mkDistinct(nCtx, (long)args.Length, AST.ArrayToNative(args))); - } - - /** - * Mk an expression representing not(a). - **/ - public BoolExpr MkNot(BoolExpr a) - { - - - - CheckContextMatch(a); - return new BoolExpr(this, Native.mkNot(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) - { - - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - CheckContextMatch(t3); - return Expr.Create(this, Native.mkIte(nCtx, t1.NativeObject, t2.NativeObject, t3.NativeObject)); - } - - /** - * Create an expression representing t1 iff t2. - **/ - public BoolExpr MkIff(BoolExpr t1, BoolExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkIff(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create an expression representing t1 -> t2. - **/ - public BoolExpr MkImplies(BoolExpr t1, BoolExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkImplies(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create an expression representing t1 xor t2. - **/ - public BoolExpr MkXor(BoolExpr t1, BoolExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkXor(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create an expression representing t[0] and t[1] and .... - **/ - public BoolExpr MkAnd(BoolExpr[] t) - { - - - - - CheckContextMatch(t); - return new BoolExpr(this, Native.mkAnd(nCtx, (long)t.Length, AST.ArrayToNative(t))); - } - - /** - * Create an expression representing t[0] or t[1] or .... - **/ - public BoolExpr MkOr(BoolExpr[] t) - { - - - - - CheckContextMatch(t); - return new BoolExpr(this, Native.mkOr(nCtx, (long)t.Length, AST.ArrayToNative(t))); - } - - /** - * Create an expression representing t[0] + t[1] + .... - **/ - public ArithExpr MkAdd(ArithExpr[] t) - { - - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Native.mkAdd(nCtx, (long)t.Length, AST.ArrayToNative(t))); - } - - /** - * Create an expression representing t[0] * t[1] * .... - **/ - public ArithExpr MkMul(ArithExpr[] t) - { - - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Native.mkMul(nCtx, (long)t.Length, AST.ArrayToNative(t))); - } - - /** - * Create an expression representing t[0] - t[1] - .... - **/ - public ArithExpr MkSub(ArithExpr[] t) - { - - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Native.mkSub(nCtx, (long)t.Length, AST.ArrayToNative(t))); - } - - /** - * Create an expression representing -t. - **/ - public ArithExpr MkUnaryMinus(ArithExpr t) - { - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Native.mkUnaryMinus(nCtx, t.NativeObject)); - } - - /** - * Create an expression representing t1 / t2. - **/ - public ArithExpr MkDiv(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return (ArithExpr)Expr.Create(this, Native.mkDiv(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new IntExpr(this, Native.mkMod(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new IntExpr(this, Native.mkRem(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create an expression representing t1 ^ t2. - **/ - public ArithExpr MkPower(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return (ArithExpr)Expr.Create(this, Native.mkPower(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create an expression representing t1 < t2 - **/ - public BoolExpr MkLt(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkLt(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create an expression representing t1 <= t2 - **/ - public BoolExpr MkLe(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkLe(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create an expression representing t1 > t2 - **/ - public BoolExpr MkGt(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkGt(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create an expression representing t1 >= t2 - **/ - public BoolExpr MkGe(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkGe(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) - { - - - - CheckContextMatch(t); - return new RealExpr(this, Native.mkInt2real(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) - { - - - - CheckContextMatch(t); - return new IntExpr(this, Native.mkReal2int(nCtx, t.NativeObject)); - } - - /** - * Creates an expression that checks whether a real number is an integer. - **/ - public BoolExpr MkIsInteger(RealExpr t) - { - - - - CheckContextMatch(t); - return new BoolExpr(this, Native.mkIsInt(nCtx, t.NativeObject)); - } - - /** - * Bitwise negation. - * The argument must have a bit-vector sort. - **/ - public BitVecExpr MkBVNot(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkBvnot(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) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkBvredand(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) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkBvredor(nCtx, t.NativeObject)); - } - - /** - * Bitwise conjunction. - * The arguments must have a bit-vector sort. - **/ - public BitVecExpr MkBVAND(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvand(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Bitwise disjunction. - * The arguments must have a bit-vector sort. - **/ - public BitVecExpr MkBVOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvor(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Bitwise XOR. - * The arguments must have a bit-vector sort. - **/ - public BitVecExpr MkBVXOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvxor(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Bitwise NAND. - * The arguments must have a bit-vector sort. - **/ - public BitVecExpr MkBVNAND(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvnand(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Bitwise NOR. - * The arguments must have a bit-vector sort. - **/ - public BitVecExpr MkBVNOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvnor(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Bitwise XNOR. - * The arguments must have a bit-vector sort. - **/ - public BitVecExpr MkBVXNOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvxnor(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Standard two's complement unary minus. - * The arguments must have a bit-vector sort. - **/ - public BitVecExpr MkBVNeg(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkBvneg(nCtx, t.NativeObject)); - } - - /** - * Two's complement addition. - * The arguments must have the same bit-vector sort. - **/ - public BitVecExpr MkBVAdd(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvadd(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvsub(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvmul(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvudiv(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvsdiv(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvurem(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvsrem(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvsmod(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Unsigned less-than - * - * The arguments must have the same bit-vector sort. - * - **/ - public BoolExpr MkBVULT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvult(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvslt(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvule(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvsle(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvuge(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvsge(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Unsigned greater-than. - * - * The arguments must have the same bit-vector sort. - * - **/ - public BoolExpr MkBVUGT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvugt(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvsgt(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Bit-vector concatenation. - * - * The arguments must have a bit-vector sort. - * - * @return - * 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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkConcat(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(long high, long low, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkExtract(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(long i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkSignExt(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(long i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkZeroExt(nCtx, i, t.NativeObject)); - } - - /** - * Bit-vector repetition. - * - * The argument must have a bit-vector sort. - * - **/ - public BitVecExpr MkRepeat(long i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkRepeat(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvshl(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvlshr(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkBvashr(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(long i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkRotateLeft(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(long i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkRotateRight(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkExtRotateLeft(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Native.mkExtRotateRight(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(long n, IntExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Native.mkInt2bv(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, boolean signed) - { - - - - CheckContextMatch(t); - return new IntExpr(this, Native.mkBv2int(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, boolean isSigned) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvaddNoOverflow(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvaddNoUnderflow(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvsubNoOverflow(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, boolean isSigned) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvsubNoUnderflow(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvsdivNoOverflow(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) - { - - - - CheckContextMatch(t); - return new BoolExpr(this, Native.mkBvnegNoOverflow(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, boolean isSigned) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvmulNoOverflow(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) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Native.mkBvmulNoUnderflow(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create an array constant. - **/ - public ArrayExpr MkArrayConst(Symbol name, Sort domain, Sort range) - { - - - - - - return (ArrayExpr)MkConst(name, MkArraySort(domain, range)); - } - - /** - * Create an array constant. - **/ - public ArrayExpr MkArrayConst(String name, Sort domain, Sort range) - { - - - - - 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) - { - - - - - CheckContextMatch(a); - CheckContextMatch(i); - return Expr.Create(this, Native.mkSelect(nCtx, a.NativeObject, i.NativeObject)); - } - - /** - * 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) - { - - - - - - CheckContextMatch(a); - CheckContextMatch(i); - CheckContextMatch(v); - return new ArrayExpr(this, Native.mkStore(nCtx, a.NativeObject, i.NativeObject, 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) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(v); - return new ArrayExpr(this, Native.mkConstArray(nCtx, domain.NativeObject, v.NativeObject)); - } - - /** - * Maps f on the argument arrays. - * - * Eeach 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, ArrayExpr[] args) - { - - - - - CheckContextMatch(f); - CheckContextMatch(args); - return (ArrayExpr)Expr.Create(this, Native.mkMap(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) - { - - - - CheckContextMatch(array); - return Expr.Create(this, Native.mkArrayDefault(nCtx, array.NativeObject)); - } - - /** - * Create a set type. - **/ - public SetSort MkSetSort(Sort ty) - { - - - - CheckContextMatch(ty); - return new SetSort(this, ty); - } - - /** - * Create an empty set. - **/ - public Expr MkEmptySet(Sort domain) - { - - - - CheckContextMatch(domain); - return Expr.Create(this, Native.mkEmptySet(nCtx, domain.NativeObject)); - } - - /** - * Create the full set. - **/ - public Expr MkFullSet(Sort domain) - { - - - - CheckContextMatch(domain); - return Expr.Create(this, Native.mkFullSet(nCtx, domain.NativeObject)); - } - - /** - * Add an element to the set. - **/ - public Expr MkSetAdd(Expr set, Expr element) - { - - - - - CheckContextMatch(set); - CheckContextMatch(element); - return Expr.Create(this, Native.mkSetAdd(nCtx, set.NativeObject, element.NativeObject)); - } - - - /** - * Remove an element from a set. - **/ - public Expr MkSetDel(Expr set, Expr element) - { - - - - - CheckContextMatch(set); - CheckContextMatch(element); - return Expr.Create(this, Native.mkSetDel(nCtx, set.NativeObject, element.NativeObject)); - } - - /** - * Take the union of a list of sets. - **/ - public Expr MkSetUnion(Expr[] args) - { - - - - CheckContextMatch(args); - return Expr.Create(this, Native.mkSetUnion(nCtx, (long)args.Length, AST.ArrayToNative(args))); - } - - /** - * Take the intersection of a list of sets. - **/ - public Expr MkSetIntersection(Expr[] args) - { - - - - - CheckContextMatch(args); - return Expr.Create(this, Native.mkSetIntersect(nCtx, (long)args.Length, AST.ArrayToNative(args))); - } - - /** - * Take the difference between two sets. - **/ - public Expr MkSetDifference(Expr arg1, Expr arg2) - { - - - - - CheckContextMatch(arg1); - CheckContextMatch(arg2); - return Expr.Create(this, Native.mkSetDifference(nCtx, arg1.NativeObject, arg2.NativeObject)); - } - - /** - * Take the complement of a set. - **/ - public Expr MkSetComplement(Expr arg) - { - - - - CheckContextMatch(arg); - return Expr.Create(this, Native.mkSetComplement(nCtx, arg.NativeObject)); - } - - /** - * Check for set membership. - **/ - public Expr MkSetMembership(Expr elem, Expr set) - { - - - - - CheckContextMatch(elem); - CheckContextMatch(set); - return Expr.Create(this, Native.mkSetMember(nCtx, elem.NativeObject, set.NativeObject)); - } - - /** - * Check for subsetness of sets. - **/ - public Expr MkSetSubset(Expr arg1, Expr arg2) - { - - - - - CheckContextMatch(arg1); - CheckContextMatch(arg2); - return Expr.Create(this, Native.mkSetSubset(nCtx, arg1.NativeObject, arg2.NativeObject)); - } - - - /** - * 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. - * @return A Term with value and sort - **/ - public Expr MkNumeral(String v, Sort ty) - { - - - - CheckContextMatch(ty); - return Expr.Create(this, Native.mkNumeral(nCtx, v, ty.NativeObject)); - } - - /** - * Create a Term of a given sort. This function can be use 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 - * @return A Term with value and type - **/ - public Expr MkNumeral(int v, Sort ty) - { - - - - CheckContextMatch(ty); - return Expr.Create(this, Native.mkInt(nCtx, v, ty.NativeObject)); - } - - /** - * Create a Term of a given sort. This function can be use 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 - * @return A Term with value and type - **/ - public Expr MkNumeral(long v, Sort ty) - { - - - - CheckContextMatch(ty); - return Expr.Create(this, Native.mkUnsignedInt(nCtx, v, ty.NativeObject)); - } - - /** - * Create a Term of a given sort. This function can be use 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 - * @return A Term with value and type - **/ - public Expr MkNumeral(long v, Sort ty) - { - - - - CheckContextMatch(ty); - return Expr.Create(this, Native.mkInt64(nCtx, v, ty.NativeObject)); - } - - /** - * Create a Term of a given sort. This function can be use 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 - * @return A Term with value and type - **/ - public Expr MkNumeral(ulong v, Sort ty) - { - - - - CheckContextMatch(ty); - return Expr.Create(this, Native.mkUnsignedInt64(nCtx, v, ty.NativeObject)); - } - - /** - * Create a real from a fraction. - * numerator of rational. - * denominator of rational. - * @return A Term with value / and sort Real - * - **/ - public RatNum MkReal(int num, int den) - { - if (den == 0) - throw new Z3Exception("Denominator is zero"); - - - - - return new RatNum(this, Native.mkReal(nCtx, num, den)); - } - - /** - * Create a real numeral. - * A string representing the Term value in decimal notation. - * @return A Term with value and sort Real - **/ - public RatNum MkReal(String v) - { - - - return new RatNum(this, Native.mkNumeral(nCtx, v, RealSort.NativeObject)); - } - - /** - * Create a real numeral. - * value of the numeral. - * @return A Term with value and sort Real - **/ - public RatNum MkReal(int v) - { - - - return new RatNum(this, Native.mkInt(nCtx, v, RealSort.NativeObject)); - } - - /** - * Create a real numeral. - * value of the numeral. - * @return A Term with value and sort Real - **/ - public RatNum MkReal(long v) - { - - - return new RatNum(this, Native.mkUnsignedInt(nCtx, v, RealSort.NativeObject)); - } - - /** - * Create a real numeral. - * value of the numeral. - * @return A Term with value and sort Real - **/ - public RatNum MkReal(long v) - { - - - return new RatNum(this, Native.mkInt64(nCtx, v, RealSort.NativeObject)); - } - - /** - * Create a real numeral. - * value of the numeral. - * @return A Term with value and sort Real - **/ - public RatNum MkReal(ulong v) - { - - - return new RatNum(this, Native.mkUnsignedInt64(nCtx, v, RealSort.NativeObject)); - } - - /** - * Create an integer numeral. - * A string representing the Term value in decimal notation. - **/ - public IntNum MkInt(String v) - { - - - return new IntNum(this, Native.mkNumeral(nCtx, v, IntSort.NativeObject)); - } - - /** - * Create an integer numeral. - * value of the numeral. - * @return A Term with value and sort Integer - **/ - public IntNum MkInt(int v) - { - - - return new IntNum(this, Native.mkInt(nCtx, v, IntSort.NativeObject)); - } - - /** - * Create an integer numeral. - * value of the numeral. - * @return A Term with value and sort Integer - **/ - public IntNum MkInt(long v) - { - - - return new IntNum(this, Native.mkUnsignedInt(nCtx, v, IntSort.NativeObject)); - } - - /** - * Create an integer numeral. - * value of the numeral. - * @return A Term with value and sort Integer - **/ - public IntNum MkInt(long v) - { - - - return new IntNum(this, Native.mkInt64(nCtx, v, IntSort.NativeObject)); - } - - /** - * Create an integer numeral. - * value of the numeral. - * @return A Term with value and sort Integer - **/ - public IntNum MkInt(ulong v) - { - - - return new IntNum(this, Native.mkUnsignedInt64(nCtx, v, IntSort.NativeObject)); - } - - /** - * Create a bit-vector numeral. - * A string representing the value in decimal notation. - * the size of the bit-vector - **/ - public BitVecNum MkBV(String v, long size) - { - - - 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, long size) - { - - - 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, long size) - { - - - 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, long size) - { - - - 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, long size) - { - - - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } - - - /** - * Create a universal Quantifier. - * - * Creates a forall formula, where is the weight, - * is an array of patterns, is an array - * with the sorts of the bound variables, is an array with the - * 'names' of the bound variables, and is the body of the - * quantifier. Quantifiers are associated with weights indicating - * the importance of using the quantifier during instantiation. - * - * the sorts of the bound variables. - * names of the bound variables - * the body of the quantifier. - * quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - * array containing the patterns created using MkPattern. - * array containing the anti-patterns created using MkPattern. - * optional symbol to track quantifier. - * optional symbol to track skolem constants. - **/ - public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, long weight, Pattern[] patterns, Expr[] noPatterns, Symbol quantifierID, Symbol skolemID) - { - - - - - - - - - - - - return new Quantifier(this, true, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - } - - - /** - * Create a universal Quantifier. - **/ - public Quantifier MkForall(Expr[] boundConstants, Expr body, long weight, Pattern[] patterns, Expr[] noPatterns, Symbol quantifierID, Symbol skolemID) - { - - - - - - - - return new Quantifier(this, true, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - } - - /** - * Create an existential Quantifier. - * - **/ - public Quantifier MkExists(Sort[] sorts, Symbol[] names, Expr body, long weight, Pattern[] patterns, Expr[] noPatterns, Symbol quantifierID, Symbol skolemID) - { - - - - - - - - - - - return new Quantifier(this, false, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - } - - /** - * Create an existential Quantifier. - **/ - public Quantifier MkExists(Expr[] boundConstants, Expr body, long weight, Pattern[] patterns, Expr[] noPatterns, Symbol quantifierID, Symbol skolemID) - { - - - - - - - return new Quantifier(this, false, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - } - - - /** - * Create a Quantifier. - **/ - public Quantifier MkQuantifier(boolean universal, Sort[] sorts, Symbol[] names, Expr body, long weight, Pattern[] patterns, Expr[] noPatterns, Symbol quantifierID, Symbol skolemID) - { - - - - - - - - - - - - if (universal) - return MkForall(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - return MkExists(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - } - - - /** - * Create a Quantifier. - **/ - public Quantifier MkQuantifier(boolean universal, Expr[] boundConstants, Expr body, long weight, Pattern[] patterns, Expr[] noPatterns, Symbol quantifierID, Symbol skolemID) - { - - - - - - - - if (universal) - return MkForall(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - return MkExists(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - } - - - - /** - * Selects the format used for pretty-printing expressions. - * - * The default mode for pretty printing expressions is to produce - * SMT-LIB style output where common subexpressions are printed - * at each occurrence. The mode is called Z3_PRINT_SMTLIB_FULL. - * To print shared common subexpressions only once, - * use the Z3_PRINT_LOW_LEVEL mode. - * To print in way that conforms to SMT-LIB standards and uses let - * expressions to share common sub-expressions use Z3_PRINT_SMTLIB_COMPLIANT. - * - * - * - * - * - **/ - public void setPrintMode(Z3_ast_print_mode value) { Native.setAstPrintMode(nCtx, (long)value); } - - /** - * Convert a benchmark into an SMT-LIB formatted string. - * Name of the benchmark. The argument is optional. - * The benchmark logic. - * The status string (sat, unsat, or unknown) - * Other attributes, such as source, difficulty or category. - * Auxiliary assumptions. - * Formula to be checked for consistency in conjunction with assumptions. - * @return A string representation of the benchmark. - **/ - public String BenchmarkToSMTString(String name, String logic, String status, String attributes, - BoolExpr[] assumptions, BoolExpr formula) - { - - - - - return Native.benchmarkToSmtlibString(nCtx, name, logic, status, attributes, - (long)assumptions.Length, AST.ArrayToNative(assumptions), - formula.NativeObject); - } - - /** - * Parse the given string using the SMT-LIB parser. - * - * The symbol table of the parser can be initialized using the given sorts and declarations. - * The symbols in the arrays and - * don't need to match the names of the sorts and declarations in the arrays - * and . This is a useful feature since we can use arbitrary names to - * reference sorts and declarations. - * - **/ - public void ParseSMTLIBString(String str, Symbol[] sortNames, Sort[] sorts, Symbol[] declNames, FuncDecl[] decls) - { - long csn = Symbol.ArrayLength(sortNames); - long cs = Sort.ArrayLength(sorts); - long cdn = Symbol.ArrayLength(declNames); - long cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Native.parseSmtlibString(nCtx, str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)); - } - - /** - * Parse the given file using the SMT-LIB parser. - * - **/ - public void ParseSMTLIBFile(String fileName, Symbol[] sortNames, Sort[] sorts, Symbol[] declNames, FuncDecl[] decls) - { - long csn = Symbol.ArrayLength(sortNames); - long cs = Sort.ArrayLength(sorts); - long cdn = Symbol.ArrayLength(declNames); - long cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Native.parseSmtlibFile(nCtx, fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)); - } - - /** - * The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - **/ - public long NumSMTLIBFormulas () { return Native.getSmtlibNumFormulas(nCtx); } - - /** - * The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - **/ - public BoolExpr[] SMTLIBFormulas() - { - - - long n = NumSMTLIBFormulas; - BoolExpr[] res = new BoolExpr[n]; - for (long i = 0; i < n; i++) - res[i] = (BoolExpr)Expr.Create(this, Native.getSmtlibFormula(nCtx, i)); - return res; - } - - /** - * The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - **/ - public long NumSMTLIBAssumptions () { return Native.getSmtlibNumAssumptions(nCtx); } - - /** - * The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - **/ - public BoolExpr[] SMTLIBAssumptions() - { - - - long n = NumSMTLIBAssumptions; - BoolExpr[] res = new BoolExpr[n]; - for (long i = 0; i < n; i++) - res[i] = (BoolExpr)Expr.Create(this, Native.getSmtlibAssumption(nCtx, i)); - return res; - } - - /** - * The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - **/ - public long NumSMTLIBDecls () { return Native.getSmtlibNumDecls(nCtx); } - - /** - * The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - **/ - public FuncDecl[] SMTLIBDecls() - { - - - long n = NumSMTLIBDecls; - FuncDecl[] res = new FuncDecl[n]; - for (long i = 0; i < n; i++) - res[i] = new FuncDecl(this, Native.getSmtlibDecl(nCtx, i)); - return res; - } - - /** - * The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - **/ - public long NumSMTLIBSorts () { return Native.getSmtlibNumSorts(nCtx); } - - /** - * The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - **/ - public Sort[] SMTLIBSorts() - { - - - long n = NumSMTLIBSorts; - Sort[] res = new Sort[n]; - for (long i = 0; i < n; i++) - res[i] = Sort.Create(this, Native.getSmtlibSort(nCtx, i)); - return res; - } - - /** - * Parse the given string using the SMT-LIB2 parser. - * - * @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. - **/ - public BoolExpr ParseSMTLIB2String(String str, Symbol[] sortNames, Sort[] sorts, Symbol[] declNames, FuncDecl[] decls) - { - - - long csn = Symbol.ArrayLength(sortNames); - long cs = Sort.ArrayLength(sorts); - long cdn = Symbol.ArrayLength(declNames); - long cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - return (BoolExpr)Expr.Create(this, Native.parseSmtlib2String(nCtx, str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls))); - } - - /** - * Parse the given file using the SMT-LIB2 parser. - * - **/ - public BoolExpr ParseSMTLIB2File(String fileName, Symbol[] sortNames, Sort[] sorts, Symbol[] declNames, FuncDecl[] decls) - { - - - long csn = Symbol.ArrayLength(sortNames); - long cs = Sort.ArrayLength(sorts); - long cdn = Symbol.ArrayLength(declNames); - long cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - return (BoolExpr)Expr.Create(this, Native.parseSmtlib2File(nCtx, fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls))); - } - - /** - * Creates a new Goal. - * - * Note that the Context must have been created with proof generation support if - * is set to true here. - * - * Indicates whether model generation should be enabled. - * Indicates whether unsat core generation should be enabled. - * Indicates whether proof generation should be enabled. - **/ - public Goal MkGoal(boolean models, boolean unsatCores, boolean proofs) - { - - - return new Goal(this, models, unsatCores, proofs); - } - - /** - * Creates a new ParameterSet. - **/ - public Params MkParams() - { - - - return new Params(this); - } - - /** - * The number of supported tactics. - **/ - public long NumTactics() { return Native.getNumTactics(nCtx); } - - /** - * The names of all supported tactics. - **/ - public String[] TacticNames() - { - - - long n = NumTactics; - String[] res = new String[n]; - for (long i = 0; i < n; i++) - res[i] = Native.getTacticName(nCtx, i); - return res; - } - - /** - * Returns a string containing a description of the tactic with the given name. - **/ - public String TacticDescription(String name) - { - - - return Native.tacticGetDescr(nCtx, name); - } - - /** - * Creates a new Tactic. - **/ - public Tactic MkTactic(String name) - { - - - return new Tactic(this, name); - } - - /** - * Create a tactic that applies to a Goal and - * then to every subgoal produced by . - **/ - public Tactic AndThen(Tactic t1, Tactic t2, Tactic[] ts) - { - - - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - CheckContextMatch(ts); - - IntPtr last = IntPtr.Zero; - if (ts != null && ts.Length > 0) - { - last = ts[ts.Length - 1].NativeObject; - for (int i = ts.Length - 2; i >= 0; i--) - last = Native.tacticAndThen(nCtx, ts[i].NativeObject, last); - } - if (last != IntPtr.Zero) - { - last = Native.tacticAndThen(nCtx, t2.NativeObject, last); - return new Tactic(this, Native.tacticAndThen(nCtx, t1.NativeObject, last)); - } - else - return new Tactic(this, Native.tacticAndThen(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create a tactic that applies to a Goal and - * then to every subgoal produced by . - * - * Shorthand for AndThen. - * - **/ - public Tactic Then(Tactic t1, Tactic t2, Tactic[] ts) - { - - - - - - return AndThen(t1, t2, ts); - } - - /** - * Create a tactic that first applies to a Goal and - * if it fails then returns the result of applied to the Goal. - **/ - public Tactic OrElse(Tactic t1, Tactic t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new Tactic(this, Native.tacticOrElse(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create a tactic that applies to a goal for milliseconds. - * - * If does not terminate within milliseconds, then it fails. - * - **/ - public Tactic TryFor(Tactic t, long ms) - { - - - - CheckContextMatch(t); - return new Tactic(this, Native.tacticTryFor(nCtx, t.NativeObject, ms)); - } - - /** - * Create a tactic that applies to a given goal if the probe - * evaluates to true. - * - * If evaluates to false, then the new tactic behaves like the skip tactic. - * - **/ - public Tactic When(Probe p, Tactic t) - { - - - - - CheckContextMatch(t); - CheckContextMatch(p); - return new Tactic(this, Native.tacticWhen(nCtx, p.NativeObject, t.NativeObject)); - } - - /** - * Create a tactic that applies to a given goal if the probe - * evaluates to true and otherwise. - **/ - public Tactic Cond(Probe p, Tactic t1, Tactic t2) - { - - - - - - CheckContextMatch(p); - CheckContextMatch(t1); - CheckContextMatch(t2); - return new Tactic(this, Native.tacticCond(nCtx, p.NativeObject, t1.NativeObject, t2.NativeObject)); - } - - /** - * Create a tactic that keeps applying until the goal is not - * modified anymore or the maximum number of iterations is reached. - **/ - public Tactic Repeat(Tactic t, long max) - { - - - - CheckContextMatch(t); - return new Tactic(this, Native.tacticRepeat(nCtx, t.NativeObject, max)); - } - - /** - * Create a tactic that just returns the given goal. - **/ - public Tactic Skip() - { - - - return new Tactic(this, Native.tacticSkip(nCtx)); - } - - /** - * Create a tactic always fails. - **/ - public Tactic Fail() - { - - - return new Tactic(this, Native.tacticFail(nCtx)); - } - - /** - * Create a tactic that fails if the probe evaluates to false. - **/ - public Tactic FailIf(Probe p) - { - - - - CheckContextMatch(p); - return new Tactic(this, Native.tacticFailIf(nCtx, p.NativeObject)); - } - - /** - * Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - * or trivially unsatisfiable (i.e., contains `false'). - **/ - public Tactic FailIfNotDecided() - { - - - return new Tactic(this, Native.tacticFailIfNotDecided(nCtx)); - } - - /** - * Create a tactic that applies using the given set of parameters . - **/ - public Tactic UsingParams(Tactic t, Params p) - { - - - - - CheckContextMatch(t); - CheckContextMatch(p); - return new Tactic(this, Native.tacticUsingParams(nCtx, t.NativeObject, p.NativeObject)); - } - - /** - * Create a tactic that applies using the given set of parameters . - * Alias for UsingParams - **/ - public Tactic With(Tactic t, Params p) - { - - - - - return UsingParams(t, p); - } - - /** - * Create a tactic that applies the given tactics in parallel. - **/ - public Tactic ParOr(Tactic[] t) - { - - - - CheckContextMatch(t); - return new Tactic(this, Native.tacticParOr(nCtx, Tactic.ArrayLength(t), Tactic.ArrayToNative(t))); - } - - /** - * Create a tactic that applies to a given goal and then - * to every subgoal produced by . The subgoals are processed in parallel. - **/ - public Tactic ParAndThen(Tactic t1, Tactic t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new Tactic(this, Native.tacticParAndThen(nCtx, t1.NativeObject, t2.NativeObject)); - } - - /** - * Interrupt the execution of a Z3 procedure. - * This procedure can be used to interrupt: solvers, simplifiers and tactics. - **/ - public void Interrupt() - { - Native.interrupt(nCtx); - } - - /** - * The number of supported Probes. - **/ - public long NumProbes() { return Native.getNumProbes(nCtx); } - - /** - * The names of all supported Probes. - **/ - public String[] ProbeNames() - { - - - long n = NumProbes; - String[] res = new String[n]; - for (long i = 0; i < n; i++) - res[i] = Native.getProbeName(nCtx, i); - return res; - } - - /** - * Returns a string containing a description of the probe with the given name. - **/ - public String ProbeDescription(String name) - { - - - return Native.probeGetDescr(nCtx, name); - } - - /** - * Creates a new Probe. - **/ - public Probe MkProbe(String name) - { - - - return new Probe(this, name); - } - - /** - * Create a probe that always evaluates to . - **/ - public Probe Const(double val) - { - - - return new Probe(this, Native.probeConst(nCtx, val)); - } - - /** - * Create a probe that evaluates to "true" when the value returned by - * is less than the value returned by - **/ - public Probe Lt(Probe p1, Probe p2) - { - - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Native.probeLt(nCtx, p1.NativeObject, p2.NativeObject)); - } - - /** - * Create a probe that evaluates to "true" when the value returned by - * is greater than the value returned by - **/ - public Probe Gt(Probe p1, Probe p2) - { - - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Native.probeGt(nCtx, p1.NativeObject, p2.NativeObject)); - } - - /** - * Create a probe that evaluates to "true" when the value returned by - * is less than or equal the value returned by - **/ - public Probe Le(Probe p1, Probe p2) - { - - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Native.probeLe(nCtx, p1.NativeObject, p2.NativeObject)); - } - - /** - * Create a probe that evaluates to "true" when the value returned by - * is greater than or equal the value returned by - **/ - public Probe Ge(Probe p1, Probe p2) - { - - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Native.probeGe(nCtx, p1.NativeObject, p2.NativeObject)); - } - - /** - * Create a probe that evaluates to "true" when the value returned by - * is equal to the value returned by - **/ - public Probe Eq(Probe p1, Probe p2) - { - - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Native.probeEq(nCtx, p1.NativeObject, p2.NativeObject)); - } - - /** - * Create a probe that evaluates to "true" when the value - * and evaluate to "true". - **/ - public Probe And(Probe p1, Probe p2) - { - - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Native.probeAnd(nCtx, p1.NativeObject, p2.NativeObject)); - } - - /** - * Create a probe that evaluates to "true" when the value - * or evaluate to "true". - **/ - public Probe Or(Probe p1, Probe p2) - { - - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Native.probeOr(nCtx, p1.NativeObject, p2.NativeObject)); - } - - /** - * Create a probe that evaluates to "true" when the value - * does not evaluate to "true". - **/ - public Probe Not(Probe p) - { - - - - CheckContextMatch(p); - return new Probe(this, Native.probeNot(nCtx, p.NativeObject)); - } - - /** - * Creates a new (incremental) solver. - * - * This solver also uses a set of builtin tactics for handling the first - * check-sat command, and check-sat commands that take more than a given - * number of milliseconds to be solved. - * - **/ - public Solver MkSolver(Symbol logic) - { - - - if (logic == null) - return new Solver(this, Native.mkSolver(nCtx)); - else - return new Solver(this, Native.mkSolverForLogic(nCtx, logic.NativeObject)); - } - - /** - * Creates a new (incremental) solver. - * - **/ - public Solver MkSolver(String logic) - { - - - return MkSolver(MkSymbol(logic)); - } - - /** - * Creates a new (incremental) solver. - **/ - public Solver MkSimpleSolver() - { - - - return new Solver(this, Native.mkSimpleSolver(nCtx)); - } - - /** - * Creates a solver that is implemented using the given tactic. - * - * The solver supports the commands Push and Pop, but it - * will always solve each check from scratch. - * - **/ - public Solver MkSolver(Tactic t) - { - - - - return new Solver(this, Native.mkSolverFromTactic(nCtx, t.NativeObject)); - } - - /** - * Create a Fixedpoint context. - **/ - public Fixedpoint MkFixedpoint() - { - - - return new Fixedpoint(this); - } - - - /** - * Wraps an AST. - * This function is used for transitions between native and - * managed objects. Note that must be a - * native object obtained from Z3 (e.g., through ) - * and that it must have a correct reference count (see e.g., - * . - * - * The native pointer to wrap. - **/ - public AST WrapAST(IntPtr nativeObject) - { - - return AST.Create(this, nativeObject); - } - - /** - * Unwraps an AST. - * This function is used for transitions between native and - * managed objects. It returns the native pointer to the AST. Note that - * AST objects are reference counted and unwrapping an AST disables automatic - * reference counting, i.e., all references to the IntPtr that is returned - * must be handled externally and through native calls (see e.g., - * ). - * - * The AST to unwrap. - **/ - public IntPtr UnwrapAST(AST a) - { - return a.NativeObject; - } - - /** - * Return a string describing all available parameters to Expr.Simplify. - **/ - public String SimplifyHelp() - { - - - return Native.simplifyGetHelp(nCtx); - } - - /** - * Retrieves parameter descriptions for simplifier. - **/ - public ParamDescrs SimplifyParameterDescriptions() { return new ParamDescrs(this, Native.simplifyGetParamDescrs(nCtx)); } - - /** - * Enable/disable printing of warning messages to the console. - * Note that this function is static and effects the behaviour of - * all contexts globally. - **/ - public static void ToggleWarningMessages(boolean enabled) - { - Native.toggleWarningMessages((enabled) ? 1 : 0); - } - - ///// - ///// A delegate which is executed when an error is raised. - ///// - ///// - ///// Note that it is possible for memory leaks to occur if error handlers - ///// throw exceptions. - ///// - //public delegate void ErrorHandler(Context ctx, Z3_error_code errorCode, String errorString); - - ///// - ///// The OnError event. - ///// - //public event ErrorHandler OnError = null; - - /** - * Update a mutable configuration parameter. - * - * The list of all configuration parameters can be obtained using the Z3 executable: - * z3.exe -ini? - * Only a few configuration parameters are mutable once the context is created. - * An exception is thrown when trying to modify an immutable parameter. - * - * - **/ - public void UpdateParamValue(String id, String value) - { - Native.updateParamValue(nCtx, id, value); - } - - /** - * Get a configuration parameter. - * - * Returns null if the parameter value does not exist. - * - * - **/ - public String GetParamValue(String id) - { - Native.IntPtr res = new Native.IntPtr(); - int r = Native.getParamValue(nCtx, id, res); - if (r == (int)Z3_lboolean.Z3_L_FALSE) - return null; - else - return Marshal.PtrtoStringAnsi(res); - } - - - IntPtr m_ctx = IntPtr.Zero; - Native.errorHandler mNErrHandler = null; - IntPtr nCtx () { return m_ctx; } - - void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) - { - // Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. - } - - void InitContext() - { - PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; - m_n_err_handler = new Native.errorHandler(NativeErrorHandler); // keep reference so it doesn't get collected. - Native.setErrorHandler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); - } - - void CheckContextMatch(Z3Object other) - { - - - if (!ReferenceEquals(this, other.Context)) - throw new Z3Exception("Context mismatch"); - } - - void CheckContextMatch(Z3Object[] arr) - { - - - if (arr != null) - { - for (Z3Object.Iterator a = arr.iterator(); a.hasNext(); ) - { - // It was an assume, now we added the precondition, and we made it into an assert - CheckContextMatch(a); - } - } - } - - private void ObjectInvariant() - { - - - - - - - - - - - - - - - - } - - private AST.DecRefQueue m_AST_DRQ = new AST.DecRefQueue(); - private ASTMap.DecRefQueue m_ASTMap_DRQ = new ASTMap.DecRefQueue(); - private ASTVector.DecRefQueue m_ASTVector_DRQ = new ASTVector.DecRefQueue(); - private ApplyResult.DecRefQueue m_ApplyResult_DRQ = new ApplyResult.DecRefQueue(); - private FuncInterp.Entry.DecRefQueue m_FuncEntry_DRQ = new FuncInterp.Entry.DecRefQueue(); - private FuncInterp.DecRefQueue m_FuncInterp_DRQ = new FuncInterp.DecRefQueue(); - private Goal.DecRefQueue m_Goal_DRQ = new Goal.DecRefQueue(); - private Model.DecRefQueue m_Model_DRQ = new Model.DecRefQueue(); - private Params.DecRefQueue m_Params_DRQ = new Params.DecRefQueue(); - private ParamDescrs.DecRefQueue m_ParamDescrs_DRQ = new ParamDescrs.DecRefQueue(); - private Probe.DecRefQueue m_Probe_DRQ = new Probe.DecRefQueue(); - private Solver.DecRefQueue m_Solver_DRQ = new Solver.DecRefQueue(); - private Statistics.DecRefQueue m_Statistics_DRQ = new Statistics.DecRefQueue(); - private Tactic.DecRefQueue m_Tactic_DRQ = new Tactic.DecRefQueue(); - private Fixedpoint.DecRefQueue m_Fixedpoint_DRQ = new Fixedpoint.DecRefQueue(); - - AST.DecRefQueue AST_DRQ () { return m_AST_DRQ; } - ASTMap.DecRefQueue ASTMap_DRQ () { return m_ASTMap_DRQ; } - ASTVector.DecRefQueue ASTVector_DRQ () { return m_ASTVector_DRQ; } - ApplyResult.DecRefQueue ApplyResult_DRQ () { return m_ApplyResult_DRQ; } - FuncInterp.Entry.DecRefQueue FuncEntry_DRQ () { return m_FuncEntry_DRQ; } - FuncInterp.DecRefQueue FuncInterp_DRQ () { return m_FuncInterp_DRQ; } - Goal.DecRefQueue Goal_DRQ () { return m_Goal_DRQ; } - Model.DecRefQueue Model_DRQ () { return m_Model_DRQ; } - Params.DecRefQueue Params_DRQ () { return m_Params_DRQ; } - ParamDescrs.DecRefQueue ParamDescrs_DRQ () { return m_ParamDescrs_DRQ; } - Probe.DecRefQueue Probe_DRQ () { return m_Probe_DRQ; } - Solver.DecRefQueue Solver_DRQ () { return m_Solver_DRQ; } - Statistics.DecRefQueue Statistics_DRQ () { return m_Statistics_DRQ; } - Tactic.DecRefQueue Tactic_DRQ () { return m_Tactic_DRQ; } - Fixedpoint.DecRefQueue Fixedpoint_DRQ () { return m_Fixedpoint_DRQ; } - - - long refCount = 0; - - /** - * Finalizer. - **/ - protected void finalize() - { - // Console.WriteLine("Context Finalizer from " + System.Threading.Thread.CurrentThread.ManagedThreadId); - Dispose(); - - if (refCount == 0) - { - m_n_err_handler = null; - Native.delContext(m_ctx); - m_ctx = IntPtr.Zero; - } - else - GC.ReRegisterForFinalize(this); - } - - /** - * Disposes of the context. - **/ - public void Dispose() - { - // Console.WriteLine("Context Dispose from " + System.Threading.Thread.CurrentThread.ManagedThreadId); - AST_DRQ.Clear(this); - ASTMap_DRQ.Clear(this); - ASTVector_DRQ.Clear(this); - ApplyResult_DRQ.Clear(this); - FuncEntry_DRQ.Clear(this); - FuncInterp_DRQ.Clear(this); - Goal_DRQ.Clear(this); - Model_DRQ.Clear(this); - Params_DRQ.Clear(this); - Probe_DRQ.Clear(this); - Solver_DRQ.Clear(this); - Statistics_DRQ.Clear(this); - Tactic_DRQ.Clear(this); - Fixedpoint_DRQ.Clear(this); - - m_booleanSort = null; - m_intSort = null; - m_realSort = null; - } - } diff --git a/src/api/java/com/Microsoft/Z3/DecRefQUeue.java b/src/api/java/com/Microsoft/Z3/DecRefQUeue.java deleted file mode 100644 index 279887a7c..000000000 --- a/src/api/java/com/Microsoft/Z3/DecRefQUeue.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * This file was automatically generated from DecRefQUeue.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ -/* using System.Collections; */ -/* using System.Collections.Generic; */ -/* using System.Threading; */ - - abstract class DecRefQueue - { - - private void ObjectInvariant() - { - - } - - - protected Object m_lock = new Object(); - protected List m_queue = new List(); - final long m_move_limit = 1024; - - public abstract void IncRef(Context ctx, IntPtr obj); - public abstract void DecRef(Context ctx, IntPtr obj); - - public void IncAndClear(Context ctx, IntPtr o) - { - - - IncRef(ctx, o); - if (m_queue.Count >= m_move_limit) Clear(ctx); - } - - public void Add(IntPtr o) - { - if (o == IntPtr.Zero) return; - - synchronized (m_lock) - { - m_queue.Add(o); - } - } - - public void Clear(Context ctx) - { - - - synchronized (m_lock) - { - for (IntPtr.Iterator o = m_queue.iterator(); o.hasNext(); ) - DecRef(ctx, o); - m_queue.Clear(); - } - } - } - - abstract class DecRefQueueContracts extends DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - - } - - public void DecRef(Context ctx, IntPtr obj) - { - - } - } diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_ast_kind.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_ast_kind.java deleted file mode 100644 index 2ba3f58ab..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_ast_kind.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_ast_kind - **/ -public enum Z3_ast_kind { -Z3_VAR_AST (2), -Z3_SORT_AST (4), -Z3_QUANTIFIER_AST (3), -Z3_UNKNOWN_AST (1000), -Z3_FUNC_DECL_AST (5), -Z3_NUMERAL_AST (0), -Z3_APP_AST (1), -} - diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_ast_print_mode.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_ast_print_mode.java deleted file mode 100644 index 4aa4a2716..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_ast_print_mode.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_ast_print_mode - **/ -public enum Z3_ast_print_mode { -Z3_PRINT_SMTLIB2_COMPLIANT (3), -Z3_PRINT_SMTLIB_COMPLIANT (2), -Z3_PRINT_SMTLIB_FULL (0), -Z3_PRINT_LOW_LEVEL (1), -} - diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_decl_kind.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_decl_kind.java deleted file mode 100644 index 3b0b01715..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_decl_kind.java +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_decl_kind - **/ -public enum Z3_decl_kind { -Z3_OP_LABEL (1792), -Z3_OP_PR_REWRITE (1294), -Z3_OP_UNINTERPRETED (2051), -Z3_OP_SUB (519), -Z3_OP_ZERO_EXT (1058), -Z3_OP_ADD (518), -Z3_OP_IS_INT (528), -Z3_OP_BREDOR (1061), -Z3_OP_BNOT (1051), -Z3_OP_BNOR (1054), -Z3_OP_PR_CNF_STAR (1315), -Z3_OP_RA_JOIN (1539), -Z3_OP_LE (514), -Z3_OP_SET_UNION (773), -Z3_OP_PR_UNDEF (1280), -Z3_OP_BREDAND (1062), -Z3_OP_LT (516), -Z3_OP_RA_UNION (1540), -Z3_OP_BADD (1028), -Z3_OP_BUREM0 (1039), -Z3_OP_OEQ (267), -Z3_OP_PR_MODUS_PONENS (1284), -Z3_OP_RA_CLONE (1548), -Z3_OP_REPEAT (1060), -Z3_OP_RA_NEGATION_FILTER (1544), -Z3_OP_BSMOD0 (1040), -Z3_OP_BLSHR (1065), -Z3_OP_BASHR (1066), -Z3_OP_PR_UNIT_RESOLUTION (1304), -Z3_OP_ROTATE_RIGHT (1068), -Z3_OP_ARRAY_DEFAULT (772), -Z3_OP_PR_PULL_QUANT (1296), -Z3_OP_PR_APPLY_DEF (1310), -Z3_OP_PR_REWRITE_STAR (1295), -Z3_OP_IDIV (523), -Z3_OP_PR_GOAL (1283), -Z3_OP_PR_IFF_TRUE (1305), -Z3_OP_LABEL_LIT (1793), -Z3_OP_BOR (1050), -Z3_OP_PR_SYMMETRY (1286), -Z3_OP_TRUE (256), -Z3_OP_SET_COMPLEMENT (776), -Z3_OP_CONCAT (1056), -Z3_OP_PR_NOT_OR_ELIM (1293), -Z3_OP_IFF (263), -Z3_OP_BSHL (1064), -Z3_OP_PR_TRANSITIVITY (1287), -Z3_OP_SGT (1048), -Z3_OP_RA_WIDEN (1541), -Z3_OP_PR_DEF_INTRO (1309), -Z3_OP_NOT (265), -Z3_OP_PR_QUANT_INTRO (1290), -Z3_OP_UGT (1047), -Z3_OP_DT_RECOGNISER (2049), -Z3_OP_SET_INTERSECT (774), -Z3_OP_BSREM (1033), -Z3_OP_RA_STORE (1536), -Z3_OP_SLT (1046), -Z3_OP_ROTATE_LEFT (1067), -Z3_OP_PR_NNF_NEG (1313), -Z3_OP_PR_REFLEXIVITY (1285), -Z3_OP_ULEQ (1041), -Z3_OP_BIT1 (1025), -Z3_OP_BIT0 (1026), -Z3_OP_EQ (258), -Z3_OP_BMUL (1030), -Z3_OP_ARRAY_MAP (771), -Z3_OP_STORE (768), -Z3_OP_PR_HYPOTHESIS (1302), -Z3_OP_RA_RENAME (1545), -Z3_OP_AND (261), -Z3_OP_TO_REAL (526), -Z3_OP_PR_NNF_POS (1312), -Z3_OP_PR_AND_ELIM (1292), -Z3_OP_MOD (525), -Z3_OP_BUDIV0 (1037), -Z3_OP_PR_TRUE (1281), -Z3_OP_BNAND (1053), -Z3_OP_PR_ELIM_UNUSED_VARS (1299), -Z3_OP_RA_FILTER (1543), -Z3_OP_FD_LT (1549), -Z3_OP_RA_EMPTY (1537), -Z3_OP_DIV (522), -Z3_OP_ANUM (512), -Z3_OP_MUL (521), -Z3_OP_UGEQ (1043), -Z3_OP_BSREM0 (1038), -Z3_OP_PR_TH_LEMMA (1318), -Z3_OP_BXOR (1052), -Z3_OP_DISTINCT (259), -Z3_OP_PR_IFF_FALSE (1306), -Z3_OP_BV2INT (1072), -Z3_OP_EXT_ROTATE_LEFT (1069), -Z3_OP_PR_PULL_QUANT_STAR (1297), -Z3_OP_BSUB (1029), -Z3_OP_PR_ASSERTED (1282), -Z3_OP_BXNOR (1055), -Z3_OP_EXTRACT (1059), -Z3_OP_PR_DER (1300), -Z3_OP_DT_CONSTRUCTOR (2048), -Z3_OP_GT (517), -Z3_OP_BUREM (1034), -Z3_OP_IMPLIES (266), -Z3_OP_SLEQ (1042), -Z3_OP_GE (515), -Z3_OP_BAND (1049), -Z3_OP_ITE (260), -Z3_OP_AS_ARRAY (778), -Z3_OP_RA_SELECT (1547), -Z3_OP_CONST_ARRAY (770), -Z3_OP_BSDIV (1031), -Z3_OP_OR (262), -Z3_OP_PR_HYPER_RESOLVE (1319), -Z3_OP_AGNUM (513), -Z3_OP_PR_PUSH_QUANT (1298), -Z3_OP_BSMOD (1035), -Z3_OP_PR_IFF_OEQ (1311), -Z3_OP_PR_LEMMA (1303), -Z3_OP_SET_SUBSET (777), -Z3_OP_SELECT (769), -Z3_OP_RA_PROJECT (1542), -Z3_OP_BNEG (1027), -Z3_OP_UMINUS (520), -Z3_OP_REM (524), -Z3_OP_TO_INT (527), -Z3_OP_PR_QUANT_INST (1301), -Z3_OP_SGEQ (1044), -Z3_OP_POWER (529), -Z3_OP_XOR3 (1074), -Z3_OP_RA_IS_EMPTY (1538), -Z3_OP_CARRY (1073), -Z3_OP_DT_ACCESSOR (2050), -Z3_OP_PR_TRANSITIVITY_STAR (1288), -Z3_OP_PR_NNF_STAR (1314), -Z3_OP_PR_COMMUTATIVITY (1307), -Z3_OP_ULT (1045), -Z3_OP_BSDIV0 (1036), -Z3_OP_SET_DIFFERENCE (775), -Z3_OP_INT2BV (1071), -Z3_OP_XOR (264), -Z3_OP_PR_MODUS_PONENS_OEQ (1317), -Z3_OP_BNUM (1024), -Z3_OP_BUDIV (1032), -Z3_OP_PR_MONOTONICITY (1289), -Z3_OP_PR_DEF_AXIOM (1308), -Z3_OP_FALSE (257), -Z3_OP_EXT_ROTATE_RIGHT (1070), -Z3_OP_PR_DISTRIBUTIVITY (1291), -Z3_OP_SIGN_EXT (1057), -Z3_OP_PR_SKOLEMIZE (1316), -Z3_OP_BCOMP (1063), -Z3_OP_RA_COMPLEMENT (1546), -} - diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_error_code.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_error_code.java deleted file mode 100644 index ef5fa6f2c..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_error_code.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_error_code - **/ -public enum Z3_error_code { -Z3_INVALID_PATTERN (6), -Z3_MEMOUT_FAIL (7), -Z3_NO_PARSER (5), -Z3_OK (0), -Z3_INVALID_ARG (3), -Z3_EXCEPTION (12), -Z3_IOB (2), -Z3_INTERNAL_FATAL (9), -Z3_INVALID_USAGE (10), -Z3_FILE_ACCESS_ERROR (8), -Z3_SORT_ERROR (1), -Z3_PARSER_ERROR (4), -Z3_DEC_REF_ERROR (11), -} - diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_goal_prec.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_goal_prec.java deleted file mode 100644 index 38e2fdf96..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_goal_prec.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_goal_prec - **/ -public enum Z3_goal_prec { -Z3_GOAL_UNDER (1), -Z3_GOAL_PRECISE (0), -Z3_GOAL_UNDER_OVER (3), -Z3_GOAL_OVER (2), -} - diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_lbool.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_lbool.java deleted file mode 100644 index 63ee2e227..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_lbool.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_lbool - **/ -public enum Z3_lbool { -Z3_L_TRUE (1), -Z3_L_UNDEF (0), -Z3_L_FALSE (-1), -} - diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_param_kind.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_param_kind.java deleted file mode 100644 index e3d8c0e77..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_param_kind.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_param_kind - **/ -public enum Z3_param_kind { -Z3_PK_BOOL (1), -Z3_PK_SYMBOL (3), -Z3_PK_OTHER (5), -Z3_PK_INVALID (6), -Z3_PK_UINT (0), -Z3_PK_STRING (4), -Z3_PK_DOUBLE (2), -} - diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_parameter_kind.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_parameter_kind.java deleted file mode 100644 index 0de56c3cd..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_parameter_kind.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_parameter_kind - **/ -public enum Z3_parameter_kind { -Z3_PARAMETER_FUNC_DECL (6), -Z3_PARAMETER_DOUBLE (1), -Z3_PARAMETER_SYMBOL (3), -Z3_PARAMETER_INT (0), -Z3_PARAMETER_AST (5), -Z3_PARAMETER_SORT (4), -Z3_PARAMETER_RATIONAL (2), -} - diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_sort_kind.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_sort_kind.java deleted file mode 100644 index 59a69b4c0..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_sort_kind.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_sort_kind - **/ -public enum Z3_sort_kind { -Z3_BV_SORT (4), -Z3_FINITE_DOMAIN_SORT (8), -Z3_ARRAY_SORT (5), -Z3_UNKNOWN_SORT (1000), -Z3_RELATION_SORT (7), -Z3_REAL_SORT (3), -Z3_INT_SORT (2), -Z3_UNINTERPRETED_SORT (0), -Z3_BOOL_SORT (1), -Z3_DATATYPE_SORT (6), -} - diff --git a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_symbol_kind.java b/src/api/java/com/Microsoft/Z3/Enumerations/Z3_symbol_kind.java deleted file mode 100644 index efe5804eb..000000000 --- a/src/api/java/com/Microsoft/Z3/Enumerations/Z3_symbol_kind.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Automatically generated file - **/ - -package com.Microsoft.Z3; - -/** - * Z3_symbol_kind - **/ -public enum Z3_symbol_kind { -Z3_INT_SYMBOL (0), -Z3_STRING_SYMBOL (1), -} - diff --git a/src/api/java/com/Microsoft/Z3/Expr.java b/src/api/java/com/Microsoft/Z3/Expr.java deleted file mode 100644 index 760fe813d..000000000 --- a/src/api/java/com/Microsoft/Z3/Expr.java +++ /dev/null @@ -1,1554 +0,0 @@ -/** - * This file was automatically generated from Expr.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Expressions are terms. - **/ - public class Expr extends AST - { - /** - * Returns a simplified version of the expression. - * A set of parameters to configure the simplifier - * - **/ - public Expr Simplify(Params p) - { - - - if (p == null) - return Expr.Create(Context, Native.simplify(Context.nCtx, NativeObject)); - else - return Expr.Create(Context, Native.simplifyEx(Context.nCtx, NativeObject, p.NativeObject)); - } - - /** - * The function declaration of the function that is applied in this expression. - **/ - public FuncDecl FuncDecl() - { - - return new FuncDecl(Context, Native.getAppDecl(Context.nCtx, NativeObject)); - } - - /** - * Indicates whether the expression is the true or false expression - * or something else (Z3_L_UNDEF). - **/ - public Z3_lboolean BoolValue() { return (Z3_lboolean)Native.getBooleanValue(Context.nCtx, NativeObject); } - - /** - * The number of arguments of the expression. - **/ - public long NumArgs() { return Native.getAppNumArgs(Context.nCtx, NativeObject); } - - /** - * The arguments of the expression. - **/ - public Expr[] Args() - { - - - long n = NumArgs; - Expr[] res = new Expr[n]; - for (long i = 0; i < n; i++) - res[i] = Expr.Create(Context, Native.getAppArg(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * Update the arguments of the expression using the arguments - * The number of new arguments should coincide with the current number of arguments. - **/ - public void Update(Expr[] args) - { - - - - Context.CheckContextMatch(args); - if (args.Length != NumArgs) - throw new Z3Exception("Number of arguments does not match"); - NativeObject = Native.updateTerm(Context.nCtx, NativeObject, (long)args.Length, Expr.ArrayToNative(args)); - } - - /** - * Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs. - * - * The result is the new expression. The arrays from and to must have size num_exprs. - * For every i smaller than num_exprs, we must have that - * sort of from[i] must be equal to sort of to[i]. - * - **/ - public Expr Substitute(Expr[] from, Expr[] to) - { - - - - - - - Context.CheckContextMatch(from); - Context.CheckContextMatch(to); - if (from.Length != to.Length) - throw new Z3Exception("Argument sizes do not match"); - return Expr.Create(Context, Native.substitute(Context.nCtx, NativeObject, (long)from.Length, Expr.ArrayToNative(from), Expr.ArrayToNative(to))); - } - - /** - * Substitute every occurrence of from in the expression with to. - * - **/ - public Expr Substitute(Expr from, Expr to) - { - - - - - return Substitute(new Expr[] { from }, new Expr[] { to }); - } - - /** - * Substitute the free variables in the expression with the expressions in - * - * For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. - * - **/ - public Expr SubstituteVars(Expr[] to) - { - - - - - Context.CheckContextMatch(to); - return Expr.Create(Context, Native.substituteVars(Context.nCtx, NativeObject, (long)to.Length, Expr.ArrayToNative(to))); - } - - /** - * Translates (copies) the term to the Context . - * A context - * @return A copy of the term which is associated with - **/ - public Expr Translate(Context ctx) - { - - - - if (ReferenceEquals(Context, ctx)) - return this; - else - return Expr.Create(ctx, Native.translate(Context.nCtx, NativeObject, ctx.nCtx)); - } - - /** - * Returns a string representation of the expression. - **/ - public String toString() - { - return super.toString(); - } - - /** - * Indicates whether the term is a numeral - **/ - public boolean IsNumeral() { return Native.isNumeralAst(Context.nCtx, NativeObject) != 0; } - - /** - * Indicates whether the term is well-sorted. - * @return True if the term is well-sorted, false otherwise. - **/ - public boolean IsWellSorted() { return Native.isWellSorted(Context.nCtx, NativeObject) != 0; } - - /** - * The Sort of the term. - **/ - public Sort Sort() - { - - return Sort.Create(Context, Native.getSort(Context.nCtx, NativeObject)); - } - - /** - * Indicates whether the term represents a constant. - **/ - public boolean IsConst() { return IsExpr && NumArgs == 0 && FuncDecl.DomainSize == 0; } - - /** - * Indicates whether the term is an integer numeral. - **/ - public boolean IsIntNum() { return IsNumeral && IsInt; } - - /** - * Indicates whether the term is a real numeral. - **/ - public boolean IsRatNum() { return IsNumeral && IsReal; } - - /** - * Indicates whether the term is an algebraic number - **/ - public boolean IsAlgebraicNumber() { return Native.isAlgebraicNumber(Context.nCtx, NativeObject) != 0; } - - - /** - * Indicates whether the term has Boolean sort. - **/ - public boolean IsBool() - { - return (IsExpr && - Native.isEqSort(Context.nCtx, - Native.mkBooleanSort(Context.nCtx), - Native.getSort(Context.nCtx, NativeObject)) != 0); - } - - /** - * Indicates whether the term is the constant true. - **/ - public boolean IsTrue() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_TRUE; } - - /** - * Indicates whether the term is the constant false. - **/ - public boolean IsFalse() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FALSE; } - - /** - * Indicates whether the term is an equality predicate. - **/ - public boolean IsEq() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_EQ; } - - /** - * Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). - **/ - public boolean IsDistinct() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_DISTINCT; } - - /** - * Indicates whether the term is a ternary if-then-else term - **/ - public boolean IsITE() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ITE; } - - /** - * Indicates whether the term is an n-ary conjunction - **/ - public boolean IsAnd() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_AND; } - - /** - * Indicates whether the term is an n-ary disjunction - **/ - public boolean IsOr() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_OR; } - - /** - * Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) - **/ - public boolean IsIff() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_IFF; } - - /** - * Indicates whether the term is an exclusive or - **/ - public boolean IsXor() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_XOR; } - - /** - * Indicates whether the term is a negation - **/ - public boolean IsNot() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_NOT; } - - /** - * Indicates whether the term is an implication - **/ - public boolean IsImplies() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_IMPLIES; } - - /** - * Indicates whether the term is of integer sort. - **/ - public boolean IsInt() - { - return (Native.isNumeralAst(Context.nCtx, NativeObject) != 0 && - Native.getSortKind(Context.nCtx, Native.getSort(Context.nCtx, NativeObject)) == (long)Z3_sort_kind.Z3_INT_SORT); - } - - /** - * Indicates whether the term is of sort real. - **/ - public boolean IsReal() { return Native.getSortKind(Context.nCtx, Native.getSort(Context.nCtx, NativeObject)) == (long)Z3_sort_kind.Z3_REAL_SORT; } - - /** - * Indicates whether the term is an arithmetic numeral. - **/ - public boolean IsArithmeticNumeral() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ANUM; } - - /** - * Indicates whether the term is a less-than-or-equal - **/ - public boolean IsLE() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_LE; } - - /** - * Indicates whether the term is a greater-than-or-equal - **/ - public boolean IsGE() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_GE; } - - /** - * Indicates whether the term is a less-than - **/ - public boolean IsLT() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_LT; } - - /** - * Indicates whether the term is a greater-than - **/ - public boolean IsGT() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_GT; } - - /** - * Indicates whether the term is addition (binary) - **/ - public boolean IsAdd() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ADD; } - - /** - * Indicates whether the term is subtraction (binary) - **/ - public boolean IsSub() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SUB; } - - /** - * Indicates whether the term is a unary minus - **/ - public boolean IsUMinus() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_UMINUS; } - - /** - * Indicates whether the term is multiplication (binary) - **/ - public boolean IsMul() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_MUL; } - - /** - * Indicates whether the term is division (binary) - **/ - public boolean IsDiv() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_DIV; } - - /** - * Indicates whether the term is integer division (binary) - **/ - public boolean IsIDiv() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_IDIV; } - - /** - * Indicates whether the term is remainder (binary) - **/ - public boolean IsRemainder() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_REM; } - - /** - * Indicates whether the term is modulus (binary) - **/ - public boolean IsModulus() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_MOD; } - - /** - * Indicates whether the term is a coercion of integer to real (unary) - **/ - public boolean IsIntToReal() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_TO_REAL; } - - /** - * Indicates whether the term is a coercion of real to integer (unary) - **/ - public boolean IsRealToInt() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_TO_INT; } - - /** - * Indicates whether the term is a check that tests whether a real is integral (unary) - **/ - public boolean IsRealIsInt() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_IS_INT; } - - /** - * Indicates whether the term is of an array sort. - **/ - public boolean IsArray() - { - return (Native.isApp(Context.nCtx, NativeObject) != 0 && - (Z3_sort_kind)Native.getSortKind(Context.nCtx, Native.getSort(Context.nCtx, NativeObject)) == Z3_sort_kind.Z3_ARRAY_SORT); - } - - /** - * Indicates whether the term is an array store. - * It satisfies select(store(a,i,v),j) = if i = j then v else select(a,j). - * Array store takes at least 3 arguments. - **/ - public boolean IsStore() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_STORE; } - - /** - * Indicates whether the term is an array select. - **/ - public boolean IsSelect() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SELECT; } - - /** - * Indicates whether the term is a constant array. - * For example, select(const(v),i) = v holds for every v and i. The function is unary. - **/ - public boolean IsConstantArray() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_CONST_ARRAY; } - - /** - * Indicates whether the term is a default array. - * For example default(const(v)) = v. The function is unary. - **/ - public boolean IsDefaultArray() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ARRAY_DEFAULT; } - - /** - * Indicates whether the term is an array map. - * It satisfies map[f](a1,..,a_n)[i] = f(a1[i],...,a_n[i]) for every i. - **/ - public boolean IsArrayMap() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ARRAY_MAP; } - - /** - * Indicates whether the term is an as-array term. - * An as-array term is n array value that behaves as the function graph of the - * function passed as parameter. - **/ - public boolean IsAsArray() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_AS_ARRAY; } - - /** - * Indicates whether the term is set union - **/ - public boolean IsSetUnion() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SET_UNION; } - - /** - * Indicates whether the term is set intersection - **/ - public boolean IsSetIntersect() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SET_INTERSECT; } - - /** - * Indicates whether the term is set difference - **/ - public boolean IsSetDifference() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SET_DIFFERENCE; } - - /** - * Indicates whether the term is set complement - **/ - public boolean IsSetComplement() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SET_COMPLEMENT; } - - /** - * Indicates whether the term is set subset - **/ - public boolean IsSetSubset() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SET_SUBSET; } - - /** - * Indicates whether the terms is of bit-vector sort. - **/ - public boolean IsBV() { return Native.getSortKind(Context.nCtx, Native.getSort(Context.nCtx, NativeObject)) == (long)Z3_sort_kind.Z3_BV_SORT; } - - /** - * Indicates whether the term is a bit-vector numeral - **/ - public boolean IsBVNumeral() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BNUM; } - - /** - * Indicates whether the term is a one-bit bit-vector with value one - **/ - public boolean IsBVBitOne() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BIT1; } - - /** - * Indicates whether the term is a one-bit bit-vector with value zero - **/ - public boolean IsBVBitZero() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BIT0; } - - /** - * Indicates whether the term is a bit-vector unary minus - **/ - public boolean IsBVUMinus() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BNEG; } - - /** - * Indicates whether the term is a bit-vector addition (binary) - **/ - public boolean IsBVAdd() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BADD; } - - /** - * Indicates whether the term is a bit-vector subtraction (binary) - **/ - public boolean IsBVSub() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BSUB; } - - /** - * Indicates whether the term is a bit-vector multiplication (binary) - **/ - public boolean IsBVMul() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BMUL; } - - /** - * Indicates whether the term is a bit-vector signed division (binary) - **/ - public boolean IsBVSDiv() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BSDIV; } - - /** - * Indicates whether the term is a bit-vector unsigned division (binary) - **/ - public boolean IsBVUDiv() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BUDIV; } - - /** - * Indicates whether the term is a bit-vector signed remainder (binary) - **/ - public boolean IsBVSRem() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BSREM; } - - /** - * Indicates whether the term is a bit-vector unsigned remainder (binary) - **/ - public boolean IsBVURem() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BUREM; } - - /** - * Indicates whether the term is a bit-vector signed modulus - **/ - public boolean IsBVSMod() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BSMOD; } - - /** - * Indicates whether the term is a bit-vector signed division by zero - **/ - boolean IsBVSDiv0 () { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BSDIV0; } - - /** - * Indicates whether the term is a bit-vector unsigned division by zero - **/ - boolean IsBVUDiv0 () { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BUDIV0; } - - /** - * Indicates whether the term is a bit-vector signed remainder by zero - **/ - boolean IsBVSRem0 () { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BSREM0; } - - /** - * Indicates whether the term is a bit-vector unsigned remainder by zero - **/ - boolean IsBVURem0 () { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BUREM0; } - - /** - * Indicates whether the term is a bit-vector signed modulus by zero - **/ - boolean IsBVSMod0 () { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BSMOD0; } - - /** - * Indicates whether the term is an unsigned bit-vector less-than-or-equal - **/ - public boolean IsBVULE() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ULEQ; } - - /** - * Indicates whether the term is a signed bit-vector less-than-or-equal - **/ - public boolean IsBVSLE() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SLEQ; } - - /** - * Indicates whether the term is an unsigned bit-vector greater-than-or-equal - **/ - public boolean IsBVUGE() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_UGEQ; } - - /** - * Indicates whether the term is a signed bit-vector greater-than-or-equal - **/ - public boolean IsBVSGE() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SGEQ; } - - /** - * Indicates whether the term is an unsigned bit-vector less-than - **/ - public boolean IsBVULT() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ULT; } - - /** - * Indicates whether the term is a signed bit-vector less-than - **/ - public boolean IsBVSLT() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SLT; } - - /** - * Indicates whether the term is an unsigned bit-vector greater-than - **/ - public boolean IsBVUGT() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_UGT; } - - /** - * Indicates whether the term is a signed bit-vector greater-than - **/ - public boolean IsBVSGT() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SGT; } - - /** - * Indicates whether the term is a bit-wise AND - **/ - public boolean IsBVAND() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BAND; } - - /** - * Indicates whether the term is a bit-wise OR - **/ - public boolean IsBVOR() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BOR; } - - /** - * Indicates whether the term is a bit-wise NOT - **/ - public boolean IsBVNOT() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BNOT; } - - /** - * Indicates whether the term is a bit-wise XOR - **/ - public boolean IsBVXOR() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BXOR; } - - /** - * Indicates whether the term is a bit-wise NAND - **/ - public boolean IsBVNAND() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BNAND; } - - /** - * Indicates whether the term is a bit-wise NOR - **/ - public boolean IsBVNOR() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BNOR; } - - /** - * Indicates whether the term is a bit-wise XNOR - **/ - public boolean IsBVXNOR() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BXNOR; } - - /** - * Indicates whether the term is a bit-vector concatenation (binary) - **/ - public boolean IsBVConcat() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_CONCAT; } - - /** - * Indicates whether the term is a bit-vector sign extension - **/ - public boolean IsBVSignExtension() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SIGN_EXT; } - - /** - * Indicates whether the term is a bit-vector zero extension - **/ - public boolean IsBVZeroExtension() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ZERO_EXT; } - - /** - * Indicates whether the term is a bit-vector extraction - **/ - public boolean IsBVExtract() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_EXTRACT; } - - /** - * Indicates whether the term is a bit-vector repetition - **/ - public boolean IsBVRepeat() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_REPEAT; } - - /** - * Indicates whether the term is a bit-vector reduce OR - **/ - public boolean IsBVReduceOR() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BREDOR; } - - /** - * Indicates whether the term is a bit-vector reduce AND - **/ - public boolean IsBVReduceAND() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BREDAND; } - - /** - * Indicates whether the term is a bit-vector comparison - **/ - public boolean IsBVComp() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BCOMP; } - - /** - * Indicates whether the term is a bit-vector shift left - **/ - public boolean IsBVShiftLeft() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BSHL; } - - /** - * Indicates whether the term is a bit-vector logical shift right - **/ - public boolean IsBVShiftRightLogical() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BLSHR; } - - /** - * Indicates whether the term is a bit-vector arithmetic shift left - **/ - public boolean IsBVShiftRightArithmetic() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BASHR; } - - /** - * Indicates whether the term is a bit-vector rotate left - **/ - public boolean IsBVRotateLeft() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ROTATE_LEFT; } - - /** - * Indicates whether the term is a bit-vector rotate right - **/ - public boolean IsBVRotateRight() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_ROTATE_RIGHT; } - - /** - * Indicates whether the term is a bit-vector rotate left (extended) - * Similar to Z3_OP_ROTATE_LEFT, but it is a binary operator instead of a parametric one. - **/ - public boolean IsBVRotateLeftExtended() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_EXT_ROTATE_LEFT; } - - /** - * Indicates whether the term is a bit-vector rotate right (extended) - * Similar to Z3_OP_ROTATE_RIGHT, but it is a binary operator instead of a parametric one. - **/ - public boolean IsBVRotateRightExtended() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_EXT_ROTATE_RIGHT; } - - /** - * Indicates whether the term is a coercion from integer to bit-vector - * This function is not supported by the decision procedures. Only the most - * rudimentary simplification rules are applied to this function. - **/ - public boolean IsIntToBV() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_INT2BV; } - - /** - * Indicates whether the term is a coercion from bit-vector to integer - * This function is not supported by the decision procedures. Only the most - * rudimentary simplification rules are applied to this function. - **/ - public boolean IsBVToInt() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_BV2INT; } - - /** - * Indicates whether the term is a bit-vector carry - * Compute the carry bit in a full-adder. The meaning is given by the - * equivalence (carry l1 l2 l3) <=> (or (and l1 l2) (and l1 l3) (and l2 l3))) - **/ - public boolean IsBVCarry() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_CARRY; } - - /** - * Indicates whether the term is a bit-vector ternary XOR - * The meaning is given by the equivalence (xor3 l1 l2 l3) <=> (xor (xor l1 l2) l3) - **/ - public boolean IsBVXOR3() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_XOR3; } - - - /** - * Indicates whether the term is a label (used by the Boogie Verification condition generator). - * The label has two parameters, a string and a Boolean polarity. It takes one argument, a formula. - **/ - public boolean IsLabel() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_LABEL; } - - /** - * Indicates whether the term is a label literal (used by the Boogie Verification condition generator). - * A label literal has a set of string parameters. It takes no arguments. - **/ - public boolean IsLabelLit() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_LABEL_LIT; } - - /** - * Indicates whether the term is a binary equivalence modulo namings. - * This binary predicate is used in proof terms. - * It captures equisatisfiability and equivalence modulo renamings. - **/ - public boolean IsOEQ() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_OEQ; } - - /** - * Indicates whether the term is a Proof for the expression 'true'. - **/ - public boolean IsProofTrue() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_TRUE; } - - /** - * Indicates whether the term is a proof for a fact asserted by the user. - **/ - public boolean IsProofAsserted() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_ASSERTED; } - - /** - * Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. - **/ - public boolean IsProofGoal() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_GOAL; } - - /** - * Indicates whether the term is proof via modus ponens - * - * Given a proof for p and a proof for (implies p q), produces a proof for q. - * T1: p - * T2: (implies p q) - * [mp T1 T2]: q - * The second antecedents may also be a proof for (iff p q). - **/ - public boolean IsProofModusPonens() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_MODUS_PONENS; } - - /** - * Indicates whether the term is a proof for (R t t), where R is a reflexive relation. - * This proof object has no antecedents. - * The only reflexive relations that are used are - * equivalence modulo namings, equality and equivalence. - * That is, R is either '~', '=' or 'iff'. - **/ - public boolean IsProofReflexivity() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_REFLEXIVITY; } - - /** - * Indicates whether the term is proof by symmetricity of a relation - * - * Given an symmetric relation R and a proof for (R t s), produces a proof for (R s t). - * T1: (R t s) - * [symmetry T1]: (R s t) - * T1 is the antecedent of this proof object. - * - **/ - public boolean IsProofSymmetry() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_SYMMETRY; } - - /** - * Indicates whether the term is a proof by transitivity of a relation - * - * Given a transitive relation R, and proofs for (R t s) and (R s u), produces a proof - * for (R t u). - * T1: (R t s) - * T2: (R s u) - * [trans T1 T2]: (R t u) - * - **/ - public boolean IsProofTransitivity() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_TRANSITIVITY; } - - /** - * Indicates whether the term is a proof by condensed transitivity of a relation - * - * Condensed transitivity proof. This proof object is only used if the parameter PROOF_MODE is 1. - * It combines several symmetry and transitivity proofs. - * Example: - * T1: (R a b) - * T2: (R c b) - * T3: (R c d) - * [trans* T1 T2 T3]: (R a d) - * R must be a symmetric and transitive relation. - * - * Assuming that this proof object is a proof for (R s t), then - * a proof checker must check if it is possible to prove (R s t) - * using the antecedents, symmetry and transitivity. That is, - * if there is a path from s to t, if we view every - * antecedent (R a b) as an edge between a and b. - * - **/ - public boolean IsProofTransitivityStar() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_TRANSITIVITY_STAR; } - - - /** - * Indicates whether the term is a monotonicity proof object. - * - * T1: (R t_1 s_1) - * ... - * Tn: (R t_n s_n) - * [monotonicity T1 ... Tn]: (R (f t_1 ... t_n) (f s_1 ... s_n)) - * Remark: if t_i == s_i, then the antecedent Ti is suppressed. - * That is, reflexivity proofs are supressed to save space. - * - **/ - public boolean IsProofMonotonicity() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_MONOTONICITY; } - - /** - * Indicates whether the term is a quant-intro proof - * - * Given a proof for (~ p q), produces a proof for (~ (forall (x) p) (forall (x) q)). - * T1: (~ p q) - * [quant-intro T1]: (~ (forall (x) p) (forall (x) q)) - * - **/ - public boolean IsProofQuantIntro() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_QUANT_INTRO; } - - /** - * Indicates whether the term is a distributivity proof object. - * - * Given that f (= or) distributes over g (= and), produces a proof for - * (= (f a (g c d)) - * (g (f a c) (f a d))) - * If f and g are associative, this proof also justifies the following equality: - * (= (f (g a b) (g c d)) - * (g (f a c) (f a d) (f b c) (f b d))) - * where each f and g can have arbitrary number of arguments. - * - * This proof object has no antecedents. - * Remark. This rule is used by the CNF conversion pass and - * instantiated by f = or, and g = and. - * - **/ - public boolean IsProofDistributivity() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_DISTRIBUTIVITY; } - - /** - * Indicates whether the term is a proof by elimination of AND - * - * Given a proof for (and l_1 ... l_n), produces a proof for l_i - * T1: (and l_1 ... l_n) - * [and-elim T1]: l_i - * - **/ - public boolean IsProofAndElimination() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_AND_ELIM; } - - /** - * Indicates whether the term is a proof by eliminiation of not-or - * - * Given a proof for (not (or l_1 ... l_n)), produces a proof for (not l_i). - * T1: (not (or l_1 ... l_n)) - * [not-or-elim T1]: (not l_i) - * - **/ - public boolean IsProofOrElimination() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_NOT_OR_ELIM; } - - /** - * Indicates whether the term is a proof by rewriting - * - * A proof for a local rewriting step (= t s). - * The head function symbol of t is interpreted. - * - * This proof object has no antecedents. - * The conclusion of a rewrite rule is either an equality (= t s), - * an equivalence (iff t s), or equi-satisfiability (~ t s). - * Remark: if f is bool, then = is iff. - * - * Examples: - * (= (+ x 0) x) - * (= (+ x 1 2) (+ 3 x)) - * (iff (or x false) x) - * - **/ - public boolean IsProofRewrite() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_REWRITE; } - - /** - * Indicates whether the term is a proof by rewriting - * - * A proof for rewriting an expression t into an expression s. - * This proof object is used if the parameter PROOF_MODE is 1. - * This proof object can have n antecedents. - * The antecedents are proofs for equalities used as substitution rules. - * The object is also used in a few cases if the parameter PROOF_MODE is 2. - * The cases are: - * - When applying contextual simplification (CONTEXT_SIMPLIFIER=true) - * - When converting bit-vectors to Booleans (BIT2BOOL=true) - * - When pulling ite expression up (PULL_CHEAP_ITE_TREES=true) - * - **/ - public boolean IsProofRewriteStar() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_REWRITE_STAR; } - - /** - * Indicates whether the term is a proof for pulling quantifiers out. - * - * A proof for (iff (f (forall (x) q(x)) r) (forall (x) (f (q x) r))). This proof object has no antecedents. - * - **/ - public boolean IsProofPullQuant() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_PULL_QUANT; } - - /** - * Indicates whether the term is a proof for pulling quantifiers out. - * - * A proof for (iff P Q) where Q is in prenex normal form. - * This proof object is only used if the parameter PROOF_MODE is 1. - * This proof object has no antecedents - * - **/ - public boolean IsProofPullQuantStar() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_PULL_QUANT_STAR; } - - /** - * Indicates whether the term is a proof for pushing quantifiers in. - * - * A proof for: - * (iff (forall (x_1 ... x_m) (and p_1[x_1 ... x_m] ... p_n[x_1 ... x_m])) - * (and (forall (x_1 ... x_m) p_1[x_1 ... x_m]) - * ... - * (forall (x_1 ... x_m) p_n[x_1 ... x_m]))) - * This proof object has no antecedents - * - **/ - public boolean IsProofPushQuant() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_PUSH_QUANT; } - - /** - * Indicates whether the term is a proof for elimination of unused variables. - * - * A proof for (iff (forall (x_1 ... x_n y_1 ... y_m) p[x_1 ... x_n]) - * (forall (x_1 ... x_n) p[x_1 ... x_n])) - * - * It is used to justify the elimination of unused variables. - * This proof object has no antecedents. - * - **/ - public boolean IsProofElimUnusedVars() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_ELIM_UNUSED_VARS; } - - /** - * Indicates whether the term is a proof for destructive equality resolution - * - * A proof for destructive equality resolution: - * (iff (forall (x) (or (not (= x t)) P[x])) P[t]) - * if x does not occur in t. - * - * This proof object has no antecedents. - * - * Several variables can be eliminated simultaneously. - * - **/ - public boolean IsProofDER() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_DER; } - - /** - * Indicates whether the term is a proof for quantifier instantiation - * - * A proof of (or (not (forall (x) (P x))) (P a)) - * - **/ - public boolean IsProofQuantInst() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_QUANT_INST; } - - /** - * Indicates whether the term is a hypthesis marker. - * Mark a hypothesis in a natural deduction style proof. - **/ - public boolean IsProofHypothesis() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_HYPOTHESIS; } - - /** - * Indicates whether the term is a proof by lemma - * - * T1: false - * [lemma T1]: (or (not l_1) ... (not l_n)) - * - * This proof object has one antecedent: a hypothetical proof for false. - * It converts the proof in a proof for (or (not l_1) ... (not l_n)), - * when T1 contains the hypotheses: l_1, ..., l_n. - * - **/ - public boolean IsProofLemma() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_LEMMA; } - - /** - * Indicates whether the term is a proof by unit resolution - * - * T1: (or l_1 ... l_n l_1' ... l_m') - * T2: (not l_1) - * ... - * T(n+1): (not l_n) - * [unit-resolution T1 ... T(n+1)]: (or l_1' ... l_m') - * - **/ - public boolean IsProofUnitResolution() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_UNIT_RESOLUTION; } - - /** - * Indicates whether the term is a proof by iff-true - * - * T1: p - * [iff-true T1]: (iff p true) - * - **/ - public boolean IsProofIFFTrue() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_IFF_TRUE; } - - /** - * Indicates whether the term is a proof by iff-false - * - * T1: (not p) - * [iff-false T1]: (iff p false) - * - **/ - public boolean IsProofIFFFalse() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_IFF_FALSE; } - - /** - * Indicates whether the term is a proof by commutativity - * - * [comm]: (= (f a b) (f b a)) - * - * f is a commutative operator. - * - * This proof object has no antecedents. - * Remark: if f is bool, then = is iff. - * - **/ - public boolean IsProofCommutativity() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_COMMUTATIVITY; } - - /** - * Indicates whether the term is a proof for Tseitin-like axioms - * - * Proof object used to justify Tseitin's like axioms: - * - * (or (not (and p q)) p) - * (or (not (and p q)) q) - * (or (not (and p q r)) p) - * (or (not (and p q r)) q) - * (or (not (and p q r)) r) - * ... - * (or (and p q) (not p) (not q)) - * (or (not (or p q)) p q) - * (or (or p q) (not p)) - * (or (or p q) (not q)) - * (or (not (iff p q)) (not p) q) - * (or (not (iff p q)) p (not q)) - * (or (iff p q) (not p) (not q)) - * (or (iff p q) p q) - * (or (not (ite a b c)) (not a) b) - * (or (not (ite a b c)) a c) - * (or (ite a b c) (not a) (not b)) - * (or (ite a b c) a (not c)) - * (or (not (not a)) (not a)) - * (or (not a) a) - * - * This proof object has no antecedents. - * Note: all axioms are propositional tautologies. - * Note also that 'and' and 'or' can take multiple arguments. - * You can recover the propositional tautologies by - * unfolding the Boolean connectives in the axioms a small - * bounded number of steps (=3). - * - **/ - public boolean IsProofDefAxiom() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_DEF_AXIOM; } - - /** - * Indicates whether the term is a proof for introduction of a name - * - * Introduces a name for a formula/term. - * Suppose e is an expression with free variables x, and def-intro - * introduces the name n(x). The possible cases are: - * - * When e is of Boolean type: - * [def-intro]: (and (or n (not e)) (or (not n) e)) - * - * or: - * [def-intro]: (or (not n) e) - * when e only occurs positively. - * - * When e is of the form (ite cond th el): - * [def-intro]: (and (or (not cond) (= n th)) (or cond (= n el))) - * - * Otherwise: - * [def-intro]: (= n e) - * - **/ - public boolean IsProofDefIntro() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_DEF_INTRO; } - - /** - * Indicates whether the term is a proof for application of a definition - * - * [apply-def T1]: F ~ n - * F is 'equivalent' to n, given that T1 is a proof that - * n is a name for F. - * - **/ - public boolean IsProofApplyDef() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_APPLY_DEF; } - - /** - * Indicates whether the term is a proof iff-oeq - * - * T1: (iff p q) - * [iff~ T1]: (~ p q) - * - **/ - public boolean IsProofIFFOEQ() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_IFF_OEQ; } - - /** - * Indicates whether the term is a proof for a positive NNF step - * - * Proof for a (positive) NNF step. Example: - * - * T1: (not s_1) ~ r_1 - * T2: (not s_2) ~ r_2 - * T3: s_1 ~ r_1' - * T4: s_2 ~ r_2' - * [nnf-pos T1 T2 T3 T4]: (~ (iff s_1 s_2) - * (and (or r_1 r_2') (or r_1' r_2))) - * - * The negation normal form steps NNF_POS and NNF_NEG are used in the following cases: - * (a) When creating the NNF of a positive force quantifier. - * The quantifier is retained (unless the bound variables are eliminated). - * Example - * T1: q ~ q_new - * [nnf-pos T1]: (~ (forall (x T) q) (forall (x T) q_new)) - * - * (b) When recursively creating NNF over Boolean formulas, where the top-level - * connective is changed during NNF conversion. The relevant Boolean connectives - * for NNF_POS are 'implies', 'iff', 'xor', 'ite'. - * NNF_NEG furthermore handles the case where negation is pushed - * over Boolean connectives 'and' and 'or'. - * - **/ - public boolean IsProofNNFPos() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_NNF_POS; } - - /** - * Indicates whether the term is a proof for a negative NNF step - * - * Proof for a (negative) NNF step. Examples: - * - * T1: (not s_1) ~ r_1 - * ... - * Tn: (not s_n) ~ r_n - * [nnf-neg T1 ... Tn]: (not (and s_1 ... s_n)) ~ (or r_1 ... r_n) - * and - * T1: (not s_1) ~ r_1 - * ... - * Tn: (not s_n) ~ r_n - * [nnf-neg T1 ... Tn]: (not (or s_1 ... s_n)) ~ (and r_1 ... r_n) - * and - * T1: (not s_1) ~ r_1 - * T2: (not s_2) ~ r_2 - * T3: s_1 ~ r_1' - * T4: s_2 ~ r_2' - * [nnf-neg T1 T2 T3 T4]: (~ (not (iff s_1 s_2)) - * (and (or r_1 r_2) (or r_1' r_2'))) - * - **/ - public boolean IsProofNNFNeg() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_NNF_NEG; } - - /** - * Indicates whether the term is a proof for (~ P Q) here Q is in negation normal form. - * - * A proof for (~ P Q) where Q is in negation normal form. - * - * This proof object is only used if the parameter PROOF_MODE is 1. - * - * This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO. - * - **/ - public boolean IsProofNNFStar() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_NNF_STAR; } - - /** - * Indicates whether the term is a proof for (~ P Q) where Q is in conjunctive normal form. - * - * A proof for (~ P Q) where Q is in conjunctive normal form. - * This proof object is only used if the parameter PROOF_MODE is 1. - * This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO. - * - **/ - public boolean IsProofCNFStar() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_CNF_STAR; } - - /** - * Indicates whether the term is a proof for a Skolemization step - * - * Proof for: - * - * [sk]: (~ (not (forall x (p x y))) (not (p (sk y) y))) - * [sk]: (~ (exists x (p x y)) (p (sk y) y)) - * - * This proof object has no antecedents. - * - **/ - public boolean IsProofSkolemize() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_SKOLEMIZE; } - - /** - * Indicates whether the term is a proof by modus ponens for equi-satisfiability. - * - * Modus ponens style rule for equi-satisfiability. - * T1: p - * T2: (~ p q) - * [mp~ T1 T2]: q - * - **/ - public boolean IsProofModusPonensOEQ() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_MODUS_PONENS_OEQ; } - - /** - * Indicates whether the term is a proof for theory lemma - * - * Generic proof for theory lemmas. - * - * The theory lemma function comes with one or more parameters. - * The first parameter indicates the name of the theory. - * For the theory of arithmetic, additional parameters provide hints for - * checking the theory lemma. - * The hints for arithmetic are: - * - farkas - followed by rational coefficients. Multiply the coefficients to the - * inequalities in the lemma, add the (negated) inequalities and obtain a contradiction. - * - triangle-eq - Indicates a lemma related to the equivalence: - * (iff (= t1 t2) (and (<= t1 t2) (<= t2 t1))) - * - gcd-test - Indicates an integer linear arithmetic lemma that uses a gcd test. - * - **/ - public boolean IsProofTheoryLemma() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_TH_LEMMA; } - - /** - * Indicates whether the term is of an array sort. - **/ - public boolean IsRelation() - { - return (Native.isApp(Context.nCtx, NativeObject) != 0 && - (Z3_sort_kind)Native.getSortKind(Context.nCtx, Native.getSort(Context.nCtx, NativeObject)) == Z3_sort_kind.Z3_RELATION_SORT); - } - - /** - * Indicates whether the term is an relation store - * - * Insert a record into a relation. - * The function takes n+1 arguments, where the first argument is the relation and the remaining n elements - * correspond to the n columns of the relation. - * - **/ - public boolean IsRelationStore() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_STORE; } - - /** - * Indicates whether the term is an empty relation - **/ - public boolean IsEmptyRelation() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_EMPTY; } - - /** - * Indicates whether the term is a test for the emptiness of a relation - **/ - public boolean IsIsEmptyRelation() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_IS_EMPTY; } - - /** - * Indicates whether the term is a relational join - **/ - public boolean IsRelationalJoin() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_JOIN; } - - /** - * Indicates whether the term is the union or convex hull of two relations. - * The function takes two arguments. - **/ - public boolean IsRelationUnion() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_UNION; } - - /** - * Indicates whether the term is the widening of two relations - * The function takes two arguments. - **/ - public boolean IsRelationWiden() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_WIDEN; } - - /** - * Indicates whether the term is a projection of columns (provided as numbers in the parameters). - * The function takes one argument. - **/ - public boolean IsRelationProject() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_PROJECT; } - - /** - * Indicates whether the term is a relation filter - * - * Filter (restrict) a relation with respect to a predicate. - * The first argument is a relation. - * The second argument is a predicate with free de-Brujin indices - * corresponding to the columns of the relation. - * So the first column in the relation has index 0. - * - **/ - public boolean IsRelationFilter() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_FILTER; } - - /** - * Indicates whether the term is an intersection of a relation with the negation of another. - * - * Intersect the first relation with respect to negation - * of the second relation (the function takes two arguments). - * Logically, the specification can be described by a function - * - * target = filter_by_negation(pos, neg, columns) - * - * where columns are pairs c1, d1, .., cN, dN of columns from pos and neg, such that - * target are elements in x in pos, such that there is no y in neg that agrees with - * x on the columns c1, d1, .., cN, dN. - * - **/ - public boolean IsRelationNegationFilter() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_NEGATION_FILTER; } - - /** - * Indicates whether the term is the renaming of a column in a relation - * - * The function takes one argument. - * The parameters contain the renaming as a cycle. - * - **/ - public boolean IsRelationRename() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_RENAME; } - - /** - * Indicates whether the term is the complement of a relation - **/ - public boolean IsRelationComplement() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_COMPLEMENT; } - - /** - * Indicates whether the term is a relational select - * - * Check if a record is an element of the relation. - * The function takes n+1 arguments, where the first argument is a relation, - * and the remaining n arguments correspond to a record. - * - **/ - public boolean IsRelationSelect() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_SELECT; } - - /** - * Indicates whether the term is a relational clone (copy) - * - * Create a fresh copy (clone) of a relation. - * The function is logically the identity, but - * in the context of a register machine allows - * for terms of kind - * to perform destructive updates to the first argument. - * - **/ - public boolean IsRelationClone() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_RA_CLONE; } - - /** - * Indicates whether the term is of an array sort. - **/ - public boolean IsFiniteDomain() - { - return (Native.isApp(Context.nCtx, NativeObject) != 0 && - (Z3_sort_kind)Native.getSortKind(Context.nCtx, Native.getSort(Context.nCtx, NativeObject)) == Z3_sort_kind.Z3_FINITE_DOMAIN_SORT); - } - - /** - * Indicates whether the term is a less than predicate over a finite domain. - **/ - public boolean IsFiniteDomainLT() { return FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FD_LT; } - - /** - * The de-Burijn index of a bound variable. - * - * Bound variables are indexed by de-Bruijn indices. It is perhaps easiest to explain - * the meaning of de-Bruijn indices by indicating the compilation process from - * non-de-Bruijn formulas to de-Bruijn format. - * - * abs(forall (x1) phi) = forall (x1) abs1(phi, x1, 0) - * abs(forall (x1, x2) phi) = abs(forall (x1) abs(forall (x2) phi)) - * abs1(x, x, n) = b_n - * abs1(y, x, n) = y - * abs1(f(t1,...,tn), x, n) = f(abs1(t1,x,n), ..., abs1(tn,x,n)) - * abs1(forall (x1) phi, x, n) = forall (x1) (abs1(phi, x, n+1)) - * - * The last line is significant: the index of a bound variable is different depending - * on the scope in which it appears. The deeper x appears, the higher is its - * index. - * - **/ - public long Index() - { - if (!IsVar) - throw new Z3Exception("Term is not a bound variable."); - - - - return Native.getIndexValue(Context.nCtx, NativeObject); - } - - /** - * Constructor for Expr - **/ - protected Expr(Context ctx) { super(ctx); } - /** - * Constructor for Expr - **/ - protected Expr(Context ctx, IntPtr obj) { super(ctx, obj); } - - void CheckNativeObject(IntPtr obj) - { - if (Native.isApp(Context.nCtx, obj) == 0 && - (Z3_ast_kind)Native.getAstKind(Context.nCtx, obj) != Z3_ast_kind.Z3_VAR_AST && - (Z3_ast_kind)Native.getAstKind(Context.nCtx, obj) != Z3_ast_kind.Z3_QUANTIFIER_AST) - throw new Z3Exception("Underlying object is not a term"); - super.CheckNativeObject(obj); - } - - static Expr Create(Context ctx, FuncDecl f, Expr[] arguments) - { - - - - - IntPtr obj = Native.mkApp(ctx.nCtx, f.NativeObject, - AST.ArrayLength(arguments), - AST.ArrayToNative(arguments)); - return Create(ctx, obj); - } - - static Expr Create(Context ctx, IntPtr obj) - { - - - - Z3_ast_kind k = (Z3_ast_kind)Native.getAstKind(ctx.nCtx, obj); - if (k == Z3_ast_kind.Z3_QUANTIFIER_AST) - return new Quantifier(ctx, obj); - IntPtr s = Native.getSort(ctx.nCtx, obj); - Z3_sort_kind sk = (Z3_sort_kind)Native.getSortKind(ctx.nCtx, s); - - if (Native.isAlgebraicNumber(ctx.nCtx, obj) != 0) // is this a numeral ast? - return new AlgebraicNum(ctx, obj); - - if (Native.isNumeralAst(ctx.nCtx, obj) != 0) - { - switch (sk) - { - case Z3_sort_kind.Z3_INT_SORT: return new IntNum(ctx, obj); - case Z3_sort_kind.Z3_REAL_SORT: return new RatNum(ctx, obj); - case Z3_sort_kind.Z3_BV_SORT: return new BitVecNum(ctx, obj); - } - } - - switch (sk) - { - case Z3_sort_kind.Z3_BOOL_SORT: return new BoolExpr(ctx, obj); - case Z3_sort_kind.Z3_INT_SORT: return new IntExpr(ctx, obj); - case Z3_sort_kind.Z3_REAL_SORT: return new RealExpr(ctx, obj); - case Z3_sort_kind.Z3_BV_SORT: return new BitVecExpr(ctx, obj); - case Z3_sort_kind.Z3_ARRAY_SORT: return new ArrayExpr(ctx, obj); - case Z3_sort_kind.Z3_DATATYPE_SORT: return new DatatypeExpr(ctx, obj); - } - - return new Expr(ctx, obj); - } - } - - /** - * Boolean expressions - **/ - public class BoolExpr extends Expr - { - /** Constructor for BoolExpr - **/ - protected BoolExpr(Context ctx) { super(ctx); } - /** Constructor for BoolExpr - **/ - BoolExpr(Context ctx, IntPtr obj) { super(ctx, obj); } - } - - /** - * Arithmetic expressions (int/real) - **/ - public class ArithExpr extends Expr - { - /** Constructor for ArithExpr - **/ - protected ArithExpr(Context ctx) - { super(ctx); - - } - ArithExpr(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - } - - /** - * Int expressions - **/ - public class IntExpr extends ArithExpr - { - /** Constructor for IntExpr - **/ - protected IntExpr(Context ctx) - { super(ctx); - - } - IntExpr(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - } - - /** - * Real expressions - **/ - public class RealExpr extends ArithExpr - { - /** Constructor for RealExpr - **/ - protected RealExpr(Context ctx) - { super(ctx); - - } - RealExpr(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - } - - /** - * Bit-vector expressions - **/ - public class BitVecExpr extends Expr - { - - /** - * The size of the sort of a bit-vector term. - **/ - public long SortSize() { return ((BitVecSort)Sort).Size; } - - /** Constructor for BitVecExpr - **/ - protected BitVecExpr(Context ctx) { super(ctx); } - BitVecExpr(Context ctx, IntPtr obj) { super(ctx, obj); } - } - - /** - * Array expressions - **/ - public class ArrayExpr extends Expr - { - /** Constructor for ArrayExpr - **/ - protected ArrayExpr(Context ctx) - { super(ctx); - - } - ArrayExpr(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - } - - /** - * Datatype expressions - **/ - public class DatatypeExpr extends Expr - { - /** Constructor for DatatypeExpr - **/ - protected DatatypeExpr(Context ctx) - { super(ctx); - - } - DatatypeExpr(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - } diff --git a/src/api/java/com/Microsoft/Z3/Fixedpoint.java b/src/api/java/com/Microsoft/Z3/Fixedpoint.java deleted file mode 100644 index 77ce576ac..000000000 --- a/src/api/java/com/Microsoft/Z3/Fixedpoint.java +++ /dev/null @@ -1,302 +0,0 @@ -/** - * This file was automatically generated from Fixedpoint.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Object for managing fixedpoints - **/ - public class Fixedpoint extends Z3Object - { - - /** - * A string that describes all available fixedpoint solver parameters. - **/ - public String Help() - { - - return Native.fixedpointGetHelp(Context.nCtx, NativeObject); - } - - /** - * Sets the fixedpoint solver parameters. - **/ - public void setParameters(Params value) - { - - Context.CheckContextMatch(value); - Native.fixedpointSetParams(Context.nCtx, NativeObject, value.NativeObject); - } - - /** - * Retrieves parameter descriptions for Fixedpoint solver. - **/ - public ParamDescrs ParameterDescriptions() { return new ParamDescrs(Context, Native.fixedpointGetParamDescrs(Context.nCtx, NativeObject)); } - - - /** - * Assert a constraint (or multiple) into the fixedpoint solver. - **/ - public void Assert(BoolExpr[] constraints) - { - - - - Context.CheckContextMatch(constraints); - for (BoolExpr.Iterator a = constraints.iterator(); a.hasNext(); ) - { - Native.fixedpointAssert(Context.nCtx, NativeObject, a.NativeObject); - } - } - - /** - * Register predicate as recursive relation. - **/ - public void RegisterRelation(FuncDecl f) - { - - - Context.CheckContextMatch(f); - Native.fixedpointRegisterRelation(Context.nCtx, NativeObject, f.NativeObject); - } - - /** - * Add rule into the fixedpoint solver. - **/ - public void AddRule(BoolExpr rule, Symbol name) - { - - - Context.CheckContextMatch(rule); - Native.fixedpointAddRule(Context.nCtx, NativeObject, rule.NativeObject, AST.GetNativeObject(name)); - } - - /** - * Add table fact to the fixedpoint solver. - **/ - public void AddFact(FuncDecl pred, long[] args) - { - - - - Context.CheckContextMatch(pred); - Native.fixedpointAddFact(Context.nCtx, NativeObject, pred.NativeObject, (long)args.Length, args); - } - - /** - * Query the fixedpoint solver. - * A query is a conjunction of constraints. The constraints may include the recursively defined relations. - * The query is satisfiable if there is an instance of the query variables and a derivation for it. - * The query is unsatisfiable if there are no derivations satisfying the query variables. - **/ - public Status Query(BoolExpr query) - { - - - Context.CheckContextMatch(query); - Z3_lboolean r = (Z3_lboolean)Native.fixedpointQuery(Context.nCtx, NativeObject, query.NativeObject); - switch (r) - { - case Z3_lboolean.Z3_L_TRUE: return Status.SATISFIABLE; - case Z3_lboolean.Z3_L_FALSE: return Status.UNSATISFIABLE; - default: return Status.UNKNOWN; - } - } - - /** - * Query the fixedpoint solver. - * A query is an array of relations. - * The query is satisfiable if there is an instance of some relation that is non-empty. - * The query is unsatisfiable if there are no derivations satisfying any of the relations. - **/ - public Status Query(FuncDecl[] relations) - { - - - - Context.CheckContextMatch(relations); - Z3_lboolean r = (Z3_lboolean)Native.fixedpointQueryRelations(Context.nCtx, NativeObject, - AST.ArrayLength(relations), AST.ArrayToNative(relations)); - switch (r) - { - case Z3_lboolean.Z3_L_TRUE: return Status.SATISFIABLE; - case Z3_lboolean.Z3_L_FALSE: return Status.UNSATISFIABLE; - default: return Status.UNKNOWN; - } - } - - /** - * Creates a backtracking point. - * - **/ - public void Push() - { - Native.fixedpointPush(Context.nCtx, NativeObject); - } - - /** - * Backtrack one backtracking point. - * Note that an exception is thrown if Pop is called without a corresponding Push - * - **/ - public void Pop() - { - Native.fixedpointPop(Context.nCtx, NativeObject); - } - - - /** - * Update named rule into in the fixedpoint solver. - **/ - public void UpdateRule(BoolExpr rule, Symbol name) - { - - - Context.CheckContextMatch(rule); - Native.fixedpointUpdateRule(Context.nCtx, NativeObject, rule.NativeObject, AST.GetNativeObject(name)); - } - - /** - * Retrieve satisfying instance or instances of solver, - * or definitions for the recursive predicates that show unsatisfiability. - **/ - public Expr GetAnswer() - { - IntPtr ans = Native.fixedpointGetAnswer(Context.nCtx, NativeObject); - return (ans == IntPtr.Zero) ? null : Expr.Create(Context, ans); - } - - /** - * Retrieve explanation why fixedpoint engine returned status Unknown. - **/ - public String GetReasonUnknown() - { - - - return Native.fixedpointGetReasonUnknown(Context.nCtx, NativeObject); - } - - /** - * Retrieve the number of levels explored for a given predicate. - **/ - public long GetNumLevels(FuncDecl predicate) - { - return Native.fixedpointGetNumLevels(Context.nCtx, NativeObject, predicate.NativeObject); - } - - /** - * Retrieve the cover of a predicate. - **/ - public Expr GetCoverDelta(int level, FuncDecl predicate) - { - IntPtr res = Native.fixedpointGetCoverDelta(Context.nCtx, NativeObject, level, predicate.NativeObject); - return (res == IntPtr.Zero) ? null : Expr.Create(Context, res); - } - - /** - * Add property about the predicate. - * The property is added at level. - **/ - public void AddCover(int level, FuncDecl predicate, Expr property) - { - Native.fixedpointAddCover(Context.nCtx, NativeObject, level, predicate.NativeObject, property.NativeObject); - } - - /** - * Retrieve internal string representation of fixedpoint object. - **/ - public String toString() - { - return Native.fixedpointtoString(Context.nCtx, NativeObject, 0, null); - } - - /** - * Instrument the Datalog engine on which table representation to use for recursive predicate. - **/ - public void SetPredicateRepresentation(FuncDecl f, Symbol[] kinds) - { - - - Native.fixedpointSetPredicateRepresentation(Context.nCtx, NativeObject, - f.NativeObject, AST.ArrayLength(kinds), Symbol.ArrayToNative(kinds)); - - } - - /** - * Convert benchmark given as set of axioms, rules and queries to a string. - **/ - public String toString(BoolExpr[] queries) - { - - return Native.fixedpointtoString(Context.nCtx, NativeObject, - AST.ArrayLength(queries), AST.ArrayToNative(queries)); - } - - /** - * Retrieve set of rules added to fixedpoint context. - **/ - public BoolExpr[] Rules() - { - - - ASTVector v = new ASTVector(Context, Native.fixedpointGetRules(Context.nCtx, NativeObject)); - long n = v.Size; - BoolExpr[] res = new BoolExpr[n]; - for (long i = 0; i < n; i++) - res[i] = new BoolExpr(Context, v[i].NativeObject); - return res; - } - - /** - * Retrieve set of assertions added to fixedpoint context. - **/ - public BoolExpr[] Assertions() - { - - - ASTVector v = new ASTVector(Context, Native.fixedpointGetAssertions(Context.nCtx, NativeObject)); - long n = v.Size; - BoolExpr[] res = new BoolExpr[n]; - for (long i = 0; i < n; i++) - res[i] = new BoolExpr(Context, v[i].NativeObject); - return res; - } - - - Fixedpoint(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - Fixedpoint(Context ctx) - { super(ctx, Native.mkFixedpoint(ctx.nCtx)); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.fixedpointIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.fixedpointDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.Fixedpoint_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.Fixedpoint_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/FuncDecl.java b/src/api/java/com/Microsoft/Z3/FuncDecl.java deleted file mode 100644 index ddedcf4ee..000000000 --- a/src/api/java/com/Microsoft/Z3/FuncDecl.java +++ /dev/null @@ -1,292 +0,0 @@ -/** - * This file was automatically generated from FuncDecl.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Function declarations. - **/ - public class FuncDecl extends AST - { - /** - * Comparison operator. - * @return True if and share the same context and are equal, false otherwise. - **/ - /* Overloaded operators are not translated. */ - - /** - * Comparison operator. - * @return True if and do not share the same context or are not equal, false otherwise. - **/ - /* Overloaded operators are not translated. */ - - /** - * Object comparison. - **/ - public boolean Equals(object o) - { - FuncDecl casted = (FuncDecl) o; - if (casted == null) return false; - return this == casted; - } - - /** - * A hash code. - **/ - public int GetHashCode() - { - return super.GetHashCode(); - } - - /** - * A string representations of the function declaration. - **/ - public String toString() - { - return Native.funcDecltoString(Context.nCtx, NativeObject); - } - - /** - * Returns a unique identifier for the function declaration. - **/ - public long Id() { return Native.getFuncDeclId(Context.nCtx, NativeObject); } - - /** - * The arity of the function declaration - **/ - public long Arity() { return Native.getArity(Context.nCtx, NativeObject); } - - /** - * The size of the domain of the function declaration - * - **/ - public long DomainSize() { return Native.getDomainSize(Context.nCtx, NativeObject); } - - /** - * The domain of the function declaration - **/ - public Sort[] Domain() - { - - - var n = DomainSize; - - Sort[] res = new Sort[n]; - for (long i = 0; i < n; i++) - res[i] = Sort.Create(Context, Native.getDomain(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The range of the function declaration - **/ - public Sort Range() - { - - return Sort.Create(Context, Native.getRange(Context.nCtx, NativeObject)); - } - - /** - * The kind of the function declaration. - **/ - public Z3_decl_kind DeclKind() { return (Z3_decl_kind)Native.getDeclKind(Context.nCtx, NativeObject); } - - /** - * The name of the function declaration - **/ - public Symbol Name() - { - - return Symbol.Create(Context, Native.getDeclName(Context.nCtx, NativeObject)); - } - - /** - * The number of parameters of the function declaration - **/ - public long NumParameters() { return Native.getDeclNumParameters(Context.nCtx, NativeObject); } - - /** - * The parameters of the function declaration - **/ - public Parameter[] Parameters() - { - - - long num = NumParameters; - Parameter[] res = new Parameter[num]; - for (long i = 0; i < num; i++) - { - Z3_parameter_kind k = (Z3_parameter_kind)Native.getDeclParameterKind(Context.nCtx, NativeObject, i); - switch (k) - { - case Z3_parameter_kind.Z3_PARAMETER_INT: - res[i] = new Parameter(k, Native.getDeclIntParameter(Context.nCtx, NativeObject, i)); - break; - case Z3_parameter_kind.Z3_PARAMETER_DOUBLE: - res[i] = new Parameter(k, Native.getDeclDoubleParameter(Context.nCtx, NativeObject, i)); - break; - case Z3_parameter_kind.Z3_PARAMETER_SYMBOL: - res[i] = new Parameter(k, Symbol.Create(Context, Native.getDeclSymbolParameter(Context.nCtx, NativeObject, i))); - break; - case Z3_parameter_kind.Z3_PARAMETER_SORT: - res[i] = new Parameter(k, Sort.Create(Context, Native.getDeclSortParameter(Context.nCtx, NativeObject, i))); - break; - case Z3_parameter_kind.Z3_PARAMETER_AST: - res[i] = new Parameter(k, new AST(Context, Native.getDeclAstParameter(Context.nCtx, NativeObject, i))); - break; - case Z3_parameter_kind.Z3_PARAMETER_FUNC_DECL: - res[i] = new Parameter(k, new FuncDecl(Context, Native.getDeclFuncDeclParameter(Context.nCtx, NativeObject, i))); - break; - case Z3_parameter_kind.Z3_PARAMETER_RATIONAL: - res[i] = new Parameter(k, Native.getDeclRationalParameter(Context.nCtx, NativeObject, i)); - break; - default: - throw new Z3Exception("Unknown function declaration parameter kind encountered"); - } - return res; - } - } - - /** - * Function declarations can have Parameters associated with them. - **/ - public class Parameter - { - private Z3_parameter_kind kind; - private int i; - private double d; - private Symbol sym; - private Sort srt; - private AST ast; - private FuncDecl fd; - private String r; - - /**The int value of the parameter. - **/ - public int Int () { if (ParameterKind != Z3_parameter_kind.Z3_PARAMETER_INT) throw new Z3Exception("parameter is not an int"); return i; } - /**The double value of the parameter. - **/ - public double Double () { if (ParameterKind != Z3_parameter_kind.Z3_PARAMETER_DOUBLE) throw new Z3Exception("parameter is not a double "); return d; } - /**The Symbol value of the parameter. - **/ - public Symbol Symbol () { if (ParameterKind != Z3_parameter_kind.Z3_PARAMETER_SYMBOL) throw new Z3Exception("parameter is not a Symbol"); return sym; } - /**The Sort value of the parameter. - **/ - public Sort Sort () { if (ParameterKind != Z3_parameter_kind.Z3_PARAMETER_SORT) throw new Z3Exception("parameter is not a Sort"); return srt; } - /**The AST value of the parameter. - **/ - public AST AST () { if (ParameterKind != Z3_parameter_kind.Z3_PARAMETER_AST) throw new Z3Exception("parameter is not an AST"); return ast; } - /**The FunctionDeclaration value of the parameter. - **/ - public FuncDecl FuncDecl () { if (ParameterKind != Z3_parameter_kind.Z3_PARAMETER_FUNC_DECL) throw new Z3Exception("parameter is not a function declaration"); return fd; } - /**The rational string value of the parameter. - **/ - public String Rational () { if (ParameterKind != Z3_parameter_kind.Z3_PARAMETER_RATIONAL) throw new Z3Exception("parameter is not a rational String"); return r; } - - /** - * The kind of the parameter. - **/ - public Z3_parameter_kind ParameterKind() { return kind; } - - Parameter(Z3_parameter_kind k, int i) - { - this.kind = k; - this.i = i; - } - Parameter(Z3_parameter_kind k, double d) - { - this.kind = k; - this.d = d; - } - - Parameter(Z3_parameter_kind k, Symbol s) - { - this.kind = k; - this.sym = s; - } - - Parameter(Z3_parameter_kind k, Sort s) - { - this.kind = k; - this.srt = s; - } - - Parameter(Z3_parameter_kind k, AST a) - { - this.kind = k; - this.ast = a; - } - - Parameter(Z3_parameter_kind k, FuncDecl fd) - { - this.kind = k; - this.fd = fd; - } - - Parameter(Z3_parameter_kind k, String r) - { - this.kind = k; - this.r = r; - } - } - - FuncDecl(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - - FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range) - : base(ctx, Native.mkFuncDecl(ctx.nCtx, name.NativeObject, - AST.ArrayLength(domain), AST.ArrayToNative(domain), - range.NativeObject)) - - - - } - - FuncDecl(Context ctx, String prefix, Sort[] domain, Sort range) - : base(ctx, Native.mkFreshFuncDecl(ctx.nCtx, prefix, - AST.ArrayLength(domain), AST.ArrayToNative(domain), - range.NativeObject)) - - - } - - void CheckNativeObject(IntPtr obj) - { - if (Native.getAstKind(Context.nCtx, obj) != (long)Z3_ast_kind.Z3_FUNC_DECL_AST) - throw new Z3Exception("Underlying object is not a function declaration"); - super.CheckNativeObject(obj); - } - - /** - * Create expression that applies function to arguments. - * - * @return - **/ - public Expr this[params() lic Expr this[params Expr[] args - { - public Expr this[params() - { - - - return Apply(args); - } - - /** - * Create expression that applies function to arguments. - * - * @return - **/ - public Expr Apply(Expr[] args) - { - - - Context.CheckContextMatch(args); - return Expr.Create(Context, this, args); - } - - } diff --git a/src/api/java/com/Microsoft/Z3/FuncInterp.java b/src/api/java/com/Microsoft/Z3/FuncInterp.java deleted file mode 100644 index 6aeb33759..000000000 --- a/src/api/java/com/Microsoft/Z3/FuncInterp.java +++ /dev/null @@ -1,179 +0,0 @@ -/** - * This file was automatically generated from FuncInterp.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * A function interpretation is represented as a finite map and an 'else' value. - * Each entry in the finite map represents the value of a function given a set of arguments. - **/ - public class FuncInterp extends Z3Object - { - /** - * An Entry object represents an element in the finite map used to encode - * a function interpretation. - **/ - public class Entry extends Z3Object - { - /** - * Return the (symbolic) value of this entry. - **/ - public Expr Value() { - - return Expr.Create(Context, Native.funcEntryGetValue(Context.nCtx, NativeObject)); } - } - - /** - * The number of arguments of the entry. - **/ - public long NumArgs() { return Native.funcEntryGetNumArgs(Context.nCtx, NativeObject); } - - /** - * The arguments of the function entry. - **/ - public Expr[] Args() - { - - - - long n = NumArgs; - Expr[] res = new Expr[n]; - for (long i = 0; i < n; i++) - res[i] = Expr.Create(Context, Native.funcEntryGetArg(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * A string representation of the function entry. - **/ - public String toString() - { - long n = NumArgs; - String res = "["; - Expr[] args = Args; - for (long i = 0; i < n; i++) - res += args[i] + ", "; - return res + Value + "]"; - } - - Entry(Context ctx, IntPtr obj) { super(ctx, obj); } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.funcEntryIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.funcEntryDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.FuncEntry_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.FuncEntry_DRQ.Add(o); - super.DecRef(o); - } - }; - - /** - * The number of entries in the function interpretation. - **/ - public long NumEntries() { return Native.funcInterpGetNumEntries(Context.nCtx, NativeObject); } - - /** - * The entries in the function interpretation - **/ - public Entry[] Entries() - { - - Contract.Ensures(Contract.ForAll(0, Contract.Result().Length, - j => Contract.Result()[j] != null)); - - long n = NumEntries; - Entry[] res = new Entry[n]; - for (long i = 0; i < n; i++) - res[i] = new Entry(Context, Native.funcInterpGetEntry(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The (symbolic) `else' value of the function interpretation. - **/ - public Expr Else() { - - - return Expr.Create(Context, Native.funcInterpGetElse(Context.nCtx, NativeObject)); } - } - - /** - * The arity of the function interpretation - **/ - public long Arity() { return Native.funcInterpGetArity(Context.nCtx, NativeObject); } - - /** - * A string representation of the function interpretation. - **/ - public String toString() - { - String res = ""; - res += "["; - for (Entry.Iterator e = Entries.iterator(); e.hasNext(); ) - { - long n = e.NumArgs; - if (n > 1) res += "["; - Expr[] args = e.Args; - for (long i = 0; i < n; i++) - { - if (i != 0) res += ", "; - res += args[i]; - } - if (n > 1) res += "]"; - res += " -> " + e.Value + ", "; - } - res += "else -> " + Else; - res += "]"; - return res; - } - - FuncInterp(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.funcInterpIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.funcInterpDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.FuncInterp_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.FuncInterp_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Goal.java b/src/api/java/com/Microsoft/Z3/Goal.java deleted file mode 100644 index 171b81d47..000000000 --- a/src/api/java/com/Microsoft/Z3/Goal.java +++ /dev/null @@ -1,182 +0,0 @@ -/** - * This file was automatically generated from Goal.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * A goal (aka problem). A goal is essentially a set - * of formulas, that can be solved and/or transformed using - * tactics and solvers. - **/ - public class Goal extends Z3Object - { - /** - * The precision of the goal. - * - * Goals can be transformed using over and under approximations. - * An under approximation is applied when the objective is to find a model for a given goal. - * An over approximation is applied when the objective is to find a proof for a given goal. - * - **/ - public Z3_goal_prec Precision() { return (Z3_goal_prec)Native.goalPrecision(Context.nCtx, NativeObject); } - - /** - * Indicates whether the goal is precise. - **/ - public boolean IsPrecise() { return Precision == Z3_goal_prec.Z3_GOAL_PRECISE; } - /** - * Indicates whether the goal is an under-approximation. - **/ - public boolean IsUnderApproximation() { return Precision == Z3_goal_prec.Z3_GOAL_UNDER; } - - /** - * Indicates whether the goal is an over-approximation. - **/ - public boolean IsOverApproximation() { return Precision == Z3_goal_prec.Z3_GOAL_OVER; } - - /** - * Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). - **/ - public boolean IsGarbage() { return Precision == Z3_goal_prec.Z3_GOAL_UNDER_OVER; } - - /** - * Adds the to the given goal. - **/ - public void Assert(BoolExpr[] constraints) - { - - - - Context.CheckContextMatch(constraints); - for (BoolExpr.Iterator c = constraints.iterator(); c.hasNext(); ) - { - // It was an assume, now made an assert just to be sure we do not regress - Native.goalAssert(Context.nCtx, NativeObject, c.NativeObject); - } - } - - /** - * Indicates whether the goal contains `false'. - **/ - public boolean Inconsistent() { return Native.goalInconsistent(Context.nCtx, NativeObject) != 0; } - - /** - * The depth of the goal. - * - * This tracks how many transformations were applied to it. - * - **/ - public long Depth() { return Native.goalDepth(Context.nCtx, NativeObject); } - - /** - * Erases all formulas from the given goal. - **/ - public void Reset() - { - Native.goalReset(Context.nCtx, NativeObject); - } - - /** - * The number of formulas in the goal. - **/ - public long Size() { return Native.goalSize(Context.nCtx, NativeObject); } - - /** - * The formulas in the goal. - **/ - public BoolExpr[] Formulas() - { - - - long n = Size; - BoolExpr[] res = new BoolExpr[n]; - for (long i = 0; i < n; i++) - res[i] = new BoolExpr(Context, Native.goalFormula(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The number of formulas, subformulas and terms in the goal. - **/ - public long NumExprs() { return Native.goalNumExprs(Context.nCtx, NativeObject); } - - /** - * Indicates whether the goal is empty, and it is precise or the product of an under approximation. - **/ - public boolean IsDecidedSat() { return Native.goalIsDecidedSat(Context.nCtx, NativeObject) != 0; } - - /** - * Indicates whether the goal contains `false', and it is precise or the product of an over approximation. - **/ - public boolean IsDecidedUnsat() { return Native.goalIsDecidedUnsat(Context.nCtx, NativeObject) != 0; } - - /** - * Translates (copies) the Goal to the target Context . - **/ - public Goal Translate(Context ctx) - { - - - return new Goal(ctx, Native.goalTranslate(Context.nCtx, NativeObject, ctx.nCtx)); - } - - /** - * Simplifies the goal. - * Essentially invokes the `simplify' tactic on the goal. - **/ - public Goal Simplify(Params p) - { - Tactic t = Context.MkTactic("simplify"); - ApplyResult res = t.Apply(this, p); - - if (res.NumSubgoals == 0) - return Context.MkGoal(); - else - return res.Subgoals[0]; - } - - /** - * Goal to string conversion. - * @return A string representation of the Goal. - **/ - public String toString() - { - return Native.goaltoString(Context.nCtx, NativeObject); - } - - Goal(Context ctx, IntPtr obj) { super(ctx, obj); } - - Goal(Context ctx, boolean models, boolean unsatCores, boolean proofs) - { super(ctx, Native.mkGoal(ctx.nCtx, (models); ? 1 : 0, (unsatCores) ? 1 : 0, (proofs) ? 1 : 0)) - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.goalIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.goalDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.Goal_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.Goal_DRQ.Add(o); - super.DecRef(o); - } - - } diff --git a/src/api/java/com/Microsoft/Z3/Log.java b/src/api/java/com/Microsoft/Z3/Log.java deleted file mode 100644 index 35ac0e022..000000000 --- a/src/api/java/com/Microsoft/Z3/Log.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * This file was automatically generated from Log.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Interaction logging for Z3. - * - * Note that this is a global, static log and if multiple Context - * objects are created, it logs the interaction with all of them. - * - **/ - public final class Log - { - private boolean m_is_open = false; - - /** - * Open an interaction log file. - * the name of the file to open - * @return True if opening the log file succeeds, false otherwise. - **/ - public boolean Open(String filename) - { - m_is_open = true; - return Native.openLog(filename) == 1; - } - - /** - * Closes the interaction log. - **/ - public void Close() - { - m_is_open = false; - Native.closeLog(); - } - - /** - * Appends the user-provided string to the interaction log. - **/ - public void Append(String s) - { - - - if (!m_is_open) - throw new Z3Exception("Log cannot be closed."); - Native.appendLog(s); - } - - /** - * Checks whether the interaction log is opened. - * @return True if the interaction log is open, false otherwise. - **/ - public boolean isOpen() - { - return m_is_open; - } - } diff --git a/src/api/java/com/Microsoft/Z3/Model.java b/src/api/java/com/Microsoft/Z3/Model.java deleted file mode 100644 index edd774f56..000000000 --- a/src/api/java/com/Microsoft/Z3/Model.java +++ /dev/null @@ -1,279 +0,0 @@ -/** - * This file was automatically generated from Model.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * A Model contains interpretations (assignments) of constants and functions. - **/ - public class Model extends Z3Object - { - /** - * Retrieves the interpretation (the assignment) of in the model. - * A Constant - * @return An expression if the constant has an interpretation in the model, null otherwise. - **/ - public Expr ConstInterp(Expr a) - { - - - Context.CheckContextMatch(a); - return ConstInterp(a.FuncDecl); - } - - /** - * Retrieves the interpretation (the assignment) of in the model. - * A function declaration of zero arity - * @return An expression if the function has an interpretation in the model, null otherwise. - **/ - public Expr ConstInterp(FuncDecl f) - { - - - Context.CheckContextMatch(f); - if (f.Arity != 0 || - Native.getSortKind(Context.nCtx, Native.getRange(Context.nCtx, f.NativeObject)) == (long)Z3_sort_kind.Z3_ARRAY_SORT) - throw new Z3Exception("Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp."); - - IntPtr n = Native.modelGetConstInterp(Context.nCtx, NativeObject, f.NativeObject); - if (n == IntPtr.Zero) - return null; - else - return Expr.Create(Context, n); - } - - /** - * Retrieves the interpretation (the assignment) of a non-constant in the model. - * A function declaration of non-zero arity - * @return A FunctionInterpretation if the function has an interpretation in the model, null otherwise. - **/ - public FuncInterp FuncInterp(FuncDecl f) - { - - - Context.CheckContextMatch(f); - - Z3_sort_kind sk = (Z3_sort_kind)Native.getSortKind(Context.nCtx, Native.getRange(Context.nCtx, f.NativeObject)); - - if (f.Arity == 0) - { - IntPtr n = Native.modelGetConstInterp(Context.nCtx, NativeObject, f.NativeObject); - - if (sk == Z3_sort_kind.Z3_ARRAY_SORT) - { - if (n == IntPtr.Zero) - return null; - else - { - if (Native.isAsArray(Context.nCtx, n) == 0) - throw new Z3Exception("Argument was not an array constant"); - IntPtr fd = Native.getAsArrayFuncDecl(Context.nCtx, n); - return FuncInterp(new FuncDecl(Context, fd)); - } - } - else - { - throw new Z3Exception("Constant functions do not have a function interpretation; use ConstInterp"); - } - } - else - { - IntPtr n = Native.modelGetFuncInterp(Context.nCtx, NativeObject, f.NativeObject); - if (n == IntPtr.Zero) - return null; - else - return new FuncInterp(Context, n); - } - } - - /** - * The number of constants that have an interpretation in the model. - **/ - public long NumConsts() { return Native.modelGetNumConsts(Context.nCtx, NativeObject); } - - /** - * The function declarations of the constants in the model. - **/ - public FuncDecl[] ConstDecls() - { - - - long n = NumConsts; - FuncDecl[] res = new FuncDecl[n]; - for (long i = 0; i < n; i++) - res[i] = new FuncDecl(Context, Native.modelGetConstDecl(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The number of function interpretations in the model. - **/ - public long NumFuncs() { return Native.modelGetNumFuncs(Context.nCtx, NativeObject); } - - /** - * The function declarations of the function interpretations in the model. - **/ - public FuncDecl[] FuncDecls() - { - - - long n = NumFuncs; - FuncDecl[] res = new FuncDecl[n]; - for (long i = 0; i < n; i++) - res[i] = new FuncDecl(Context, Native.modelGetFuncDecl(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * All symbols that have an interpretation in the model. - **/ - public FuncDecl[] Decls() - { - - - var nFuncs = NumFuncs; - var nConsts = NumConsts; - long n = nFuncs + nConsts; - FuncDecl[] res = new FuncDecl[n]; - for (long i = 0; i < nConsts; i++) - res[i] = new FuncDecl(Context, Native.modelGetConstDecl(Context.nCtx, NativeObject, i)); - for (long i = 0; i < nFuncs; i++) - res[nConsts + i] = new FuncDecl(Context, Native.modelGetFuncDecl(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. - **/ - public class ModelEvaluationFailedException extends Z3Exception - { - /** - * An exception that is thrown when model evaluation fails. - **/ - public ModelEvaluationFailedException() { super(); } - } - - /** - * Evaluates the expression in the current model. - * - * This function may fail if contains quantifiers, - * is partial (MODEL_PARTIAL enabled), or if is not well-sorted. - * In this case a ModelEvaluationFailedException is thrown. - * - * An expression - * - * When this flag is enabled, a model value will be assigned to any constant - * or function that does not have an interpretation in the model. - * - * @return The evaluation of in the model. - **/ - public Expr Eval(Expr t, boolean completion) - { - - - - IntPtr v = IntPtr.Zero; - if (Native.modelEval(Context.nCtx, NativeObject, t.NativeObject, (completion) ? 1 : 0, v) == 0) - throw new ModelEvaluationFailedException(); - else - return Expr.Create(Context, v); - } - - /** - * Alias for Eval. - **/ - public Expr Evaluate(Expr t, boolean completion) - { - - - - return Eval(t, completion); - } - - /** - * The number of uninterpreted sorts that the model has an interpretation for. - **/ - public long NumSorts () { return Native.modelGetNumSorts(Context.nCtx, NativeObject); } - - /** - * The uninterpreted sorts that the model has an interpretation for. - * - * Z3 also provides an intepretation for uninterpreted sorts used in a formula. - * The interpretation for a sort is a finite set of distinct values. We say this finite set is - * the "universe" of the sort. - * - * - * - **/ - public Sort[] Sorts() - { - - - long n = NumSorts; - Sort[] res = new Sort[n]; - for (long i = 0; i < n; i++) - res[i] = Sort.Create(Context, Native.modelGetSort(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The finite set of distinct values that represent the interpretation for sort . - * - * An uninterpreted sort - * @return An array of expressions, where each is an element of the universe of - **/ - public Expr[] SortUniverse(Sort s) - { - - - - ASTVector nUniv = new ASTVector(Context, Native.modelGetSortUniverse(Context.nCtx, NativeObject, s.NativeObject)); - long n = nUniv.Size; - Expr[] res = new Expr[n]; - for (long i = 0; i < n; i++) - res[i] = Expr.Create(Context, nUniv[i].NativeObject); - return res; - } - - /** - * Conversion of models to strings. - * @return A string representation of the model. - **/ - public String toString() - { - return Native.modeltoString(Context.nCtx, NativeObject); - } - - Model(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.modelIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.modelDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.Model_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.Model_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Native.class b/src/api/java/com/Microsoft/Z3/Native.class deleted file mode 100644 index 04e71cfb4..000000000 Binary files a/src/api/java/com/Microsoft/Z3/Native.class and /dev/null differ diff --git a/src/api/java/com/Microsoft/Z3/Numeral.java b/src/api/java/com/Microsoft/Z3/Numeral.java deleted file mode 100644 index d0ed20dc9..000000000 --- a/src/api/java/com/Microsoft/Z3/Numeral.java +++ /dev/null @@ -1,264 +0,0 @@ -/** - * This file was automatically generated from Numeral.cs - **/ - -package com.Microsoft.Z3; -/* using System; */ - -/* using System.Numerics; */ - - /** - * Integer Numerals - **/ - public class IntNum extends IntExpr - { - - IntNum(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - - - /** - * Retrieve the 64-bit unsigned integer value. - **/ - public UInt64 UInt64() - { - UInt64 res = 0; - if (Native.getNumeralLong64(Context.nCtx, NativeObject, res) == 0) - throw new Z3Exception("Numeral is not a 64 bit unsigned"); - return res; - } - - /** - * Retrieve the int value. - **/ - public int Int() - { - int res = 0; - if (Native.getNumeralInt(Context.nCtx, NativeObject, res) == 0) - throw new Z3Exception("Numeral is not an int"); - return res; - } - - /** - * Retrieve the 64-bit int value. - **/ - public Int64 Int64() - { - Int64 res = 0; - if (Native.getNumeralInt64(Context.nCtx, NativeObject, res) == 0) - throw new Z3Exception("Numeral is not an int64"); - return res; - } - - /** - * Retrieve the int value. - **/ - public long UInt() - { - long res = 0; - if (Native.getNumeralLong(Context.nCtx, NativeObject, res) == 0) - throw new Z3Exception("Numeral is not a long"); - return res; - } - - /** - * Retrieve the BigInteger value. - **/ - public BigInteger BigInteger() - { - return BigInteger.Parse(this.toString()); - } - - /** - * Returns a string representation of the numeral. - **/ - public String toString() - { - return Native.getNumeralString(Context.nCtx, NativeObject); - } - } - - /** - * Rational Numerals - **/ - public class RatNum extends RealExpr - { - /** - * The numerator of a rational numeral. - **/ - public IntNum Numerator() { - - - return new IntNum(Context, Native.getNumerator(Context.nCtx, NativeObject)); } - } - - /** - * The denominator of a rational numeral. - **/ - public IntNum Denominator() { - - - return new IntNum(Context, Native.getDenominator(Context.nCtx, NativeObject)); } - } - - /** - * Converts the numerator of the rational to a BigInteger - **/ - public BigInteger BigIntNumerator() - { - IntNum n = Numerator; - return BigInteger.Parse(n.toString()); - } - - /** - * Converts the denominator of the rational to a BigInteger - **/ - public BigInteger BigIntDenominator() - { - IntNum n = Denominator; - return BigInteger.Parse(n.toString()); - } - - /** - * Returns a string representation in decimal notation. - * The result has at most decimal places. - **/ - public String ToDecimalString(long precision) - { - return Native.getNumeralDecimalString(Context.nCtx, NativeObject, precision); - } - - /** - * Returns a string representation of the numeral. - **/ - public String toString() - { - return Native.getNumeralString(Context.nCtx, NativeObject); - } - - RatNum(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - } - - - /** - * Bit-vector numerals - **/ - public class BitVecNum extends BitVecExpr - { - /** - * Retrieve the 64-bit unsigned integer value. - **/ - public UInt64 UInt64() - { - UInt64 res = 0; - if (Native.getNumeralLong64(Context.nCtx, NativeObject, res) == 0) - throw new Z3Exception("Numeral is not a 64 bit unsigned"); - return res; - } - - /** - * Retrieve the int value. - **/ - public int Int() - { - int res = 0; - if (Native.getNumeralInt(Context.nCtx, NativeObject, res) == 0) - throw new Z3Exception("Numeral is not an int"); - return res; - } - - /** - * Retrieve the 64-bit int value. - **/ - public Int64 Int64() - { - Int64 res = 0; - if (Native.getNumeralInt64(Context.nCtx, NativeObject, res) == 0) - throw new Z3Exception("Numeral is not an int64"); - return res; - } - - /** - * Retrieve the int value. - **/ - public long UInt() - { - long res = 0; - if (Native.getNumeralLong(Context.nCtx, NativeObject, res) == 0) - throw new Z3Exception("Numeral is not a long"); - return res; - } - - /** - * Retrieve the BigInteger value. - **/ - public BigInteger BigInteger() - { - return BigInteger.Parse(this.toString()); - } - - /** - * Returns a string representation of the numeral. - **/ - public String toString() - { - return Native.getNumeralString(Context.nCtx, NativeObject); - } - - BitVecNum(Context ctx, IntPtr obj) { super(ctx, obj); } - } - - /** - * Algebraic numbers - **/ - public class AlgebraicNum extends ArithExpr - { - /** - * Return a upper bound for a given real algebraic number. - * The interval isolating the number is smaller than 1/10^. - * - * the precision of the result - * @return A numeral Expr of sort Real - **/ - public RatNum ToUpper(long precision) - { - - - return new RatNum(Context, Native.getAlgebraicNumberUpper(Context.nCtx, NativeObject, precision)); - } - - /** - * Return a lower bound for the given real algebraic number. - * The interval isolating the number is smaller than 1/10^. - * - * - * @return A numeral Expr of sort Real - **/ - public RatNum ToLower(long precision) - { - - - return new RatNum(Context, Native.getAlgebraicNumberLower(Context.nCtx, NativeObject, precision)); - } - - /** - * Returns a string representation in decimal notation. - * The result has at most decimal places. - **/ - public String ToDecimal(long precision) - { - - - return Native.getNumeralDecimalString(Context.nCtx, NativeObject, precision); - } - - AlgebraicNum(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - } diff --git a/src/api/java/com/Microsoft/Z3/ParamDescrs.java b/src/api/java/com/Microsoft/Z3/ParamDescrs.java deleted file mode 100644 index abade80b2..000000000 --- a/src/api/java/com/Microsoft/Z3/ParamDescrs.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * This file was automatically generated from ParamDescrs.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * A ParamDescrs describes a set of parameters. - **/ - public class ParamDescrs extends Z3Object - { - /** - * validate a set of parameters. - **/ - public void Validate(Params p) - { - - Native.paramsValidate(Context.nCtx, p.NativeObject, NativeObject); - } - - /** - * Retrieve kind of parameter. - **/ - public Z3_param_kind GetKind(Symbol name) - { - - return (Z3_param_kind)Native.paramDescrsGetKind(Context.nCtx, NativeObject, name.NativeObject); - } - - /** - * Retrieve all names of parameters. - **/ - public Symbol[] Names() - { - long sz = Native.paramDescrsSize(Context.nCtx, NativeObject); - Symbol[] names = new Symbol[sz]; - for (long i = 0; i < sz; ++i) { - names[i] = Symbol.Create(Context, Native.paramDescrsGetName(Context.nCtx, NativeObject, i)); - } - return names; - } - - /** - * The size of the ParamDescrs. - **/ - public long Size() { return Native.paramDescrsSize(Context.nCtx, NativeObject); } - - /** - * Retrieves a string representation of the ParamDescrs. - **/ - public String toString() - { - return Native.paramDescrstoString(Context.nCtx, NativeObject); - } - - ParamDescrs(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.paramDescrsIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.paramDescrsDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.ParamDescrs_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.ParamDescrs_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Params.java b/src/api/java/com/Microsoft/Z3/Params.java deleted file mode 100644 index 040b6d67d..000000000 --- a/src/api/java/com/Microsoft/Z3/Params.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * This file was automatically generated from Params.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * A ParameterSet represents a configuration in the form of Symbol/value pairs. - **/ - public class Params extends Z3Object - { - /** - * Adds a parameter setting. - **/ - public void Add(Symbol name, boolean value) - { - - - Native.paramsSetBoolean(Context.nCtx, NativeObject, name.NativeObject, (value) ? 1 : 0); - } - - /** - * Adds a parameter setting. - **/ - public void Add(Symbol name, long value) - { - - - Native.paramsSetLong(Context.nCtx, NativeObject, name.NativeObject, value); - } - - /** - * Adds a parameter setting. - **/ - public void Add(Symbol name, double value) - { - - - Native.paramsSetDouble(Context.nCtx, NativeObject, name.NativeObject, value); - } - - /** - * Adds a parameter setting. - **/ - public void Add(Symbol name, Symbol value) - { - - - - Native.paramsSetSymbol(Context.nCtx, NativeObject, name.NativeObject, value.NativeObject); - } - - /** - * Adds a parameter setting. - **/ - public void Add(String name, boolean value) - { - Native.paramsSetBoolean(Context.nCtx, NativeObject, Context.MkSymbol(name).NativeObject, (value) ? 1 : 0); - } - - /** - * Adds a parameter setting. - **/ - public void Add(String name, long value) - { - Native.paramsSetLong(Context.nCtx, NativeObject, Context.MkSymbol(name).NativeObject, value); - } - - /** - * Adds a parameter setting. - **/ - public void Add(String name, double value) - { - Native.paramsSetDouble(Context.nCtx, NativeObject, Context.MkSymbol(name).NativeObject, value); - } - - /** - * Adds a parameter setting. - **/ - public void Add(String name, Symbol value) - { - - - Native.paramsSetSymbol(Context.nCtx, NativeObject, Context.MkSymbol(name).NativeObject, value.NativeObject); - } - - /** - * A string representation of the parameter set. - **/ - public String toString() - { - return Native.paramstoString(Context.nCtx, NativeObject); - } - - Params(Context ctx) - { super(ctx, Native.mkParams(ctx.nCtx)); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.paramsIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.paramsDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.Params_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.Params_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Pattern.java b/src/api/java/com/Microsoft/Z3/Pattern.java deleted file mode 100644 index edc772dcf..000000000 --- a/src/api/java/com/Microsoft/Z3/Pattern.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * This file was automatically generated from Pattern.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ -/* using System.Runtime.InteropServices; */ - - /** - * Patterns comprise a list of terms. The list should be - * non-empty. If the list comprises of more than one term, it is - * also called a multi-pattern. - **/ - public class Pattern extends AST - { - /** - * The number of terms in the pattern. - **/ - public long NumTerms() { return Native.getPatternNumTerms(Context.nCtx, NativeObject); } - - /** - * The terms in the pattern. - **/ - public Expr[] Terms() - { - - - long n = NumTerms; - Expr[] res = new Expr[n]; - for (long i = 0; i < n; i++) - res[i] = Expr.Create(Context, Native.getPattern(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * A string representation of the pattern. - **/ - public String toString() - { - return Native.patterntoString(Context.nCtx, NativeObject); - } - - Pattern(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - } diff --git a/src/api/java/com/Microsoft/Z3/Probe.java b/src/api/java/com/Microsoft/Z3/Probe.java deleted file mode 100644 index 36f949966..000000000 --- a/src/api/java/com/Microsoft/Z3/Probe.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * This file was automatically generated from Probe.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ -/* using System.Runtime.InteropServices; */ - - /** - * Probes are used to inspect a goal (aka problem) and collect information that may be used to decide - * which solver and/or preprocessing step will be used. - * The complete list of probes may be obtained using the procedures Context.NumProbes - * and Context.ProbeNames. - * It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. - **/ - public class Probe extends Z3Object - { - /** - * Execute the probe over the goal. - * @return A probe always produce a double value. - * "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. - **/ - public double Apply(Goal g) - { - - - Context.CheckContextMatch(g); - return Native.probeApply(Context.nCtx, NativeObject, g.NativeObject); - } - - /** - * Apply the probe to a goal. - **/ - public double this[Goal() - - - return Apply(g); } } - - Probe(Context ctx, IntPtr obj) - { super(ctx, obj); - - Probe(Context ctx, String name) - { super(ctx, Native.mkProbe(ctx.nCtx, name)); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.probeIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.probeDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.Probe_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.Probe_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Quantifier.java b/src/api/java/com/Microsoft/Z3/Quantifier.java deleted file mode 100644 index 6c7c91be7..000000000 --- a/src/api/java/com/Microsoft/Z3/Quantifier.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * This file was automatically generated from Quantifier.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Quantifier expressions. - **/ - public class Quantifier extends BoolExpr - { - /** - * Indicates whether the quantifier is universal. - **/ - public boolean IsUniversal() { return Native.isQuantifierForall(Context.nCtx, NativeObject) != 0; } - - /** - * Indicates whether the quantifier is existential. - **/ - public boolean IsExistential() { return !IsUniversal; } - - /** - * The weight of the quantifier. - **/ - public long Weight() { return Native.getQuantifierWeight(Context.nCtx, NativeObject); } - - /** - * The number of patterns. - **/ - public long NumPatterns() { return Native.getQuantifierNumPatterns(Context.nCtx, NativeObject); } - - /** - * The patterns. - **/ - public Pattern[] Patterns() - { - - - long n = NumPatterns; - Pattern[] res = new Pattern[n]; - for (long i = 0; i < n; i++) - res[i] = new Pattern(Context, Native.getQuantifierPatternAst(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The number of no-patterns. - **/ - public long NumNoPatterns() { return Native.getQuantifierNumNoPatterns(Context.nCtx, NativeObject); } - - /** - * The no-patterns. - **/ - public Pattern[] NoPatterns() - { - - - long n = NumNoPatterns; - Pattern[] res = new Pattern[n]; - for (long i = 0; i < n; i++) - res[i] = new Pattern(Context, Native.getQuantifierNoPatternAst(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The number of bound variables. - **/ - public long NumBound() { return Native.getQuantifierNumBound(Context.nCtx, NativeObject); } - - /** - * The symbols for the bound variables. - **/ - public Symbol[] BoundVariableNames() - { - - - long n = NumBound; - Symbol[] res = new Symbol[n]; - for (long i = 0; i < n; i++) - res[i] = Symbol.Create(Context, Native.getQuantifierBoundName(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The sorts of the bound variables. - **/ - public Sort[] BoundVariableSorts() - { - - - long n = NumBound; - Sort[] res = new Sort[n]; - for (long i = 0; i < n; i++) - res[i] = Sort.Create(Context, Native.getQuantifierBoundSort(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The body of the quantifier. - **/ - public BoolExpr Body() { - - - return new BoolExpr(Context, Native.getQuantifierBody(Context.nCtx, NativeObject)); } - } - - Quantifier(Context ctx, boolean isForall, Sort[] sorts, Symbol[] names, Expr body, - long weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, - Symbol quantifierID = null, Symbol skolemID = null - ) - { super(ctx); - - - - - - - - - - - Context.CheckContextMatch(patterns); - Context.CheckContextMatch(noPatterns); - Context.CheckContextMatch(sorts); - Context.CheckContextMatch(names); - Context.CheckContextMatch(body); - - if (sorts.Length != names.Length) - throw new Z3Exception("Number of sorts does not match number of names"); - - IntPtr[] _patterns = AST.ArrayToNative(patterns); - - if (noPatterns == null && quantifierID == null && skolemID == null) - { - NativeObject = Native.mkQuantifier(ctx.nCtx, (isForall) ? 1 : 0, weight, - AST.ArrayLength(patterns), AST.ArrayToNative(patterns), - AST.ArrayLength(sorts), AST.ArrayToNative(sorts), - Symbol.ArrayToNative(names), - body.NativeObject); - else - { - NativeObject = Native.mkQuantifierEx(ctx.nCtx, (isForall) ? 1 : 0, weight, - AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID), - AST.ArrayLength(patterns), AST.ArrayToNative(patterns), - AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns), - AST.ArrayLength(sorts), AST.ArrayToNative(sorts), - Symbol.ArrayToNative(names), - body.NativeObject); - } - } - - Quantifier(Context ctx, boolean isForall, Expr[] bound, Expr body, - long weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, - Symbol quantifierID = null, Symbol skolemID = null - ) - { super(ctx); - - - - - - - - Context.CheckContextMatch(noPatterns); - Context.CheckContextMatch(patterns); - //Context.CheckContextMatch(bound); - Context.CheckContextMatch(body); - - if (noPatterns == null && quantifierID == null && skolemID == null) - { - NativeObject = Native.mkQuantifierConst(ctx.nCtx, (isForall) ? 1 : 0, weight, - AST.ArrayLength(bound), AST.ArrayToNative(bound), - AST.ArrayLength(patterns), AST.ArrayToNative(patterns), - body.NativeObject); - } - else - { - NativeObject = Native.mkQuantifierConstEx(ctx.nCtx, (isForall) ? 1 : 0, weight, - AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID), - AST.ArrayLength(bound), AST.ArrayToNative(bound), - AST.ArrayLength(patterns), AST.ArrayToNative(patterns), - AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns), - body.NativeObject); - } - } - - - Quantifier(Context ctx, IntPtr obj) { super(ctx, obj); } - - void CheckNativeObject(IntPtr obj) - { - if ((Z3_ast_kind)Native.getAstKind(Context.nCtx, obj) != Z3_ast_kind.Z3_QUANTIFIER_AST) - throw new Z3Exception("Underlying object is not a quantifier"); - super.CheckNativeObject(obj); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Solver.java b/src/api/java/com/Microsoft/Z3/Solver.java deleted file mode 100644 index 787e115ab..000000000 --- a/src/api/java/com/Microsoft/Z3/Solver.java +++ /dev/null @@ -1,247 +0,0 @@ -/** - * This file was automatically generated from Solver.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Solvers. - **/ - public class Solver extends Z3Object - { - /** - * A string that describes all available solver parameters. - **/ - public String Help() - { - - - return Native.solverGetHelp(Context.nCtx, NativeObject); - } - - /** - * Sets the solver parameters. - **/ - public void setParameters(Params value) - { - - - Context.CheckContextMatch(value); - Native.solverSetParams(Context.nCtx, NativeObject, value.NativeObject); - } - - /** - * Retrieves parameter descriptions for solver. - **/ - public ParamDescrs ParameterDescriptions() { return new ParamDescrs(Context, Native.solverGetParamDescrs(Context.nCtx, NativeObject)); } - - - /** - * The current number of backtracking points (scopes). - * - * - **/ - public long NumScopes() { return Native.solverGetNumScopes(Context.nCtx, NativeObject); } - - /** - * Creates a backtracking point. - * - **/ - public void Push() - { - Native.solverPush(Context.nCtx, NativeObject); - } - - /** - * Backtracks backtracking points. - * Note that an exception is thrown if is not smaller than NumScopes - * - **/ - public void Pop(long n) - { - Native.solverPop(Context.nCtx, NativeObject, n); - } - - /** - * Resets the Solver. - * This removes all assertions from the solver. - **/ - public void Reset() - { - Native.solverReset(Context.nCtx, NativeObject); - } - - /** - * Assert a constraint (or multiple) into the solver. - **/ - public void Assert(BoolExpr[] constraints) - { - - - - Context.CheckContextMatch(constraints); - for (BoolExpr.Iterator a = constraints.iterator(); a.hasNext(); ) - { - Native.solverAssert(Context.nCtx, NativeObject, a.NativeObject); - } - } - - /** - * The number of assertions in the solver. - **/ - public long NumAssertions() - { - ASTVector ass = new ASTVector(Context, Native.solverGetAssertions(Context.nCtx, NativeObject)); - return ass.Size; - } - - /** - * The set of asserted formulas. - **/ - public BoolExpr[] Assertions() - { - - - ASTVector ass = new ASTVector(Context, Native.solverGetAssertions(Context.nCtx, NativeObject)); - long n = ass.Size; - BoolExpr[] res = new BoolExpr[n]; - for (long i = 0; i < n; i++) - res[i] = new BoolExpr(Context, ass[i].NativeObject); - return res; - } - - /** - * Checks whether the assertions in the solver are consistent or not. - * - * - * - * - * - **/ - public Status Check(Expr[] assumptions) - { - Z3_lboolean r; - if (assumptions == null) - r = (Z3_lboolean)Native.solverCheck(Context.nCtx, NativeObject); - else - r = (Z3_lboolean)Native.solverCheckAssumptions(Context.nCtx, NativeObject, (long)assumptions.Length, AST.ArrayToNative(assumptions)); - switch (r) - { - case Z3_lboolean.Z3_L_TRUE: return Status.SATISFIABLE; - case Z3_lboolean.Z3_L_FALSE: return Status.UNSATISFIABLE; - default: return Status.UNKNOWN; - } - } - - /** - * The model of the last Check. - * - * The result is null if Check was not invoked before, - * if its results was not SATISFIABLE, or if model production is not enabled. - * - **/ - public Model Model() - { - IntPtr x = Native.solverGetModel(Context.nCtx, NativeObject); - if (x == IntPtr.Zero) - return null; - else - return new Model(Context, x); - } - - /** - * The proof of the last Check. - * - * The result is null if Check was not invoked before, - * if its results was not UNSATISFIABLE, or if proof production is disabled. - * - **/ - public Expr Proof() - { - IntPtr x = Native.solverGetProof(Context.nCtx, NativeObject); - if (x == IntPtr.Zero) - return null; - else - return Expr.Create(Context, x); - } - - /** - * The unsat core of the last Check. - * - * The unsat core is a subset of Assertions - * The result is empty if Check was not invoked before, - * if its results was not UNSATISFIABLE, or if core production is disabled. - * - **/ - public Expr[] UnsatCore() - { - - - ASTVector core = new ASTVector(Context, Native.solverGetUnsatCore(Context.nCtx, NativeObject)); - long n = core.Size; - Expr[] res = new Expr[n]; - for (long i = 0; i < n; i++) - res[i] = Expr.Create(Context, core[i].NativeObject); - return res; - } - - /** - * A brief justification of why the last call to Check returned UNKNOWN. - **/ - public String ReasonUnknown() - { - - - return Native.solverGetReasonUnknown(Context.nCtx, NativeObject); - } - - /** - * Solver statistics. - **/ - public Statistics Statistics() - { - - - return new Statistics(Context, Native.solverGetStatistics(Context.nCtx, NativeObject)); - } - - /** - * A string representation of the solver. - **/ - public String toString() - { - return Native.solvertoString(Context.nCtx, NativeObject); - } - - Solver(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.solverIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.solverDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.Solver_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.Solver_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Sort.java b/src/api/java/com/Microsoft/Z3/Sort.java deleted file mode 100644 index 8e4735389..000000000 --- a/src/api/java/com/Microsoft/Z3/Sort.java +++ /dev/null @@ -1,583 +0,0 @@ -/** - * This file was automatically generated from Sort.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * The Sort class implements type information for ASTs. - **/ - public class Sort extends AST - { - /** - * Comparison operator. - * A Sort - * A Sort - * @return True if and are from the same context - * and represent the same sort; false otherwise. - **/ - /* Overloaded operators are not translated. */ - - /** - * Comparison operator. - * A Sort - * A Sort - * @return True if and are not from the same context - * or represent different sorts; false otherwise. - **/ - /* Overloaded operators are not translated. */ - - /** - * Equality operator for objects of type Sort. - * - * @return - **/ - public boolean Equals(object o) - { - Sort casted = o as Sort; - if (casted == null) return false; - return this == casted; - } - - /** - * Hash code generation for Sorts - * @return A hash code - **/ - public int GetHashCode() - { - return super.GetHashCode(); - } - - /** - * Returns a unique identifier for the sort. - **/ - public long Id() { return Native.getSortId(Context.nCtx, NativeObject); } - - /** - * The kind of the sort. - **/ - public Z3_sort_kind SortKind() { return (Z3_sort_kind)Native.getSortKind(Context.nCtx, NativeObject); } - - /** - * The name of the sort - **/ - public Symbol Name() { - - return Symbol.Create(Context, Native.getSortName(Context.nCtx, NativeObject)); } - } - - /** - * A string representation of the sort. - **/ - public String toString() - { - return Native.sorttoString(Context.nCtx, NativeObject); - - /** - * Sort constructor - **/ - protected Sort(Context ctx) { super(ctx); } - Sort(Context ctx, IntPtr obj) { super(ctx, obj); } - - void CheckNativeObject(IntPtr obj) - { - if (Native.getAstKind(Context.nCtx, obj) != (long)Z3_ast_kind.Z3_SORT_AST) - throw new Z3Exception("Underlying object is not a sort"); - super.CheckNativeObject(obj); - } - - static Sort Create(Context ctx, IntPtr obj) - { - - - - switch ((Z3_sort_kind)Native.getSortKind(ctx.nCtx, obj)) - { - case Z3_sort_kind.Z3_ARRAY_SORT: return new ArraySort(ctx, obj); - case Z3_sort_kind.Z3_BOOL_SORT: return new BoolSort(ctx, obj); - case Z3_sort_kind.Z3_BV_SORT: return new BitVecSort(ctx, obj); - case Z3_sort_kind.Z3_DATATYPE_SORT: return new DatatypeSort(ctx, obj); - case Z3_sort_kind.Z3_INT_SORT: return new IntSort(ctx, obj); - case Z3_sort_kind.Z3_REAL_SORT: return new RealSort(ctx, obj); - case Z3_sort_kind.Z3_UNINTERPRETED_SORT: return new UninterpretedSort(ctx, obj); - case Z3_sort_kind.Z3_FINITE_DOMAIN_SORT: return new FiniteDomainSort(ctx, obj); - case Z3_sort_kind.Z3_RELATION_SORT: return new RelationSort(ctx, obj); - default: - throw new Z3Exception("Unknown sort kind"); - } - } - } - - /** - * A Boolean sort. - **/ - public class BoolSort extends Sort - { - BoolSort(Context ctx, IntPtr obj) { super(ctx, obj); } - BoolSort(Context ctx) { super(ctx, Native.mkBooleanSort(ctx.nCtx)); } - }; - - /** - * An arithmetic sort, i.e., Int or Real. - **/ - public class ArithSort extends Sort - { - ArithSort(Context ctx, IntPtr obj) { super(ctx, obj); } - }; - - /** - * An Integer sort - **/ - public class IntSort extends ArithSort - { - IntSort(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - IntSort(Context ctx) - { super(ctx, Native.mkIntSort(ctx.nCtx)); - - } - } - - /** - * A real sort - **/ - public class RealSort extends ArithSort - { - RealSort(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - RealSort(Context ctx) - { super(ctx, Native.mkRealSort(ctx.nCtx)); - - } - } - - /** - * Bit-vector sorts. - **/ - public class BitVecSort extends Sort - { - /** - * The size of the bit-vector sort. - **/ - public long Size() { return Native.getBvSortSize(Context.nCtx, NativeObject); } - - BitVecSort(Context ctx, IntPtr obj) { super(ctx, obj); } - BitVecSort(Context ctx, long size) { super(ctx, Native.mkBvSort(ctx.nCtx, size)); } - }; - - /** - * Array sorts. - **/ - public class ArraySort extends Sort - { - /** - * The domain of the array sort. - **/ - public Sort Domain() { - - - return Sort.Create(Context, Native.getArraySortDomain(Context.nCtx, NativeObject)); } - } - - /** - * The range of the array sort. - **/ - public Sort Range() { - - - return Sort.Create(Context, Native.getArraySortRange(Context.nCtx, NativeObject)); } - } - - ArraySort(Context ctx, IntPtr obj) { super(ctx, obj); } - ArraySort(Context ctx, Sort domain, Sort range) - { super(ctx, Native.mkArraySort(ctx.nCtx, domain.NativeObject, range.NativeObject)); - - - - }; - - /** - * Datatype sorts. - **/ - public class DatatypeSort extends Sort - { - /** - * The number of constructors of the datatype sort. - **/ - public long NumConstructors() { return Native.getDatatypeSortNumConstructors(Context.nCtx, NativeObject); } - - /** - * The constructors. - **/ - public FuncDecl[] Constructors() - { - - - long n = NumConstructors; - FuncDecl[] res = new FuncDecl[n]; - for (long i = 0; i < n; i++) - res[i] = new FuncDecl(Context, Native.getDatatypeSortConstructor(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The recognizers. - **/ - public FuncDecl[] Recognizers() - { - - - long n = NumConstructors; - FuncDecl[] res = new FuncDecl[n]; - for (long i = 0; i < n; i++) - res[i] = new FuncDecl(Context, Native.getDatatypeSortRecognizer(Context.nCtx, NativeObject, i)); - return res; - } - - /** - * The constructor accessors. - **/ - public FuncDecl[][] Accessors() - { - - - long n = NumConstructors; - FuncDecl[][] res = new FuncDecl[n][]; - for (long i = 0; i < n; i++) - { - FuncDecl fd = new FuncDecl(Context, Native.getDatatypeSortConstructor(Context.nCtx, NativeObject, i)); - long ds = fd.DomainSize; - FuncDecl[] tmp = new FuncDecl[ds]; - for (long j = 0; j < ds; j++) - tmp[j] = new FuncDecl(Context, Native.getDatatypeSortConstructorAccessor(Context.nCtx, NativeObject, i, j)); - res[i] = tmp; - } - return res; - } - - DatatypeSort(Context ctx, IntPtr obj) { super(ctx, obj); } - - DatatypeSort(Context ctx, Symbol name, Constructor[] constructors) - { super(ctx, Native.mkDatatype(ctx.nCtx, name.NativeObject, (long)constructors.Length, ArrayToNative(constructors))); - - - - } - }; - - /** - * Uninterpreted Sorts - **/ - public class UninterpretedSort extends Sort - { - UninterpretedSort(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - UninterpretedSort(Context ctx, Symbol s) - { super(ctx, Native.mkUninterpretedSort(ctx.nCtx, s.NativeObject)); - - - } - } - - /** - * Tuple sorts. - **/ - public class TupleSort extends Sort - { - /** - * The constructor function of the tuple. - **/ - public FuncDecl MkDecl() { - - - return new FuncDecl(Context, Native.getTupleSortMkDecl(Context.nCtx, NativeObject)); } - } - - /** - * The number of fields in the tuple. - **/ - public long NumFields() { return Native.getTupleSortNumFields(Context.nCtx, NativeObject); } - - /** - * The field declarations. - **/ - public FuncDecl[] FieldDecls() - { - - - long n = NumFields; - FuncDecl[] res = new FuncDecl[n]; - for (long i = 0; i < n; i++) - res[i] = new FuncDecl(Context, Native.getTupleSortFieldDecl(Context.nCtx, NativeObject, i)); - return res; - } - - TupleSort(Context ctx, Symbol name, long numFields, Symbol[] fieldNames, Sort[] fieldSorts) - { super(ctx); - - - - IntPtr t = IntPtr.Zero; - NativeObject = Native.mkTupleSort(ctx.nCtx, name.NativeObject, numFields, - Symbol.ArrayToNative(fieldNames), AST.ArrayToNative(fieldSorts), - t, new IntPtr[numFields]); - } - }; - - /** - * Enumeration sorts. - **/ - public class EnumSort extends Sort - { - /** - * The function declarations of the constants in the enumeration. - **/ - public FuncDecl[] ConstDecls() { - - - return _constdecls; } - } - - /** - * The constants in the enumeration. - **/ - public Expr[] Consts() { - - - return _consts; } - } - - /** - * The test predicates for the constants in the enumeration. - **/ - public FuncDecl[] TesterDecls() { - - - return _testerdecls; - } - - - private void ObjectInvariant() - { - - - - } - - - - private FuncDecl[] _constdecls = null, _testerdecls = null; - private Expr[] _consts = null; - - EnumSort(Context ctx, Symbol name, Symbol[] enumNames) - { super(ctx); - - - - - int n = enumNames.Length; - IntPtr[] n_constdecls = new IntPtr[n]; - IntPtr[] n_testers = new IntPtr[n]; - NativeObject = Native.mkEnumerationSort(ctx.nCtx, name.NativeObject, (long)n, - Symbol.ArrayToNative(enumNames), n_constdecls, n_testers); - _constdecls = new FuncDecl[n]; - for (long i = 0; i < n; i++) - _constdecls[i] = new FuncDecl(ctx, n_constdecls[i]); - _testerdecls = new FuncDecl[n]; - for (long i = 0; i < n; i++) - _testerdecls[i] = new FuncDecl(ctx, n_testers[i]); - _consts = new Expr[n]; - for (long i = 0; i < n; i++) - _consts[i] = ctx.MkApp(_constdecls[i]); - } - }; - - /** - * List sorts. - **/ - public class ListSort extends Sort - { - /** - * The declaration of the nil function of this list sort. - **/ - public FuncDecl NilDecl() - - return nilDecl; } } - - /** - * The empty list. - **/ - public Expr Nil() - { - - return nilConst; - } - - /** - * The declaration of the isNil function of this list sort. - **/ - public FuncDecl IsNilDecl() - { - - return isNilDecl; - } - - /** - * The declaration of the cons function of this list sort. - **/ - public FuncDecl ConsDecl() - { - - return consDecl; - } - - /** - * The declaration of the isCons function of this list sort. - * - **/ - public FuncDecl IsConsDecl() - { - - return isConsDecl; - } - - /** - * The declaration of the head function of this list sort. - **/ - public FuncDecl HeadDecl() - { - - return headDecl; - } - - /** - * The declaration of the tail function of this list sort. - **/ - public FuncDecl TailDecl() - { - - return tailDecl; - } - - - private void ObjectInvariant() - { - - - - - - - - } - - - - private FuncDecl nilDecl, isNilDecl, consDecl, isConsDecl, headDecl, tailDecl; - private Expr nilConst; - - ListSort(Context ctx, Symbol name, Sort elemSort) - { super(ctx); - - - - - IntPtr inil = IntPtr.Zero, - iisnil = IntPtr.Zero, - icons = IntPtr.Zero, - iiscons = IntPtr.Zero, - ihead = IntPtr.Zero, - itail = IntPtr.Zero; - - NativeObject = Native.mkListSort(ctx.nCtx, name.NativeObject, elemSort.NativeObject, - inil, iisnil, icons, iiscons, ihead, itail); - nilDecl = new FuncDecl(ctx, inil); - isNilDecl = new FuncDecl(ctx, iisnil); - consDecl = new FuncDecl(ctx, icons); - isConsDecl = new FuncDecl(ctx, iiscons); - headDecl = new FuncDecl(ctx, ihead); - tailDecl = new FuncDecl(ctx, itail); - nilConst = ctx.MkConst(nilDecl); - } - }; - - /** - * Relation sorts. - **/ - public class RelationSort extends Sort - { - /** - * The arity of the relation sort. - **/ - public long Arity() { return Native.getRelationArity(Context.nCtx, NativeObject); } - - /** - * The sorts of the columns of the relation sort. - **/ - public Sort[] ColumnSorts() - { - - - if (m_columnSorts != null) - return m_columnSorts; - - long n = Arity; - Sort[] res = new Sort[n]; - for (long i = 0; i < n; i++) - res[i] = Sort.Create(Context, Native.getRelationColumn(Context.nCtx, NativeObject, i)); - return res; - } - - private Sort[] m_columnSorts = null; - - RelationSort(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - } - - /** - * Finite domain sorts. - **/ - public class FiniteDomainSort extends Sort - { - /** - * The size of the finite domain sort. - **/ - public ulong Size() { ulong res = 0; Native.getFiniteDomainSortSize(Context.nCtx, NativeObject, ref res); return res; } - - FiniteDomainSort(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - FiniteDomainSort(Context ctx, Symbol name, ulong size) - { super(ctx, Native.mkFiniteDomainSort(ctx.nCtx, name.NativeObject, size)); - - - - } - } - - /** - * Set sorts. - **/ - public class SetSort extends Sort - { - SetSort(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - SetSort(Context ctx, Sort ty) - { super(ctx, Native.mkSetSort(ctx.nCtx, ty.NativeObject)); - - - } - } diff --git a/src/api/java/com/Microsoft/Z3/Statistics.java b/src/api/java/com/Microsoft/Z3/Statistics.java deleted file mode 100644 index d9aac9d67..000000000 --- a/src/api/java/com/Microsoft/Z3/Statistics.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * This file was automatically generated from Statistics.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Objects of this class track statistical information about solvers. - **/ - public class Statistics extends Z3Object - { - /** - * Statistical data is organized into pairs of [Key, Entry], where every - * Entry is either a DoubleEntry or a UIntEntry - **/ - public class Entry - { - /** - * The key of the entry. - **/ - /** - * The uint-value of the entry. - **/ - public long UIntValue() { return m_long; } - /** - * The double-value of the entry. - **/ - public double DoubleValue() { return m_double; } - /** - * True if the entry is uint-valued. - **/ - public boolean IsUInt() { return m_is_long; } - /** - * True if the entry is double-valued. - **/ - public boolean IsDouble() { return m_is_double; } - - /** - * The string representation of the the entry's value. - **/ - public String Value() - { - - - if (IsUInt) - return m_long.toString(); - else if (IsDouble) - return m_double.toString(); - else - throw new Z3Exception("Unknown statistical entry type"); - } - - /** - * The string representation of the Entry. - **/ - public String toString() - { - return Key + ": " + Value; - } - - private boolean m_is_long = false; - private boolean m_is_double = false; - private long m_long = 0; - private double m_double = 0.0; - Entry(String k, long v) { Key = k; m_is_long = true; m_long = v; } - Entry(String k, double v) { Key = k; m_is_double = true; m_double = v; } - } - - /** - * A string representation of the statistical data. - **/ - public String toString() - { - return Native.statstoString(Context.nCtx, NativeObject); - } - - /** - * The number of statistical data. - **/ - public long Size() { return Native.statsSize(Context.nCtx, NativeObject); } - - /** - * The data entries. - **/ - public Entry[] Entries() - { - - - - - long n = Size; - Entry[] res = new Entry[n]; - for (long i = 0; i < n; i++) - { - Entry e; - String k = Native.statsGetKey(Context.nCtx, NativeObject, i); - if (Native.statsIsLong(Context.nCtx, NativeObject, i) != 0) - e = new Entry(k, Native.statsGetLongValue(Context.nCtx, NativeObject, i)); - else if (Native.statsIsDouble(Context.nCtx, NativeObject, i) != 0) - e = new Entry(k, Native.statsGetDoubleValue(Context.nCtx, NativeObject, i)); - else - throw new Z3Exception("Unknown data entry value"); - res[i] = e; - } - return res; - } - - /** - * The statistical counters. - **/ - public String[] Keys() - { - - - long n = Size; - String[] res = new String[n]; - for (long i = 0; i < n; i++) - res[i] = Native.statsGetKey(Context.nCtx, NativeObject, i); - return res; - } - - /** - * The value of a particular statistical counter. - * Returns null if the key is unknown. - **/ - public Entry get(String key) - { - long n = Size; - Entry[] es = Entries; - for (long i = 0; i < n; i++) - if (es[i].Key == key) - return es[i]; - return null; - } - - Statistics(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.statsIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.statsDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.Statistics_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.Statistics_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Status.java b/src/api/java/com/Microsoft/Z3/Status.java deleted file mode 100644 index 86c902285..000000000 --- a/src/api/java/com/Microsoft/Z3/Status.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * This file was automatically generated from Status.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Status values. - **/ - /** - * Used to signify an unsatisfiable status. - **/ - UNSATISFIABLE = -1, - - /** - * Used to signify an unknown status. - **/ - UNKNOWN = 0, - - /** - * Used to signify a satisfiable status. - **/ - SATISFIABLE = 1 - diff --git a/src/api/java/com/Microsoft/Z3/Symbol.java b/src/api/java/com/Microsoft/Z3/Symbol.java deleted file mode 100644 index 972999e66..000000000 --- a/src/api/java/com/Microsoft/Z3/Symbol.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * This file was automatically generated from Symbol.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ -/* using System.Runtime.InteropServices; */ - - /** - * Symbols are used to name several term and type constructors. - **/ - public class Symbol extends Z3Object - { - /** - * The kind of the symbol (int or string) - **/ - protected Z3_symbol_kind Kind - { - get { return (Z3_symbol_kind)Native.getSymbolKind(Context.nCtx, NativeObject); } - } - - /** - * Indicates whether the symbol is of Int kind - **/ - public boolean IsIntSymbol() - { - return Kind == Z3_symbol_kind.Z3_INT_SYMBOL; - } - - /** - * Indicates whether the symbol is of string kind. - **/ - public boolean IsStringSymbol() - { - return Kind == Z3_symbol_kind.Z3_STRING_SYMBOL; - } - - /** - * A string representation of the symbol. - **/ - public String toString() - { - if (IsIntSymbol()) - return ((IntSymbol)this).Int.toString(); - else if (IsStringSymbol()) - return ((StringSymbol)this).String; - else - throw new Z3Exception("Unknown symbol kind encountered"); - } - - /** - * Symbol constructor - **/ - protected Symbol(Context ctx, IntPtr obj) { super(ctx, obj); - - } - - static Symbol Create(Context ctx, IntPtr obj) - { - - - - switch ((Z3_symbol_kind)Native.getSymbolKind(ctx.nCtx, obj)) - { - case Z3_symbol_kind.Z3_INT_SYMBOL: return new IntSymbol(ctx, obj); - case Z3_symbol_kind.Z3_STRING_SYMBOL: return new StringSymbol(ctx, obj); - default: - throw new Z3Exception("Unknown symbol kind encountered"); - } - } - } - - /** - * Numbered symbols - **/ - public class IntSymbol extends Symbol - { - /** - * The int value of the symbol. - * Throws an exception if the symbol is not of int kind. - **/ - public int Int() - { - if (!IsIntSymbol()) - throw new Z3Exception("Int requested from non-Int symbol"); - return Native.getSymbolInt(Context.nCtx, NativeObject); - } - - IntSymbol(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - IntSymbol(Context ctx, int i) - { super(ctx, Native.mkIntSymbol(ctx.nCtx, i)); - - } - - void CheckNativeObject(IntPtr obj) - { - if ((Z3_symbol_kind)Native.getSymbolKind(Context.nCtx, obj) != Z3_symbol_kind.Z3_INT_SYMBOL) - throw new Z3Exception("Symbol is not of integer kind"); - super.CheckNativeObject(obj); - } - } - - /** - * Named symbols - **/ - public class StringSymbol extends Symbol - { - /** - * The string value of the symbol. - * Throws an exception if the symbol is not of string kind. - **/ - public String String() - { - - - if (!IsStringSymbol()) - throw new Z3Exception("String requested from non-String symbol"); - return Native.getSymbolString(Context.nCtx, NativeObject); - } - - StringSymbol(Context ctx, IntPtr obj) { super(ctx, obj); - - } - - StringSymbol(Context ctx, String s) { super(ctx, Native.mkStringSymbol(ctx.nCtx, s)); - - } - - void CheckNativeObject(IntPtr obj) - { - if ((Z3_symbol_kind)Native.getSymbolKind(Context.nCtx, obj) != Z3_symbol_kind.Z3_STRING_SYMBOL) - throw new Z3Exception("Symbol is not of String kind"); - - super.CheckNativeObject(obj); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Tactic.java b/src/api/java/com/Microsoft/Z3/Tactic.java deleted file mode 100644 index ae74c3a6b..000000000 --- a/src/api/java/com/Microsoft/Z3/Tactic.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * This file was automatically generated from Tactic.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Tactics are the basic building block for creating custom solvers for specific problem domains. - * The complete list of tactics may be obtained using Context.NumTactics - * and Context.TacticNames. - * It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. - **/ - public class Tactic extends Z3Object - { - /** - * A string containing a description of parameters accepted by the tactic. - **/ - public String Help() - { - - - return Native.tacticGetHelp(Context.nCtx, NativeObject); - } - - - /** - * Retrieves parameter descriptions for Tactics. - **/ - public ParamDescrs ParameterDescriptions() { return new ParamDescrs(Context, Native.tacticGetParamDescrs(Context.nCtx, NativeObject)); } - - - /** - * Execute the tactic over the goal. - **/ - public ApplyResult Apply(Goal g, Params p) - { - - - - Context.CheckContextMatch(g); - if (p == null) - return new ApplyResult(Context, Native.tacticApply(Context.nCtx, NativeObject, g.NativeObject)); - else - { - Context.CheckContextMatch(p); - return new ApplyResult(Context, Native.tacticApplyEx(Context.nCtx, NativeObject, g.NativeObject, p.NativeObject)); - } - } - - /** - * Apply the tactic to a goal. - **/ - public ApplyResult get(Goal g) - { - - - - return Apply(g); - } - - /** - * Creates a solver that is implemented using the given tactic. - * - **/ - public Solver Solver() - { - - - return Context.MkSolver(this); - } - - Tactic(Context ctx, IntPtr obj) - { super(ctx, obj); - - } - Tactic(Context ctx, String name) - { super(ctx, Native.mkTactic(ctx.nCtx, name)); - - } - - class DecRefQueue extends Z3.DecRefQueue - { - public void IncRef(Context ctx, IntPtr obj) - { - Native.tacticIncRef(ctx.nCtx, obj); - } - - public void DecRef(Context ctx, IntPtr obj) - { - Native.tacticDecRef(ctx.nCtx, obj); - } - }; - - void IncRef(IntPtr o) - { - Context.Tactic_DRQ.IncAndClear(Context, o); - super.IncRef(o); - } - - void DecRef(IntPtr o) - { - Context.Tactic_DRQ.Add(o); - super.DecRef(o); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Version.class b/src/api/java/com/Microsoft/Z3/Version.class deleted file mode 100644 index 472674ff6..000000000 Binary files a/src/api/java/com/Microsoft/Z3/Version.class and /dev/null differ diff --git a/src/api/java/com/Microsoft/Z3/Version.java b/src/api/java/com/Microsoft/Z3/Version.java deleted file mode 100644 index 8038f02d5..000000000 --- a/src/api/java/com/Microsoft/Z3/Version.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * This file was automatically generated from Version.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Version information. - * Note that this class is static. - **/ - public final class Version - { - Version() { } - - /** - * The major version - **/ - public long Major() - { - long major = 0, minor = 0, build = 0, revision = 0; - Native.getVersion(major, minor, build, revision); - return major; - } - - /** - * The minor version - **/ - public long Minor() - { - long major = 0, minor = 0, build = 0, revision = 0; - Native.getVersion(major, minor, build, revision); - return minor; - } - - /** - * The build version - **/ - public long Build() - { - long major = 0, minor = 0, build = 0, revision = 0; - Native.getVersion(major, minor, build, revision); - return build; - } - - /** - * The revision - **/ - public long Revision() - { - long major = 0, minor = 0, build = 0, revision = 0; - Native.getVersion(major, minor, build, revision); - return revision; - } - - /** - * A string representation of the version information. - **/ - public String toString() - { - - - long major = 0, minor = 0, build = 0, revision = 0; - Native.getVersion(major, minor, build, revision); - return major.toString() + "." + minor.toString() + "." + build.toString() + "." + revision.toString(); - } - } diff --git a/src/api/java/com/Microsoft/Z3/Z3Exception.java b/src/api/java/com/Microsoft/Z3/Z3Exception.java deleted file mode 100644 index 0e05add87..000000000 --- a/src/api/java/com/Microsoft/Z3/Z3Exception.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * This file was automatically generated from Z3Exception.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * The exception base class for error reporting from Z3 - **/ - public class Z3Exception extends Exception - { - /** - * Constructor. - **/ - public Z3Exception() { super(); } - - /** - * Constructor. - **/ - public Z3Exception(String message) { super(message); } - - /** - * Constructor. - **/ - public Z3Exception(String message, System.Exception inner) { super(message, inner); } - } diff --git a/src/api/java/com/Microsoft/Z3/Z3Object.java b/src/api/java/com/Microsoft/Z3/Z3Object.java deleted file mode 100644 index ca4258980..000000000 --- a/src/api/java/com/Microsoft/Z3/Z3Object.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * This file was automatically generated from Z3Object.cs - **/ - -package com.Microsoft.Z3; - -/* using System; */ - - /** - * Internal base class for interfacing with native Z3 objects. - * Should not be used externally. - **/ - public class Z3Object extends IDisposable - { - /** - * Finalizer. - **/ - protected void finalize() - { - Dispose(); - } - - /** - * Disposes of the underlying native Z3 object. - **/ - public void Dispose() - { - if (m_n_obj != IntPtr.Zero) - { - DecRef(m_n_obj); - m_n_obj = IntPtr.Zero; - } - - if (m_ctx != null) - { - m_ctx.refCount--; - if (m_ctx.refCount == 0) - GC.ReRegisterForFinalize(m_ctx); - m_ctx = null; - } - - GC.SuppressFinalize(this); - } - - - private void ObjectInvariant() - { - - } - - - private Context m_ctx = null; - private IntPtr m_n_obj = IntPtr.Zero; - - Z3Object(Context ctx) - { - - - ctx.refCount++; - m_ctx = ctx; - } - - Z3Object(Context ctx, IntPtr obj) - { - - - ctx.refCount++; - m_ctx = ctx; - IncRef(obj); - m_n_obj = obj; - } - - void IncRef(IntPtr o) { } - void DecRef(IntPtr o) { } - - void CheckNativeObject(IntPtr obj) { } - - IntPtr NativeObject - { - get { return m_n_obj; } - set - { - if (value != IntPtr.Zero) { CheckNativeObject(value); IncRef(value); } - if (m_n_obj != IntPtr.Zero) { DecRef(m_n_obj); } - m_n_obj = value; - } - } - - static IntPtr GetNativeObject(Z3Object s) - { - if (s == null) return new IntPtr(); - return s.NativeObject; - } - - Context Context - { - get - { - - return m_ctx; - } - } - - static IntPtr[] ArrayToNative(Z3Object[] a) - { - - - - if (a == null) return null; - IntPtr[] an = new IntPtr[a.Length]; - for (long i = 0; i < a.Length; i++) - if (a[i] != null) an[i] = a[i].NativeObject; - return an; - } - - static long ArrayLength(Z3Object[] a) - { - return (a == null)?0:(long)a.Length; - } - } diff --git a/src/api/java/mk_java.py b/src/api/java/mk_java.py index a2cc51274..1c59fc957 100644 --- a/src/api/java/mk_java.py +++ b/src/api/java/mk_java.py @@ -11,14 +11,29 @@ CS="../dotnet/" EXT=".cs" EXCLUDE=["Enumerations.cs", "Native.cs", "AssemblyInfo.cs"] OUTDIR="com/Microsoft/Z3/" +ENUMS_FILE = "Enumerations.cs" import os import fileinput import string import re +EXCLUDE_METHODS = [ [ "Context.cs", "public Expr MkNumeral(ulong" ], + [ "Context.cs", "public Expr MkNumeral(uint" ], + [ "Context.cs", "public RatNum MkReal(ulong" ], + [ "Context.cs", "public RatNum MkReal(uint" ], + [ "Context.cs", "public IntNum MkInt(ulong" ], + [ "Context.cs", "public IntNum MkInt(uint" ], + [ "Context.cs", "public BitVecNum MkBV(ulong" ], + [ "Context.cs", "public BitVecNum MkBV(uint" ], + ] + +ENUMS = [] + def mk_java_bindings(): - print "Generating Java bindings (from C# bindings in " + CS + ")." + print "Generating Java bindings (from C# bindings in " + CS + ")..." + print "Finding enumerations in " + ENUMS_FILE + "..." + find_enums(ENUMS_FILE) for root, dirs, files in os.walk(CS): for fn in files: if not fn in EXCLUDE and fn.endswith(EXT): @@ -29,9 +44,17 @@ def subst_getters(s, getters): s = s.replace(g, g + "()") def type_replace(s): - s = s.replace("bool", "boolean") - s = s.replace("uint", "long") + s = s.replace(" bool", " boolean") + s = s.replace("(bool", "(boolean") + s = s.replace("uint", "int") + s = s.replace("ulong", "long") s = s.replace("string", "String") + s = s.replace("IntPtr", "long") + s = s.replace("Dictionary<", "Map<") + s = s.replace("UInt64", "long") + s = s.replace("Int64", "long") + s = s.replace("List", "LinkedList") + s = s.replace("System.Exception", "Exception") return s def rename_native(s): @@ -47,6 +70,55 @@ def rename_native(s): s = c0 + c1 + c2 return s +def find_enums(fn): + for line in fileinput.input(os.path.join(CS, fn)): + s = string.rstrip(string.lstrip(line)) + if s.startswith("public enum"): + ENUMS.append(s.split(" ")[2]) + + +def enum_replace(line): + for e in ENUMS: + if line.find("case") != -1: + line = line.replace(e + ".", "") + elif line.find("== (int)") != -1 or line.find("!= (int)") != -1: + line = re.sub("\(int\)" + e + "\.(?P[A-Z0-9_]*)", e + ".\g.toInt()", line) + elif line.find("==") != -1 or line.find("!=") != -1: + line = re.sub(e + "\.(?P[A-Z0-9_]*)", e + ".\g", line) + else: + # line = re.sub("\(\(" + e + "\)(?P.*\(.*)\)", "(" + e + ".values()[\g])", line) + line = re.sub("\(" + e + "\)(?P.*\(.*\))", e + ".fromInt(\g)", line) + return line + +def replace_generals(a): + a = re.sub(" NativeObject", " NativeObject()", a) + a = re.sub("\.NativeObject", ".NativeObject()", a) + a = re.sub("(?P[\.\(])Id", "\gId()", a) + a = a.replace("(Context ==", "(Context() ==") + a = a.replace("(Context,", "(Context(),") + a = a.replace("Context.", "Context().") + a = a.replace(".nCtx", ".nCtx()") + a = a.replace("(nCtx", "(nCtx()") + a = re.sub("Context\(\).(?P[^_]*)_DRQ", "Context().\g_DRQ()", a) + a = re.sub("ASTKind", "ASTKind()", a) + a = re.sub("IsExpr(?P[ ;])", "IsExpr()\g", a) + a = re.sub("IsNumeral(?P[ ;])", "IsNumeral()\g", a) + a = re.sub("IsInt(?P[ ;])", "IsInt()\g", a) + a = re.sub("IsReal(?P[ ;])", "IsReal()\g", a) + a = re.sub("IsVar(?P[ ;\)])", "IsVar()\g", a) + a = re.sub("FuncDecl.DeclKind", "FuncDecl().DeclKind()", a) + a = re.sub("FuncDecl.DomainSize", "FuncDecl().DomainSize()", a) + a = re.sub("(?P[=&]) Num(?P[a-zA-Z]*)", "\g Num\g()", a) + a = re.sub("= Denominator", "= Denominator()", a) + a = re.sub(", BoolSort(?P[\)\.])", ", BoolSort()\g", a) + a = re.sub(", RealSort(?P[\)\.])", ", RealSort()\g", a) + a = re.sub(", IntSort(?P[\)\.])", ", IntSort()\g", a) + a = a.replace("? 1 : 0", "? true : false") + if a.find("Native.") != -1 and a.find("!= 0") != -1: + a = a.replace("!= 0", "") + if a.find("Native.") != -1 and a.find("== 0") != -1: + a = a.replace("== 0", "^ true") + return a def translate(filename): tgtfn = OUTDIR + filename.replace(EXT, ".java") @@ -65,6 +137,10 @@ def translate(filename): in_bracket_op = 0 in_getter_get = 0 in_getter_set = 0 + had_ulong_res = 0 + in_enum = 0 + missing_foreach_brace = 0 + foreach_opened_brace = 0 for line in fileinput.input(os.path.join(CS, filename)): s = string.rstrip(string.lstrip(line)) if in_javadoc: @@ -87,6 +163,13 @@ def translate(filename): tgt.write(t + " **/\n") in_javadoc = 0 + # for i in range(0, len(EXCLUDE_METHODS)): + # if filename == EXCLUDE_METHODS[i][0] and s.startswith(EXCLUDE_METHODS[i][1]): + # tgt.write(t + "/* Not translated because it would translate to a function with clashing types. */\n") + # in_unsupported = 1 + # break + + if in_unsupported: if s == "}": in_unsupported = 0 @@ -98,8 +181,11 @@ def translate(filename): in_header = 0 tgt.write(" * This file was automatically generated from " + filename + " \n") tgt.write(" **/\n") - tgt.write("\npackage com.Microsoft.Z3;\n") - + tgt.write("\npackage com.Microsoft.Z3;\n\n") + tgt.write("import java.math.BigInteger;\n") + tgt.write("import java.util.*;\n") + tgt.write("import java.lang.Exception;\n") + tgt.write("import com.Microsoft.Z3.Enumerations.*;\n") elif in_header == 1: # tgt.write(" * " + line.replace(filename, tgtfn)) pass @@ -113,10 +199,21 @@ def translate(filename): for i in range(0, line.find(s)+1): t += " " tgt.write(t + "/* Overloaded operators are not translated. */\n") - in_unsupported = 1; + in_unsupported = 1 + elif s.startswith("public enum"): + tgt.write(line.replace("enum", "class")) + in_enum = 1 + elif in_enum == 1: + if s == "}": + tgt.write(line) + in_enum = 0 + else: + line = re.sub("(?P.*)\W*=\W*(?P[^\n,])", "public static final int \g = \g;", line) + tgt.write(line.replace(",","")) elif s.startswith("public class") or s.startswith("internal class") or s.startswith("internal abstract class"): a = line.replace(":", "extends").replace("internal ", "") a = a.replace(", IComparable", "") + a = type_replace(a) tgt.write(a) in_class = 1 in_static_class = 0 @@ -129,10 +226,13 @@ def translate(filename): in_javadoc = 1 elif skip_brace and s == "{": skip_brace = 0 - elif s.find("public") != -1 and s.find("class") == -1 and s.find("event") == -1 and s.find("(") == -1: + elif ((s.find("public") != -1 or s.find("protected") != -1) and s.find("class") == -1 and s.find("event") == -1 and s.find("(") == -1) or s.startswith("internal virtual IntPtr NativeObject") or s.startswith("internal Context Context"): if (s.startswith("new")): s = s[3:] + s = s.replace("internal virtual", "") + s = s.replace("internal", "") tokens = s.split(" ") + # print "TOKENS: " + str(len(tokens)) if len(tokens) == 3: in_getter = tokens[2] in_getter_type = type_replace((tokens[0] + " " + tokens[1])) @@ -140,6 +240,7 @@ def translate(filename): in_getter_type = in_getter_type.replace("static", "") lastindent = line.find(s) skip_brace = 1 + getters.append(in_getter) elif len(tokens) == 4: if tokens[2].startswith("this["): in_bracket_op = 1 @@ -152,21 +253,36 @@ def translate(filename): if in_static_class: in_getter_type = in_getter_type.replace("static", "") lastindent = line.find(s) - skip_brace = 1 + skip_brace = 1 + getters.append(in_getter) else: in_getter = tokens[2] in_getter_type = type_replace(tokens[0] + " " + tokens[1]) - if in_static_class: - in_getter_type = in_getter_type.replace("static", "") - rest = s[s.find("get ") + 4:-1] - subst_getters(rest, getters) - rest = type_replace(rest) - rest = rename_native(rest) - t = "" - for i in range(0, lastindent): - t += " " - tgt.write(t + in_getter_type + " " + in_getter + "() " + rest + "\n") - getters.append(in_getter) + if tokens[2].startswith("this["): + lastindent = line.find(s) + t = "" + for i in range(0, lastindent): t += " " + tgt.write(t + "/* operator this[] not translated */\n ") + in_unsupported = 1 + else: + if in_static_class: + in_getter_type = in_getter_type.replace("static", "") + rest = s[s.find("get ") + 4:-1] + subst_getters(rest, getters) + rest = type_replace(rest) + rest = rename_native(rest) + rest = replace_generals(rest) + rest = enum_replace(rest) + t = "" + for i in range(0, lastindent): + t += " " + tgt.write(t + in_getter_type + " " + in_getter + "() " + rest + "\n") + if rest.find("}") == -1: + in_getter_get = 1 + else: + getters.append(in_getter) + in_getter = "" + in_getter_type = "" print "ACC: " + s + " --> " + in_getter elif s.find("{ get {") != -1: line = type_replace(line) @@ -177,6 +293,8 @@ def translate(filename): rest = re.sub("Contract.\w+\([\s\S]*\);", "", rest) subst_getters(rest, getters) rest = rename_native(rest) + rest = replace_generals(rest) + rest = enum_replace(rest) if in_bracket_op: tgt.write(d + rest) else: @@ -185,12 +303,14 @@ def translate(filename): elif in_getter != "" and s.startswith("get"): t = "" for i in range(0, lastindent): - t += " " + t += " " if len(s) > 3: rest = s[3:] else: rest = "" subst_getters(rest, getters) rest = type_replace(rest) rest = rename_native(rest) + rest = replace_generals(rest) + rest = enum_replace(rest) if in_bracket_op: tgt.write(t + in_getter_type + " " + in_getter + " " + rest + "\n") else: @@ -207,6 +327,8 @@ def translate(filename): rest = rest.replace("(Integer)value", "Integer(value)") rest = type_replace(rest) rest = rename_native(rest) + rest = replace_generals(rest) + rest = enum_replace(rest) ac_acc = in_getter_type[:in_getter_type.find(' ')] ac_type = in_getter_type[in_getter_type.find(' ')+1:] if in_bracket_op: @@ -216,13 +338,13 @@ def translate(filename): tgt.write(t + ac_acc + " void set" + in_getter + "(" + ac_type + " value) " + rest + "\n") if rest.find("}") == -1: in_getter_set = 1 - elif in_getter != "" and in_getter_get and s == "}": + elif in_getter != "" and in_getter_get == 1 and s == "}": tgt.write(line) in_getter_get = 0 - elif in_getter != "" and in_getter_set and s == "}": + elif in_getter != "" and in_getter_set == 1 and s == "}": tgt.write(line) in_getter_set = 0 - elif in_getter != "" and not in_getter_get and not in_getter_set and s == "}": + elif in_getter != "" and in_getter_get == 0 and in_getter_set == 0 and s == "}": in_getter = "" in_getter_type == "" in_bracket_op = 0 @@ -232,48 +354,103 @@ def translate(filename): line = re.sub("(?P\w+)(?P[,;])", "\g\g", line) tgt.write(line); elif (not in_class and (s.startswith("{") or s.startswith("}"))) or s.startswith("[") or s.startswith("#"): - # print "Skipping: " + s; + # tgt.write("// Skipping: " + s) pass elif line == "}\n": pass else: # indent = line.find(s) + # tgt.write("// LINE: " + line) if line.find(": base") != -1: - line = re.sub(": base\((?P

[\w,.\(\) ]*)\)", "{ super(\g

);", line) - if line.find("; {") != -1: - line = line.replace("; {", ";") + line = re.sub(": base\((?P

[^\{]*)\)", "{ super(\g

);", line) + line = line[4:] + obraces = line.count("{") + cbraces = line.count("}") + mbraces = obraces - cbraces + # tgt.write("// obraces = " + str(obraces) + "\n") + if obraces == 1: + skip_brace = 1 else: - skip_brace = 1 - if s.startswith("public"): + for i in range(0, mbraces): + line = line.replace("\n", "}\n") + if (s.find("public") != -1 or s.find("protected") != -1 or s.find("internal") != -1) and s.find("(") != -1: line = re.sub(" = [\w.]+(?P[,;\)])", "\g", line) a = type_replace(line) + a = enum_replace(a) a = re.sub("(?P[\(, ])params ", "\g", a) a = a.replace("base.", "super.") a = re.sub("Contract.\w+\([\s\S]*\);", "", a) a = rename_native(a) a = re.sub("~\w+\(\)", "protected void finalize()", a) + + if missing_foreach_brace == 1: + # a = a.replace("\n", " // checked " + str(foreach_opened_brace) + "\n") + if foreach_opened_brace == 0 and a.find("{") != -1: + foreach_opened_brace = 1 + elif foreach_opened_brace == 0 and a.find("}") == -1: + a = a.replace("\n", "}}\n") + foreach_opened_brace = 0 + missing_foreach_brace = 0 + elif foreach_opened_brace == 1 and a.find("}") != -1: + a = a.replace("\n", "}}\n") + foreach_opened_brace = 0 + missing_foreach_brace = 0 + +# if a.find("foreach") != -1: +# missing_foreach_brace = 1 +# a = re.sub("foreach\s*\((?P[\w <>,]+)\s+(?P\w+)\s+in\s+(?P\w+)\)", + # "{ Iterator fe_i = \g.iterator(); while (fe_i.hasNext()) { \g \g = (long)fe_i.next(); ", +# a) a = re.sub("foreach\s*\((?P[\w <>,]+)\s+(?P\w+)\s+in\s+(?P\w+)\)", - "for (\g.Iterator \g = \g.iterator(); \g.hasNext(); )", a) + "for (\g \g: \g)", + a) + if a.find("long o: m_queue") != -1: + a = a.replace("long", "Long") a = a.replace("readonly ", "") a = a.replace("const ", "final ") - a = a.replace("ToString", "toString") + a = a.replace("String ToString", "String toString") + a = a.replace(".ToString", ".toString") a = a.replace("internal ", "") a = a.replace("new static", "static") a = a.replace("new public", "public") a = a.replace("override ", "") a = a.replace("virtual ", "") a = a.replace("o as AST", "(AST) o") + a = a.replace("o as Sort", "(Sort) o") a = a.replace("other as AST", "(AST) other") a = a.replace("o as FuncDecl", "(FuncDecl) o") + a = a.replace("IntPtr obj", "long obj") + a = a.replace("IntPtr o", "long o") + a = a.replace("new long()", "0") + a = a.replace("long.Zero", "0") + a = a.replace("object o", "Object o") + a = a.replace("object other", "Object other") a = a.replace("IntPtr res = IntPtr.Zero;", "Native.IntPtr res = new Native.IntPtr();") a = a.replace("out res", "res") + a = a.replace("GC.ReRegisterForFinalize(m_ctx);", "") + a = a.replace("GC.SuppressFinalize(this);", "") + a = a.replace(".Length", ".length") + a = a.replace("m_queue.Count", "m_queue.size()") + a = a.replace("m_queue.Add", "m_queue.add") + a = a.replace("m_queue.Clear", "m_queue.clear") + a = a.replace("for (long ", "for (int ") + a = a.replace("ReferenceEquals(Context, ctx)", "Context() == ctx") + a = a.replace("BigInteger.Parse", "new BigInteger") + if had_ulong_res == 0 and a.find("ulong res = 0") != -1: + a = a.replace("ulong res = 0;", "LongPtr res = new LongPtr();") + elif had_ulong_res == 1: + a = a.replace("ref res)", "res)") + if a.find("return res;") != -1: + a = a.replace("return res;", "return res.value;") + had_ulong_res = 0 a = a.replace("lock (", "synchronized (") if in_static_class: a = a.replace("static", "") a = re.sub("ref (?P\w+)", "\g", a) subst_getters(a, getters) + a = re.sub("NativeObject = (?P.*);", "setNativeObject(\g);", a) + a = replace_generals(a) tgt.write(a) - tgt.close() mk_java_bindings() diff --git a/src/api/python/z3.py b/src/api/python/z3.py index a71db82c5..84724e51e 100644 --- a/src/api/python/z3.py +++ b/src/api/python/z3.py @@ -635,7 +635,7 @@ class FuncDeclRef(AstRef): args = _get_args(args) num = len(args) if __debug__: - _z3_assert(num == self.arity(), "Incorrect number of arguments") + _z3_assert(num == self.arity(), "Incorrect number of arguments to %s" % self) _args = (Ast * num)() saved = [] for i in range(num): @@ -1735,7 +1735,7 @@ class ArithSortRef(SortRef): """Real and Integer sorts.""" def is_real(self): - """Return `True` if `self` is the integer sort. + """Return `True` if `self` is of the sort Real. >>> x = Real('x') >>> x.is_real() @@ -1749,7 +1749,7 @@ class ArithSortRef(SortRef): return self.kind() == Z3_REAL_SORT def is_int(self): - """Return `True` if `self` is the real sort. + """Return `True` if `self` is of the sort Integer. >>> x = Int('x') >>> x.is_int() diff --git a/src/ast/array_decl_plugin.h b/src/ast/array_decl_plugin.h index bd1e123e3..68c473560 100644 --- a/src/ast/array_decl_plugin.h +++ b/src/ast/array_decl_plugin.h @@ -144,7 +144,21 @@ public: bool is_map(expr* n) const { return is_app_of(n, m_fid, OP_ARRAY_MAP); } bool is_as_array(expr * n) const { return is_app_of(n, m_fid, OP_AS_ARRAY); } bool is_as_array_tree(expr * n); + bool is_select(func_decl* f) const { return is_decl_of(f, m_fid, OP_SELECT); } + bool is_store(func_decl* f) const { return is_decl_of(f, m_fid, OP_STORE); } + bool is_const(func_decl* f) const { return is_decl_of(f, m_fid, OP_CONST_ARRAY); } + bool is_map(func_decl* f) const { return is_decl_of(f, m_fid, OP_ARRAY_MAP); } + bool is_as_array(func_decl* f) const { return is_decl_of(f, m_fid, OP_AS_ARRAY); } func_decl * get_as_array_func_decl(app * n) const { SASSERT(is_as_array(n)); return to_func_decl(n->get_decl()->get_parameter(0).get_ast()); } + + app * mk_store(unsigned num_args, expr * const * args) { + return m_manager.mk_app(m_fid, OP_STORE, 0, 0, num_args, args); + } + + app * mk_select(unsigned num_args, expr * const * args) { + return m_manager.mk_app(m_fid, OP_SELECT, 0, 0, num_args, args); + } + app * mk_map(func_decl * f, unsigned num_args, expr * const * args) { parameter p(f); return m_manager.mk_app(m_fid, OP_ARRAY_MAP, 1, &p, num_args, args); diff --git a/src/ast/ast_smt_pp.cpp b/src/ast/ast_smt_pp.cpp index 713727f05..78a1caf68 100644 --- a/src/ast/ast_smt_pp.cpp +++ b/src/ast/ast_smt_pp.cpp @@ -67,8 +67,13 @@ symbol smt_renaming::fix_symbol(symbol s, int k) { buffer << s << k; return symbol(buffer.str().c_str()); } - - buffer << mk_smt2_quoted_symbol(s); + + if (is_smt2_quoted_symbol(s)) { + buffer << mk_smt2_quoted_symbol(s); + } + else { + buffer << s; + } if (k > 0) { buffer << k; } @@ -949,6 +954,10 @@ public: mark.mark(s, true); } + void operator()(sort* s) { + ast_mark mark; + pp_sort_decl(mark, s); + } void operator()(func_decl* d) { if (m_is_smt2) { @@ -962,7 +971,6 @@ public: m_out << ") "; visit_sort(d->get_range()); m_out << ")"; - newline(); } else { m_out << "("; @@ -1021,6 +1029,22 @@ void ast_smt_pp::display_expr_smt2(std::ostream& strm, expr* n, unsigned indent, p(n); } +void ast_smt_pp::display_ast_smt2(std::ostream& strm, ast* a, unsigned indent, unsigned num_var_names, char const* const* var_names) { + ptr_vector ql; + smt_renaming rn; + smt_printer p(strm, m_manager, ql, rn, m_logic, false, true, m_simplify_implies, indent, num_var_names, var_names); + if (is_expr(a)) { + p(to_expr(a)); + } + else if (is_func_decl(a)) { + p(to_func_decl(a)); + } + else { + SASSERT(is_sort(a)); + p(to_sort(a)); + } +} + void ast_smt_pp::display_smt2(std::ostream& strm, expr* n) { ptr_vector ql; @@ -1071,6 +1095,7 @@ void ast_smt_pp::display_smt2(std::ostream& strm, expr* n) { if (!(*m_is_declared)(d)) { smt_printer p(strm, m_manager, ql, rn, m_logic, true, true, m_simplify_implies, 0); p(d); + strm << "\n"; } } @@ -1079,6 +1104,7 @@ void ast_smt_pp::display_smt2(std::ostream& strm, expr* n) { if (!(*m_is_declared)(d)) { smt_printer p(strm, m_manager, ql, rn, m_logic, true, true, m_simplify_implies, 0); p(d); + strm << "\n"; } } diff --git a/src/ast/ast_smt_pp.h b/src/ast/ast_smt_pp.h index 36d4ced2e..97527759a 100644 --- a/src/ast/ast_smt_pp.h +++ b/src/ast/ast_smt_pp.h @@ -79,22 +79,23 @@ public: void display_smt2(std::ostream& strm, expr* n); void display_expr(std::ostream& strm, expr* n); void display_expr_smt2(std::ostream& strm, expr* n, unsigned indent = 0, unsigned num_var_names = 0, char const* const* var_names = 0); + void display_ast_smt2(std::ostream& strm, ast* n, unsigned indent = 0, unsigned num_var_names = 0, char const* const* var_names = 0); }; struct mk_smt_pp { - expr * m_expr; + ast* m_ast; ast_manager& m_manager; unsigned m_indent; unsigned m_num_var_names; char const* const* m_var_names; - mk_smt_pp(expr* e, ast_manager & m, unsigned indent = 0, unsigned num_var_names = 0, char const* const* var_names = 0) : - m_expr(e), m_manager(m), m_indent(indent), m_num_var_names(num_var_names), m_var_names(var_names) {} + mk_smt_pp(ast* e, ast_manager & m, unsigned indent = 0, unsigned num_var_names = 0, char const* const* var_names = 0) : + m_ast(e), m_manager(m), m_indent(indent), m_num_var_names(num_var_names), m_var_names(var_names) {} }; inline std::ostream& operator<<(std::ostream& out, const mk_smt_pp & p) { ast_smt_pp pp(p.m_manager); - pp.display_expr_smt2(out, p.m_expr, p.m_indent, p.m_num_var_names, p.m_var_names); + pp.display_ast_smt2(out, p.m_ast, p.m_indent, p.m_num_var_names, p.m_var_names); return out; } diff --git a/src/ast/dl_decl_plugin.cpp b/src/ast/dl_decl_plugin.cpp index 76f34f316..5b73f944a 100644 --- a/src/ast/dl_decl_plugin.cpp +++ b/src/ast/dl_decl_plugin.cpp @@ -44,8 +44,7 @@ namespace datalog { m_num_sym("N"), m_lt_sym("<"), m_le_sym("<="), - m_rule_sym("R"), - m_hyper_resolve_sym("hyper-res") + m_rule_sym("R") { } diff --git a/src/ast/dl_decl_plugin.h b/src/ast/dl_decl_plugin.h index 6e824b639..32e3c6da9 100644 --- a/src/ast/dl_decl_plugin.h +++ b/src/ast/dl_decl_plugin.h @@ -69,7 +69,6 @@ namespace datalog { symbol m_lt_sym; symbol m_le_sym; symbol m_rule_sym; - symbol m_hyper_resolve_sym; bool check_bounds(char const* msg, unsigned low, unsigned up, unsigned val) const; bool check_domain(unsigned low, unsigned up, unsigned val) const; @@ -93,7 +92,6 @@ namespace datalog { func_decl * mk_compare(decl_kind k, symbol const& sym, sort*const* domain); func_decl * mk_clone(sort* r); func_decl * mk_rule(unsigned arity); - func_decl * mk_hyper_res(unsigned num_params, parameter const* params, unsigned arity, sort *const* domain); sort * mk_finite_sort(unsigned num_params, parameter const* params); sort * mk_relation_sort(unsigned num_params, parameter const* params); diff --git a/src/model/model_evaluator.cpp b/src/model/model_evaluator.cpp index bccade304..258590121 100644 --- a/src/model/model_evaluator.cpp +++ b/src/model/model_evaluator.cpp @@ -147,7 +147,7 @@ struct evaluator_cfg : public default_rewriter_cfg { return m_a_rw.mk_app_core(f, num, args, result); if (fid == m_bv_rw.get_fid()) return m_bv_rw.mk_app_core(f, num, args, result); - if (fid == m_ar_rw.get_fid()) + if (fid == m_ar_rw.get_fid()) return m_ar_rw.mk_app_core(f, num, args, result); if (fid == m_dt_rw.get_fid()) return m_dt_rw.mk_app_core(f, num, args, result); diff --git a/src/muz_qe/dl_context.cpp b/src/muz_qe/dl_context.cpp index 91e396671..f11c9852d 100644 --- a/src/muz_qe/dl_context.cpp +++ b/src/muz_qe/dl_context.cpp @@ -54,6 +54,7 @@ Revision History: #include"expr_functors.h" #include"dl_mk_partial_equiv.h" #include"dl_mk_bit_blast.h" +#include"dl_mk_array_blast.h" #include"datatype_decl_plugin.h" #include"expr_abstract.h" @@ -337,7 +338,7 @@ namespace datalog { expr_ref context::bind_variables(expr* fml, bool is_forall) { expr_ref result(m); - app_ref_vector const& vars = m_vars; + app_ref_vector const & vars = m_vars; if (vars.empty()) { result = fml; } @@ -352,9 +353,19 @@ namespace datalog { svector names; for (unsigned i = 0; i < sorts.size(); ++i) { if (!sorts[i]) { - sorts[i] = vars[i]->get_decl()->get_range(); + if (i < vars.size()) { + sorts[i] = vars[i]->get_decl()->get_range(); + } + else { + sorts[i] = m.mk_bool_sort(); + } + } + if (i < vars.size()) { + names.push_back(vars[i]->get_decl()->get_name()); + } + else { + names.push_back(symbol(i)); } - names.push_back(vars[i]->get_decl()->get_name()); } quantifier_ref q(m); sorts.reverse(); @@ -944,6 +955,7 @@ namespace datalog { transf.register_plugin(alloc(datalog::mk_subsumption_checker, *this, 34880)); transf.register_plugin(alloc(datalog::mk_bit_blast, *this, 35000)); + transf.register_plugin(alloc(datalog::mk_array_blast, *this, 36000)); transform_rules(transf, mc, pc); } @@ -982,6 +994,7 @@ namespace datalog { p.insert(":profile-timeout-milliseconds", CPK_UINT, "instructions and rules that took less than the threshold will not be printed when printed the instruction/rule list"); p.insert(":print-with-fixedpoint-extensions", CPK_BOOL, "(default true) use SMT-LIB2 fixedpoint extensions, instead of pure SMT2, when printing rules"); + p.insert(":print-low-level-smt2", CPK_BOOL, "(default true) use (faster) low-level SMT2 printer (the printer is scalable but the result may not be as readable)"); PRIVATE_PARAMS( p.insert(":dbg-fpr-nonempty-relation-signature", CPK_BOOL, @@ -1638,6 +1651,9 @@ namespace datalog { expr_ref_vector rules(m); svector names; bool use_fixedpoint_extensions = m_params.get_bool(":print-with-fixedpoint-extensions", true); + bool print_low_level = m_params.get_bool(":print-low-level-smt2", true); + +#define PP(_e_) if (print_low_level) out << mk_smt_pp(_e_, m); else ast_smt2_pp(out, _e_, env, params); get_rules_as_formulas(rules, names); @@ -1672,18 +1688,18 @@ namespace datalog { obj_hashtable& sorts = visitor.sorts(); obj_hashtable::iterator sit = sorts.begin(), send = sorts.end(); for (; sit != send; ++sit) { - ast_smt2_pp(out, *sit, env, params); + PP(*sit); } for (; it != end; ++it) { func_decl* f = *it; - ast_smt2_pp(out, f, env, params); + PP(f); out << "\n"; } it = rels.begin(); end = rels.end(); for (; it != end; ++it) { func_decl* f = *it; out << "(declare-rel " << f->get_name() << " ("; - for (unsigned i = 0; i < f->get_arity(); ++i) { + for (unsigned i = 0; i < f->get_arity(); ++i) { ast_smt2_pp(out, f->get_domain(i), env, params); if (i + 1 < f->get_arity()) { out << " "; @@ -1702,7 +1718,7 @@ namespace datalog { for (unsigned i = 0; i < num_axioms; ++i) { out << "(assert "; - ast_smt2_pp(out, axioms[i], env, params); + PP(axioms[i]); out << ")\n"; } for (unsigned i = 0; i < rules.size(); ++i) { @@ -1712,12 +1728,7 @@ namespace datalog { if (symbol::null != nm) { out << "(! "; } - if (use_fixedpoint_extensions) { - ast_smt2_pp(out, r, env, params); - } - else { - out << mk_smt_pp(r, m); - } + PP(r); if (symbol::null != nm) { while (fresh_names.contains(nm)) { std::ostringstream s; @@ -1732,7 +1743,7 @@ namespace datalog { if (use_fixedpoint_extensions) { for (unsigned i = 0; i < num_queries; ++i) { out << "(query "; - ast_smt2_pp(out, queries[i], env, params); + PP(queries[i]); out << ")\n"; } } @@ -1742,7 +1753,7 @@ namespace datalog { out << "(assert "; expr_ref q(m); q = m.mk_not(queries[i]); - ast_smt2_pp(out, q, env, params); + PP(q); out << ")\n"; out << "(check-sat)\n"; if (num_queries > 1) out << "(pop)\n"; diff --git a/src/muz_qe/dl_mk_array_blast.cpp b/src/muz_qe/dl_mk_array_blast.cpp new file mode 100644 index 000000000..d63528db3 --- /dev/null +++ b/src/muz_qe/dl_mk_array_blast.cpp @@ -0,0 +1,147 @@ +/*++ +Copyright (c) 2012 Microsoft Corporation + +Module Name: + + dl_mk_array_blast.cpp + +Abstract: + + Remove array stores from rules. + +Author: + + Nikolaj Bjorner (nbjorner) 2012-11-23 + +Revision History: + +--*/ + +#include "dl_mk_array_blast.h" +#include "expr_replacer.h" + +namespace datalog { + + + mk_array_blast::mk_array_blast(context & ctx, unsigned priority) : + rule_transformer::plugin(priority, false), + m_ctx(ctx), + m(ctx.get_manager()), + a(m), + rm(ctx.get_rule_manager()), + m_rewriter(m, m_params){ + m_params.set_bool(":expand-select-store",true); + m_rewriter.updt_params(m_params); + } + + mk_array_blast::~mk_array_blast() { + } + + bool mk_array_blast::is_store_def(expr* e, expr*& x, expr*& y) { + if (m.is_iff(e, x, y) || m.is_eq(e, x, y)) { + if (!a.is_store(y)) { + std::swap(x,y); + } + if (is_var(x) && a.is_store(y)) { + return true; + } + } + return false; + } + + bool mk_array_blast::blast(rule& r, rule_set& rules) { + unsigned utsz = r.get_uninterpreted_tail_size(); + unsigned tsz = r.get_tail_size(); + expr_ref_vector conjs(m), new_conjs(m); + expr_ref tmp(m); + expr_substitution sub(m); + uint_set lhs_vars, rhs_vars; + bool change = false; + + for (unsigned i = 0; i < utsz; ++i) { + new_conjs.push_back(r.get_tail(i)); + } + for (unsigned i = utsz; i < tsz; ++i) { + conjs.push_back(r.get_tail(i)); + } + flatten_and(conjs); + for (unsigned i = 0; i < conjs.size(); ++i) { + expr* x, *y, *e = conjs[i].get(); + + if (is_store_def(e, x, y)) { + // enforce topological order consistency: + uint_set lhs; + collect_vars(m, x, lhs_vars); + collect_vars(m, y, rhs_vars); + lhs = lhs_vars; + lhs &= rhs_vars; + if (!lhs.empty()) { + TRACE("dl", tout << "unusable equality " << mk_pp(e, m) << "\n";); + new_conjs.push_back(e); + } + else { + sub.insert(x, y); + } + } + else { + m_rewriter(e, tmp); + change = change || (tmp != e); + new_conjs.push_back(tmp); + } + } + if (sub.empty() && !change) { + rules.add_rule(&r); + return false; + } + + rule_ref_vector new_rules(rm); + expr_ref fml1(m), fml2(m), body(m), head(m); + r.to_formula(fml1); + body = m.mk_and(new_conjs.size(), new_conjs.c_ptr()); + head = r.get_head(); + scoped_ptr replace = mk_default_expr_replacer(m); + replace->set_substitution(&sub); + (*replace)(body); + m_rewriter(body); + (*replace)(head); + m_rewriter(head); + fml2 = m.mk_implies(body, head); + rm.mk_rule(fml2, new_rules, r.name()); + SASSERT(new_rules.size() == 1); + + TRACE("dl", tout << "new body " << mk_pp(fml2, m) << "\n";); + + rules.add_rule(new_rules[0].get()); + if (m_pc) { + new_rules[0]->to_formula(fml2); + m_pc->insert(fml1, fml2); + } + return true; + } + + rule_set * mk_array_blast::operator()(rule_set const & source, model_converter_ref& mc, proof_converter_ref& pc) { + ref epc; + if (pc) { + epc = alloc(equiv_proof_converter, m); + } + m_pc = epc.get(); + + rule_set* rules = alloc(rule_set, m_ctx); + rule_set::iterator it = source.begin(), end = source.end(); + bool change = false; + for (; it != end; ++it) { + change = blast(**it, *rules) || change; + } + if (!change) { + dealloc(rules); + rules = 0; + } + if (pc) { + pc = concat(pc.get(), epc.get()); + } + return rules; + } + +}; + + diff --git a/src/muz_qe/dl_mk_array_blast.h b/src/muz_qe/dl_mk_array_blast.h new file mode 100644 index 000000000..858b9c778 --- /dev/null +++ b/src/muz_qe/dl_mk_array_blast.h @@ -0,0 +1,61 @@ +/*++ +Copyright (c) 2012 Microsoft Corporation + +Module Name: + + dl_mk_array_blast.h + +Abstract: + + Remove array variables from rules. + +Author: + + Nikolaj Bjorner (nbjorner) 2012-11-23 + +Revision History: + +--*/ +#ifndef _DL_MK_ARRAY_BLAST_H_ +#define _DL_MK_ARRAY_BLAST_H_ + +#include"dl_context.h" +#include"dl_rule_set.h" +#include"dl_rule_transformer.h" +#include "equiv_proof_converter.h" +#include "array_decl_plugin.h" + +namespace datalog { + + /** + \brief Blast occurrences of arrays in rules + */ + class mk_array_blast : public rule_transformer::plugin { + context& m_ctx; + ast_manager& m; + array_util a; + rule_manager& rm; + params_ref m_params; + th_rewriter m_rewriter; + equiv_proof_converter* m_pc; + + bool blast(rule& r, rule_set& new_rules); + + bool is_store_def(expr* e, expr*& x, expr*& y); + + public: + /** + \brief Create rule transformer that extracts universal quantifiers (over recursive predicates). + */ + mk_array_blast(context & ctx, unsigned priority); + + virtual ~mk_array_blast(); + + rule_set * operator()(rule_set const & source, model_converter_ref& mc, proof_converter_ref& pc); + + }; + +}; + +#endif /* _DL_MK_ARRAY_BLAST_H_ */ + diff --git a/src/muz_qe/dl_mk_extract_quantifiers.cpp b/src/muz_qe/dl_mk_extract_quantifiers.cpp index 614e9dbc8..d2b4f0cec 100644 --- a/src/muz_qe/dl_mk_extract_quantifiers.cpp +++ b/src/muz_qe/dl_mk_extract_quantifiers.cpp @@ -38,31 +38,81 @@ namespace datalog { m_refs.reset(); } + app_ref mk_extract_quantifiers::ensure_app(expr* e) { + if (is_app(e)) { + return app_ref(to_app(e), m); + } + else { + return app_ref(m.mk_eq(e, m.mk_true()), m); + } + } + + void mk_extract_quantifiers::ensure_predicate(expr* e, unsigned& max_var, app_ref_vector& tail) { + SASSERT(is_app(e)); + SASSERT(to_app(e)->get_decl()->get_family_id() == null_family_id); + app* a = to_app(e); + expr_ref_vector args(m); + for (unsigned i = 0; i < a->get_num_args(); ++i) { + expr* arg = a->get_arg(i); + if (is_var(arg) || m.is_value(arg)) { + args.push_back(arg); + } + else { + expr_ref new_var(m); + new_var = m.mk_var(++max_var, m.get_sort(arg)); + args.push_back(new_var); + tail.push_back(m.mk_eq(new_var, arg)); + } + } + tail.push_back(m.mk_app(a->get_decl(), args.size(), args.c_ptr())); + } + void mk_extract_quantifiers::extract(rule& r, rule_set& new_rules) { app_ref_vector tail(m); - svector neg_tail; quantifier_ref_vector quantifiers(m); unsigned utsz = r.get_uninterpreted_tail_size(); unsigned tsz = r.get_tail_size(); + var_counter vc(true); + unsigned max_var = vc.get_max_var(r); for (unsigned i = 0; i < utsz; ++i) { tail.push_back(r.get_tail(i)); - neg_tail.push_back(r.is_neg_tail(i)); + if (r.is_neg_tail(i)) { + new_rules.add_rule(&r); + return; + } } + var_subst vs(m, true); for (unsigned i = utsz; i < tsz; ++i) { - SASSERT(!r.is_neg_tail(i)); app* t = r.get_tail(i); expr_ref_vector conjs(m); datalog::flatten_and(t, conjs); + expr_ref qe(m); + quantifier* q = 0; for (unsigned j = 0; j < conjs.size(); ++j) { expr* e = conjs[j].get(); - quantifier* q = 0; if (rule_manager::is_forall(m, e, q)) { quantifiers.push_back(q); + expr_ref_vector sub(m); + ptr_vector fv; + unsigned num_decls = q->get_num_decls(); + get_free_vars(q, fv); + for (unsigned k = 0; k < fv.size(); ++k) { + unsigned idx = fv.size()-k-1; + if (!fv[idx]) { + fv[idx] = m.mk_bool_sort(); + } + sub.push_back(m.mk_var(idx, fv[idx])); + } + for (unsigned k = 0; k < num_decls; ++k) { + sub.push_back(m.mk_var(num_decls+max_var-k, q->get_decl_sort(k))); + } + max_var += num_decls; + vs(q->get_expr(), sub.size(), sub.c_ptr(), qe); + ensure_predicate(qe, max_var, tail); } else { - tail.push_back(is_app(e)?to_app(e):m.mk_eq(e, m.mk_true())); - neg_tail.push_back(false); + tail.push_back(ensure_app(e)); } } } @@ -70,11 +120,17 @@ namespace datalog { new_rules.add_rule(&r); } else { - rule* new_rule = rm.mk(r.get_head(), tail.size(), tail.c_ptr(), neg_tail.c_ptr(), r.name(), false); - new_rules.add_rule(new_rule); + rule_ref new_rule(rm); + TRACE("dl", + tout << mk_pp(r.get_head(), m) << " :- \n"; + for (unsigned i = 0; i < tail.size(); ++i) { + tout << " " << mk_pp(tail[i].get(), m) << "\n"; + }); + new_rule = rm.mk(r.get_head(), tail.size(), tail.c_ptr(), 0, r.name(), false); quantifier_ref_vector* qs = alloc(quantifier_ref_vector, quantifiers); - m_quantifiers.insert(new_rule, qs); m_refs.push_back(qs); + new_rules.add_rule(new_rule); + m_quantifiers.insert(new_rule, qs); } } diff --git a/src/muz_qe/dl_mk_extract_quantifiers.h b/src/muz_qe/dl_mk_extract_quantifiers.h index 512e386cd..5da5d59d7 100644 --- a/src/muz_qe/dl_mk_extract_quantifiers.h +++ b/src/muz_qe/dl_mk_extract_quantifiers.h @@ -37,6 +37,8 @@ namespace datalog { void extract(rule& r, rule_set& new_rules); + app_ref ensure_app(expr* e); + public: /** \brief Create rule transformer that extracts universal quantifiers (over recursive predicates). @@ -51,6 +53,8 @@ namespace datalog { bool has_quantifiers() const { return !m_quantifiers.empty(); } + void ensure_predicate(expr* e, unsigned& max_var, app_ref_vector& tail); + }; }; diff --git a/src/muz_qe/dl_util.h b/src/muz_qe/dl_util.h index 1685bec9c..f314b691d 100644 --- a/src/muz_qe/dl_util.h +++ b/src/muz_qe/dl_util.h @@ -196,6 +196,12 @@ namespace datalog { scoped_no_proof(ast_manager& m): scoped_proof_mode(m, PGM_DISABLED) {} }; + class scoped_restore_proof : public scoped_proof_mode { + public: + scoped_restore_proof(ast_manager& m): scoped_proof_mode(m, m.proof_mode()) {} + }; + + class variable_intersection diff --git a/src/muz_qe/equiv_proof_converter.h b/src/muz_qe/equiv_proof_converter.h new file mode 100644 index 000000000..94d6f4e04 --- /dev/null +++ b/src/muz_qe/equiv_proof_converter.h @@ -0,0 +1,58 @@ +/*++ +Copyright (c) 2012 Microsoft Corporation + +Module Name: + + equiv_proof_converter.h + +Abstract: + + Proof converter that applies equivalence rule to leaves. + + Given a proof P with occurrences of [asserted fml] + replace [asserted fml] by a proof of the form + [mp [asserted fml'] [~ fml fml']] + +Author: + + Nikolaj Bjorner (nbjorner) 2012-11-23 + +Revision History: + +--*/ + +#ifndef _EQUIV_PROOF_CONVERTER_H_ +#define _EQUIV_PROOF_CONVERTER_H_ + +#include "replace_proof_converter.h" + +class equiv_proof_converter : public proof_converter { + ast_manager& m; + replace_proof_converter m_replace; +public: + + equiv_proof_converter(ast_manager& m): m(m), m_replace(m) {} + + virtual ~equiv_proof_converter() {} + + virtual void operator()(ast_manager & m, unsigned num_source, proof * const * source, proof_ref & result) { + m_replace(m, num_source, source, result); + } + + virtual proof_converter * translate(ast_translation & translator) { + return m_replace.translate(translator); + } + + void insert(expr* fml1, expr* fml2) { + proof_ref p1(m), p2(m), p3(m); + p1 = m.mk_asserted(fml1); + p2 = m.mk_rewrite(fml1, fml2); + p3 = m.mk_modus_ponens(p1, p2); + m_replace.insert(p3); + } + + ast_manager& get_manager() { return m; } + +}; + +#endif diff --git a/src/muz_qe/pdr_context.cpp b/src/muz_qe/pdr_context.cpp index f056342a2..798ee406d 100644 --- a/src/muz_qe/pdr_context.cpp +++ b/src/muz_qe/pdr_context.cpp @@ -35,7 +35,6 @@ Notes: #include "pdr_generalizers.h" #include "datatype_decl_plugin.h" #include "for_each_expr.h" -#include "model_v2_pp.h" #include "dl_rule_set.h" #include "unit_subsumption_tactic.h" #include "model_smt2_pp.h" @@ -44,6 +43,7 @@ Notes: #include "qe_lite.h" #include "ast_ll_pp.h" #include "proof_checker.h" +#include "smt_value_sort.h" namespace pdr { @@ -146,7 +146,6 @@ namespace pdr { expr_ref vl(m); for (; it != end; ++it) { expr* pred = it->m_key; - TRACE("pdr", tout << mk_pp(pred, m) << "\n";); if (model.eval(to_app(pred)->get_decl(), vl) && m.is_true(vl)) { return *it->m_value; } @@ -300,6 +299,7 @@ namespace pdr { if (!m_invariants.contains(lemma)) { TRACE("pdr", tout << "property1: " << head()->get_name() << " " << mk_pp(lemma, m) << "\n";); m_invariants.push_back(lemma); + m_prop2level.insert(lemma, lvl); m_solver.add_formula(lemma); return true; } @@ -362,7 +362,7 @@ namespace pdr { } // replace local constants by bound variables. expr_substitution sub(m); - for (unsigned i = 0; i < m_sig.size(); ++i) { + for (unsigned i = 0; i < sig_size(); ++i) { c = m.mk_const(pm.o2n(sig(i), 0)); v = m.mk_var(i, sig(i)->get_range()); sub.insert(c, v); @@ -397,7 +397,7 @@ namespace pdr { // replace bound variables by local constants. expr_ref result(property, m), v(m), c(m); expr_substitution sub(m); - for (unsigned i = 0; i < m_sig.size(); ++i) { + for (unsigned i = 0; i < sig_size(); ++i) { c = m.mk_const(pm.o2n(sig(i), 0)); v = m.mk_var(i, sig(i)->get_range()); sub.insert(v, c); @@ -442,6 +442,7 @@ namespace pdr { tmp = pm.mk_and(conj); prop_solver::scoped_level _sl(m_solver, level); m_solver.set_core(core); + m_solver.set_model(0); lbool r = m_solver.check_conjunction_as_assumptions(tmp); if (r == l_false) { assumes_level = m_solver.assumes_level(); @@ -602,6 +603,12 @@ namespace pdr { } m_rule2inst.insert(&rule,&var_reprs); m_rule2vars.insert(&rule, aux_vars); + TRACE("pdr", + tout << rule.get_decl()->get_name() << "\n"; + for (unsigned i = 0; i < var_reprs.size(); ++i) { + tout << mk_pp(var_reprs[i].get(), m) << " "; + } + tout << "\n";); } bool pred_transformer::check_filled(app_ref_vector const& v) const { @@ -699,16 +706,10 @@ namespace pdr { void pred_transformer::inherit_properties(pred_transformer& other) { SASSERT(m_head == other.m_head); obj_map::iterator it = other.m_prop2level.begin(); - obj_map::iterator end = other.m_prop2level.end(); - + obj_map::iterator end = other.m_prop2level.end(); for (; it != end; ++it) { add_property(it->m_key, it->m_value); } - for (unsigned i = 0; i < other.m_invariants.size(); ++i) { - expr* e = other.m_invariants[i].get(); - m_invariants.push_back(e); - m_solver.add_formula(e); - } } // ---------------- @@ -723,20 +724,18 @@ namespace pdr { pred_transformer& p = pt(); ast_manager& m = p.get_manager(); manager& pm = p.get_pdr_manager(); - TRACE("pdr", model_v2_pp(tout, get_model());); + TRACE("pdr", model_smt2_pp(tout, m, get_model(), 0);); func_decl* f = p.head(); unsigned arity = f->get_arity(); + model_ref model = get_model_ptr(); expr_ref_vector args(m); - func_decl_ref v(m); + expr_ref v(m); + model_evaluator mev(m); + for (unsigned i = 0; i < arity; ++i) { - v = pm.o2n(p.sig(i),0); - expr* e = get_model().get_const_interp(v); - if (e) { - args.push_back(e); - } - else { - args.push_back(m.mk_const(v)); - } + v = m.mk_const(pm.o2n(p.sig(i),0)); + expr_ref e = mev.eval(model, v); + args.push_back(e); } return expr_ref(m.mk_app(f, args.size(), args.c_ptr()), m); } @@ -1823,14 +1822,14 @@ namespace pdr { if (!vars.empty()) { // also fresh names for auxiliary variables in body? expr_substitution sub(m); - expr_ref_vector refs(m); expr_ref tmp(m); proof_ref pr(m); pr = m.mk_asserted(m.mk_true()); - for (unsigned i = 0; i < vars.size(); ++i) { - VERIFY (M->eval(vars[i].get(), tmp, true)); - refs.push_back(tmp); - sub.insert(vars[i].get(), tmp, pr); + for (unsigned i = 0; i < vars.size(); ++i) { + if (smt::is_value_sort(m, vars[i].get())) { + tmp = mev.eval(M, vars[i].get()); + sub.insert(vars[i].get(), tmp, pr); + } } if (!rep) rep = mk_expr_simp_replacer(m); rep->set_substitution(&sub); @@ -1861,7 +1860,7 @@ namespace pdr { for (unsigned j = 1; j < indices.size(); ++j) { ptr_vector const& vs = vars[indices[j]]; for (unsigned k = 0; k < vs.size(); ++k) { - M->eval(vs[k]->get_decl(), tmp); + tmp = mev.eval(M, vs[k]); sub.insert(vs[k], tmp, pr); child_states[indices[j]].push_back(m.mk_eq(vs[k], tmp)); } diff --git a/src/muz_qe/pdr_context.h b/src/muz_qe/pdr_context.h index 4b578a188..c7f53752a 100644 --- a/src/muz_qe/pdr_context.h +++ b/src/muz_qe/pdr_context.h @@ -116,6 +116,7 @@ namespace pdr { ptr_vector const& rules() const { return m_rules; } func_decl* sig(unsigned i) { init_sig(); return m_sig[i].get(); } // signature func_decl* const* sig() { init_sig(); return m_sig.c_ptr(); } + unsigned sig_size() { init_sig(); return m_sig.size(); } expr* transition() const { return m_transition; } expr* initial_state() const { return m_initial_state; } expr* rule2tag(datalog::rule const* r) { return m_rule2tag.find(r); } diff --git a/src/muz_qe/pdr_dl_interface.cpp b/src/muz_qe/pdr_dl_interface.cpp index be31f4724..b047aaae0 100644 --- a/src/muz_qe/pdr_dl_interface.cpp +++ b/src/muz_qe/pdr_dl_interface.cpp @@ -58,18 +58,18 @@ dl_interface::~dl_interface() { // void dl_interface::check_reset() { datalog::rule_ref_vector const& new_rules = m_ctx.get_rules().get_rules(); - datalog::rule_ref_vector const& old_rules = m_old_rules.get_rules(); - for (unsigned i = 0; i < new_rules.size(); ++i) { - bool found = false; - for (unsigned j = 0; !found && j < old_rules.size(); ++j) { + datalog::rule_ref_vector const& old_rules = m_old_rules.get_rules(); + bool is_subsumed = !old_rules.empty(); + for (unsigned i = 0; is_subsumed && i < new_rules.size(); ++i) { + is_subsumed = false; + for (unsigned j = 0; !is_subsumed && j < old_rules.size(); ++j) { if (m_ctx.check_subsumes(*old_rules[j], *new_rules[i])) { - found = true; + is_subsumed = true; } } - if (!found) { - CTRACE("pdr", (old_rules.size() > 0), new_rules[i]->display(m_ctx, tout << "Fresh rule ");); + if (!is_subsumed) { + TRACE("pdr", new_rules[i]->display(m_ctx, tout << "Fresh rule ");); m_context->reset(); - break; } } m_old_rules.reset(); @@ -160,6 +160,8 @@ lbool dl_interface::query(expr * query) { m_ctx.replace_rules(old_rules); quantifier_model_checker quantifier_mc(*m_context, m, extract_quantifiers->quantifiers(), m_pdr_rules); + + datalog::scoped_restore_proof _sc(m); // update_rules may overwrite the proof mode. m_context->set_proof_converter(pc); m_context->set_model_converter(mc); diff --git a/src/muz_qe/pdr_prop_solver.h b/src/muz_qe/pdr_prop_solver.h index 15122a21a..fcbfbd536 100644 --- a/src/muz_qe/pdr_prop_solver.h +++ b/src/muz_qe/pdr_prop_solver.h @@ -94,7 +94,7 @@ namespace pdr { scoped_level(prop_solver& ps, unsigned lvl):m_lev(ps.m_in_level) { SASSERT(!m_lev); m_lev = true; ps.m_current_level = lvl; } - ~scoped_level() { m_lev = false; } + ~scoped_level() { m_lev = false; } }; void add_formula(expr * form); diff --git a/src/muz_qe/pdr_quantifiers.cpp b/src/muz_qe/pdr_quantifiers.cpp index d52a0bf07..47a1622f3 100644 --- a/src/muz_qe/pdr_quantifiers.cpp +++ b/src/muz_qe/pdr_quantifiers.cpp @@ -19,11 +19,14 @@ Revision History: #include "pdr_quantifiers.h" #include "pdr_context.h" -#include "model_smt2_pp.h" -#include "ast_smt2_pp.h" #include "qe.h" #include "var_subst.h" #include "dl_rule_set.h" +#include "ast_smt2_pp.h" +#include "model_smt2_pp.h" +#include "ast_smt_pp.h" +#include "expr_abstract.h" +#include "dl_mk_extract_quantifiers.h" namespace pdr { @@ -103,21 +106,37 @@ namespace pdr { } void quantifier_model_checker::apply_binding(quantifier* q, expr_ref_vector& binding) { + + datalog::scoped_no_proof _scp(m); + app_ref_vector& var_inst = m_current_pt->get_inst(m_current_rule); - expr_substitution sub(m); - for (unsigned i = 0; i < var_inst.size(); ++i) { - expr* v = var_inst[i].get(); - sub.insert(v, m.mk_var(i, m.get_sort(v))); - } - scoped_ptr rep = mk_default_expr_replacer(m); - rep->set_substitution(&sub); + + TRACE("pdr", tout << mk_pp(q, m) << "\n"; + tout << "binding\n"; + for (unsigned i = 0; i < binding.size(); ++i) { + tout << mk_pp(binding[i].get(), m) << " "; + } + tout << "\n"; + tout << "inst\n"; + for (unsigned i = 0; i < var_inst.size(); ++i) { + tout << mk_pp(var_inst[i].get(), m) << " "; + } + tout << "\n"; + ); + + expr_ref e(m); var_subst vs(m, false); + inv_var_shifter invsh(m); vs(q->get_expr(), binding.size(), binding.c_ptr(), e); - (*rep)(e); + invsh(e, q->get_num_decls(), e); + expr_ref_vector inst(m); + inst.append(var_inst.size(), (expr*const*)var_inst.c_ptr()); + inst.reverse(); + expr_abstract(m, 0, inst.size(), inst.c_ptr(), e, e); + TRACE("pdr", tout << mk_pp(e, m) << "\n";); m_instantiated_rules.push_back(m_current_rule); m_instantiations.push_back(to_app(e)); - TRACE("pdr", tout << mk_pp(e, m) << "\n";); } @@ -181,25 +200,22 @@ namespace pdr { bool found_instance = false; TRACE("pdr", tout << mk_pp(m_A,m) << "\n";); - ast_manager mp(PGM_COARSE); - ast_translation tr(m, mp); - ast_translation rev_tr(mp, m); - expr_ref_vector fmls(mp); + datalog::scoped_coarse_proof _scp(m); + + expr_ref_vector fmls(m); front_end_params fparams; fparams.m_proof_mode = PGM_COARSE; + fparams.m_mbqi = true; // TBD: does not work on integers: fparams.m_mbqi = true; - expr_ref C(m); - fmls.push_back(tr(m_A.get())); - for (unsigned i = 0; i < m_Bs.size(); ++i) { - C = m.update_quantifier(qs[i], m_Bs[i].get()); - fmls.push_back(tr(C.get())); - } + + fmls.push_back(m_A.get()); + fmls.append(m_Bs); TRACE("pdr", tout << "assert\n"; for (unsigned i = 0; i < fmls.size(); ++i) { - tout << mk_pp(fmls[i].get(), mp) << "\n"; + tout << mk_pp(fmls[i].get(), m) << "\n"; }); - smt::kernel solver(mp, fparams); + smt::kernel solver(m, fparams); for (unsigned i = 0; i < fmls.size(); ++i) { solver.assert_expr(fmls[i].get()); } @@ -216,8 +232,8 @@ namespace pdr { } proof* p = solver.get_proof(); - TRACE("pdr", tout << mk_ismt2_pp(p, mp) << "\n";); - collect_insts collector(mp); + TRACE("pdr", tout << mk_ismt2_pp(p, m) << "\n";); + collect_insts collector(m); for_each_expr(collector, p); ptr_vector const& quants = collector.quantifiers(); @@ -225,20 +241,20 @@ namespace pdr { symbol qid = quants[i]->get_qid(); if (!qid_map.find(qid, q)) { TRACE("pdr", tout << "Could not find quantifier " - << mk_pp(quants[i], mp) << "\n";); + << mk_pp(quants[i], m) << "\n";); continue; } expr_ref_vector const& binding = collector.bindings()[i]; - TRACE("pdr", tout << "Instantiating:\n" << mk_pp(quants[i], mp) << "\n"; + TRACE("pdr", tout << "Instantiating:\n" << mk_pp(quants[i], m) << "\n"; for (unsigned j = 0; j < binding.size(); ++j) { - tout << mk_pp(binding[j], mp) << " "; + tout << mk_pp(binding[j], m) << " "; } tout << "\n";); expr_ref_vector new_binding(m); for (unsigned j = 0; j < binding.size(); ++j) { - new_binding.push_back(rev_tr(binding[j])); + new_binding.push_back(binding[j]); } add_binding(q, new_binding); found_instance = true; @@ -258,11 +274,32 @@ namespace pdr { return found_instance; } + /** + Given node: + + - pt - predicate transformer for rule: + P(x) :- Body1(x,y) || Body2(x,z) & (Fa u . Q(u,x,z)). + - rule - P(x) :- Body2(x,z) + + - qis - Fa u . Q(u,x,z) + + - A := node.state(x) && Body2(x,y) + + - Bs := array of Bs of the form: + . Fa u . Q(u, P_x, P_y) - instantiate quantifier to P variables. + . B := inv(Q_0,Q_1,Q_2) + . B := inv(u, P_x, P_y) := B[u/Q_0, P_x/Q_1, P_y/Q_2] + . B := Fa u . inv(u, P_x, P_y) + + + */ + + void quantifier_model_checker::model_check_node(model_node& node) { TRACE("pdr", node.display(tout, 0);); pred_transformer& pt = node.pt(); manager& pm = pt.get_pdr_manager(); - expr_ref A(m), B(m), C(m); + expr_ref A(m), B(m), C(m), v(m); expr_ref_vector As(m); m_Bs.reset(); // @@ -285,8 +322,12 @@ namespace pdr { return; } unsigned level = node.level(); - unsigned previous_level = (level == 0)?0:(level-1); + if (level == 0) { + return; + } + unsigned previous_level = level - 1; + As.push_back(pt.get_propagation_formula(m_ctx.get_pred_transformers(), level)); As.push_back(node.state()); As.push_back(pt.rule2tag(m_current_rule)); @@ -296,28 +337,42 @@ namespace pdr { { datalog::scoped_no_proof _no_proof(m); + quantifier_ref q(m); scoped_ptr rep = mk_default_expr_replacer(m); for (unsigned j = 0; j < qis->size(); ++j) { - quantifier* q = (*qis)[j].get(); + q = (*qis)[j].get(); + app_ref_vector& inst = pt.get_inst(m_current_rule); + ptr_vector& aux_vars = pt.get_aux_vars(*m_current_rule); + TRACE("pdr", + tout << "q:\n" << mk_pp(q, m) << "\n"; + tout << "level: " << level << "\n"; + model_smt2_pp(tout, m, node.get_model(), 0); + m_current_rule->display(m_ctx.get_context(), tout << "rule:\n"); + + ); + + var_subst vs(m, false); + vs(q, inst.size(), (expr*const*)inst.c_ptr(), B); + q = to_quantifier(B); + TRACE("pdr", tout << "q instantiated:\n" << mk_pp(q, m) << "\n";); + app* a = to_app(q->get_expr()); func_decl* f = a->get_decl(); pred_transformer& pt2 = m_ctx.get_pred_transformer(f); B = pt2.get_formulas(previous_level, true); + TRACE("pdr", tout << "B:\n" << mk_pp(B, m) << "\n";); + expr_substitution sub(m); - expr_ref_vector refs(m); for (unsigned i = 0; i < a->get_num_args(); ++i) { - expr* v = m.mk_const(pm.o2n(pt2.sig(i),0)); + v = m.mk_const(pm.o2n(pt2.sig(i),0)); sub.insert(v, a->get_arg(i)); - refs.push_back(v); } rep->set_substitution(&sub); (*rep)(B); - app_ref_vector& inst = pt.get_inst(m_current_rule); - ptr_vector& aux_vars = pt.get_aux_vars(*m_current_rule); - pt.ground_free_vars(B, inst, aux_vars); - var_subst vs(m, false); - vs(B, inst.size(), (expr*const*)inst.c_ptr(), B); + TRACE("pdr", tout << "B substituted:\n" << mk_pp(B, m) << "\n";); + + B = m.update_quantifier(q, B); m_Bs.push_back(B); } } @@ -328,6 +383,12 @@ namespace pdr { for (unsigned i = 0; i < m_Bs.size(); ++i) { tout << mk_pp((*qis)[i].get(), m) << "\n" << mk_pp(m_Bs[i].get(), m) << "\n"; } + ast_smt_pp pp(m); + pp.add_assumption(m_A); + for (unsigned i = 0; i < m_Bs.size(); ++i) { + pp.add_assumption(m_Bs[i].get()); + } + pp.display_smt2(tout, m.mk_true()); ); find_instantiations(*qis, level); @@ -346,16 +407,18 @@ namespace pdr { } void quantifier_model_checker::refine() { - IF_VERBOSE(1, verbose_stream() << "instantiating quantifiers\n";); - datalog::rule_manager& rule_m = m_rules.get_rule_manager(); + datalog::mk_extract_quantifiers eq(m_ctx.get_context()); + datalog::rule_manager& rm = m_rules.get_rule_manager(); datalog::rule_set new_rules(m_rules.get_context()); datalog::rule_set::iterator it = m_rules.begin(), end = m_rules.end(); for (; it != end; ++it) { datalog::rule* r = *it; - expr_ref_vector body(m); + datalog::var_counter vc(true); + unsigned max_var = vc.get_max_var(*r); + app_ref_vector body(m); for (unsigned i = 0; i < m_instantiations.size(); ++i) { if (r == m_instantiated_rules[i]) { - body.push_back(m_instantiations[i].get()); + eq.ensure_predicate(m_instantiations[i].get(), max_var, body); } } if (body.empty()) { @@ -367,17 +430,19 @@ namespace pdr { } quantifier_ref_vector* qs = 0; m_quantifiers.find(r, qs); - m_quantifiers.remove(r); - datalog::rule_ref_vector rules(rule_m); - expr_ref rule(m.mk_implies(m.mk_and(body.size(), body.c_ptr()), r->get_head()), m); - rule_m.mk_rule(rule, rules, r->name()); - for (unsigned i = 0; i < rules.size(); ++i) { - new_rules.add_rule(rules[i].get()); - m_quantifiers.insert(rules[i].get(), qs); - } + m_quantifiers.remove(r); + datalog::rule_ref new_rule(rm); + new_rule = rm.mk(r->get_head(), body.size(), body.c_ptr(), 0, r->name(), false); + new_rules.add_rule(new_rule); + m_quantifiers.insert(new_rule, qs); + IF_VERBOSE(1, + verbose_stream() << "instantiating quantifiers\n"; + r->display(m_ctx.get_context(), verbose_stream()); + verbose_stream() << "replaced by\n"; + new_rule->display(m_ctx.get_context(), verbose_stream());); } } - new_rules.close(); + new_rules.close(); m_rules.reset(); m_rules.add_rules(new_rules); m_rules.close(); diff --git a/src/muz_qe/pdr_util.cpp b/src/muz_qe/pdr_util.cpp index 512d94956..705b519a2 100644 --- a/src/muz_qe/pdr_util.cpp +++ b/src/muz_qe/pdr_util.cpp @@ -86,559 +86,601 @@ namespace pdr { return res.str(); } + ///////////////////////// + // select elimination rewriter + // -///////////////////////// -// model_evaluator -// + class select_elim { + ast_manager& m; + array_util a; + model_ref m_model; + public: + select_elim(ast_manager& m, model_ref& md): m(m), a(m), m_model(md) {} + + br_status mk_app_core(func_decl* f, unsigned num_args, expr* const* args, expr_ref& result) { + if (a.is_select(f)) { + expr_ref tmp(m); + tmp = m.mk_app(f, num_args, args); + m_model->eval(tmp, result); + return BR_DONE; + } + else { + return BR_FAILED; + } + } + }; + + struct select_elim_cfg: public default_rewriter_cfg { + select_elim m_r; + bool rewrite_patterns() const { return false; } + br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) { + return m_r.mk_app_core(f, num, args, result); + } + select_elim_cfg(ast_manager & m, model_ref& md, params_ref const & p):m_r(m, md) {} + }; -void model_evaluator::assign_value(expr* e, expr* val) { - rational r; - if (m.is_true(val)) { - set_true(e); - } - else if (m.is_false(val)) { - set_false(e); - } - else if (m_arith.is_numeral(val, r)) { - set_number(e, r); - } - else if (m.is_value(val)) { - set_value(e, val); - } - else { - IF_VERBOSE(3, verbose_stream() << "Not evaluated " << mk_pp(e, m) << "\n";); - TRACE("pdr", tout << "Variable is not tracked: " << mk_pp(e, m) << "\n";); - set_x(e); - } -} + class select_elim_star : public rewriter_tpl { + select_elim_cfg m_cfg; + public: + select_elim_star(ast_manager & m, model_ref& md, params_ref const & p = params_ref()): + rewriter_tpl(m, false, m_cfg), + m_cfg(m, md, p) {} + }; -void model_evaluator::setup_model(model_ref& model) { - m_numbers.reset(); - m_values.reset(); - m_model = model; - rational r; - unsigned sz = model->get_num_constants(); - for (unsigned i = 0; i < sz; i++) { - func_decl * d = model->get_constant(i); - expr* val = model->get_const_interp(d); - expr* e = m.mk_const(d); - m_refs.push_back(e); - assign_value(e, val); - } -} -void model_evaluator::reset() { - m1.reset(); - m2.reset(); - m_values.reset(); - m_visited.reset(); - m_numbers.reset(); - m_refs.reset(); - m_model = 0; -} -expr_ref_vector model_evaluator::minimize_model(ptr_vector const & formulas, model_ref& mdl) { - setup_model(mdl); - - TRACE("pdr_verbose", - tout << "formulas:\n"; - for (unsigned i = 0; i < formulas.size(); ++i) tout << mk_pp(formulas[i], m) << "\n"; - ); - - expr_ref_vector model = prune_by_cone_of_influence(formulas); - TRACE("pdr_verbose", - tout << "pruned model:\n"; - for (unsigned i = 0; i < model.size(); ++i) tout << mk_pp(model[i].get(), m) << "\n";); - - reset(); - - DEBUG_CODE( - setup_model(mdl); - VERIFY(check_model(formulas)); - reset();); - - return model; -} - -expr_ref_vector model_evaluator::minimize_literals(ptr_vector const& formulas, model_ref& mdl) { - - TRACE("pdr", - tout << "formulas:\n"; - for (unsigned i = 0; i < formulas.size(); ++i) tout << mk_pp(formulas[i], m) << "\n"; - ); - - expr_ref_vector result(m); - ptr_vector tocollect; + ///////////////////////// + // model_evaluator + // - setup_model(mdl); - collect(formulas, tocollect); - for (unsigned i = 0; i < tocollect.size(); ++i) { - expr* e = tocollect[i]; - SASSERT(m.is_bool(e)); - SASSERT(is_true(e) || is_false(e)); - if (is_true(e)) { - result.push_back(e); + + void model_evaluator::assign_value(expr* e, expr* val) { + rational r; + if (m.is_true(val)) { + set_true(e); + } + else if (m.is_false(val)) { + set_false(e); + } + else if (m_arith.is_numeral(val, r)) { + set_number(e, r); + } + else if (m.is_value(val)) { + set_value(e, val); } else { - result.push_back(m.mk_not(e)); + IF_VERBOSE(3, verbose_stream() << "Not evaluated " << mk_pp(e, m) << "\n";); + TRACE("pdr", tout << "Variable is not tracked: " << mk_pp(e, m) << "\n";); + set_x(e); } } - reset(); - return result; -} -void model_evaluator::process_formula(app* e, ptr_vector& todo, ptr_vector& tocollect) { - SASSERT(m.is_bool(e)); - SASSERT(is_true(e) || is_false(e)); - unsigned v = is_true(e); - unsigned sz = e->get_num_args(); - expr* const* args = e->get_args(); - if (e->get_family_id() == m.get_basic_family_id()) { - switch(e->get_decl_kind()) { - case OP_TRUE: - break; - case OP_FALSE: - break; - case OP_EQ: - case OP_IFF: - if (args[0] == args[1]) { - SASSERT(v); - // no-op - } - else if (!m.is_bool(args[0])) { - tocollect.push_back(e); + void model_evaluator::setup_model(model_ref& model) { + m_numbers.reset(); + m_values.reset(); + m_model = model; + rational r; + unsigned sz = model->get_num_constants(); + for (unsigned i = 0; i < sz; i++) { + func_decl * d = model->get_constant(i); + expr* val = model->get_const_interp(d); + expr* e = m.mk_const(d); + m_refs.push_back(e); + assign_value(e, val); + } + } + + void model_evaluator::reset() { + m1.reset(); + m2.reset(); + m_values.reset(); + m_visited.reset(); + m_numbers.reset(); + m_refs.reset(); + m_model = 0; + } + + expr_ref_vector model_evaluator::minimize_model(ptr_vector const & formulas, model_ref& mdl) { + setup_model(mdl); + + TRACE("pdr_verbose", + tout << "formulas:\n"; + for (unsigned i = 0; i < formulas.size(); ++i) tout << mk_pp(formulas[i], m) << "\n"; + ); + + expr_ref_vector model = prune_by_cone_of_influence(formulas); + TRACE("pdr_verbose", + tout << "pruned model:\n"; + for (unsigned i = 0; i < model.size(); ++i) tout << mk_pp(model[i].get(), m) << "\n";); + + reset(); + + DEBUG_CODE( + setup_model(mdl); + VERIFY(check_model(formulas)); + reset();); + + return model; + } + + expr_ref_vector model_evaluator::minimize_literals(ptr_vector const& formulas, model_ref& mdl) { + + TRACE("pdr", + tout << "formulas:\n"; + for (unsigned i = 0; i < formulas.size(); ++i) tout << mk_pp(formulas[i], m) << "\n"; + ); + + expr_ref_vector result(m); + expr_ref tmp(m); + ptr_vector tocollect; + + setup_model(mdl); + collect(formulas, tocollect); + for (unsigned i = 0; i < tocollect.size(); ++i) { + expr* e = tocollect[i]; + SASSERT(m.is_bool(e)); + SASSERT(is_true(e) || is_false(e)); + if (is_true(e)) { + result.push_back(e); } else { - todo.append(sz, args); + result.push_back(m.mk_not(e)); } - break; - case OP_DISTINCT: - tocollect.push_back(e); - break; - case OP_ITE: - if (args[1] == args[2]) { - tocollect.push_back(args[1]); - } - else if (is_true(args[1]) && is_true(args[2])) { - todo.append(2, args+1); - } - else if (is_false(args[1]) && is_false(args[2])) { - todo.append(2, args+1); - } - else if (is_true(args[0])) { - todo.append(2, args); - } - else { - SASSERT(is_false(args[0])); - todo.push_back(args[0]); - todo.push_back(args[2]); - } - break; - case OP_AND: - if (v) { - todo.append(sz, args); - } - else { - unsigned i = 0; - for (; !is_false(args[i]) && i < sz; ++i); - if (i == sz) { - fatal_error(1); + } + select_elim_star select_elim(m, m_model); + for (unsigned i = 0; i < result.size(); ++i) { + select_elim(result[i].get(), tmp); + result[i] = tmp; + } + reset(); + TRACE("pdr", + tout << "minimized model:\n"; + for (unsigned i = 0; i < result.size(); ++i) tout << mk_pp(result[i].get(), m) << "\n"; + ); + + return result; + } + + void model_evaluator::process_formula(app* e, ptr_vector& todo, ptr_vector& tocollect) { + SASSERT(m.is_bool(e)); + SASSERT(is_true(e) || is_false(e)); + unsigned v = is_true(e); + unsigned sz = e->get_num_args(); + expr* const* args = e->get_args(); + if (e->get_family_id() == m.get_basic_family_id()) { + switch(e->get_decl_kind()) { + case OP_TRUE: + break; + case OP_FALSE: + break; + case OP_EQ: + case OP_IFF: + if (args[0] == args[1]) { + SASSERT(v); + // no-op } - VERIFY(i < sz); - todo.push_back(args[i]); - } - break; - case OP_OR: - if (v) { - unsigned i = 0; - for (; !is_true(args[i]) && i < sz; ++i); - if (i == sz) { - fatal_error(1); - } - VERIFY(i < sz); - todo.push_back(args[i]); - } - else { - todo.append(sz, args); - } - break; - case OP_XOR: - case OP_NOT: - todo.append(sz, args); - break; - case OP_IMPLIES: - if (v) { - if (is_true(args[1])) { - todo.push_back(args[1]); - } - else if (is_false(args[0])) { - todo.push_back(args[0]); + else if (!m.is_bool(args[0])) { + tocollect.push_back(e); } else { - IF_VERBOSE(0, verbose_stream() << "Term not handled " << mk_pp(e, m) << "\n";); - UNREACHABLE(); + todo.append(sz, args); } + break; + case OP_DISTINCT: + tocollect.push_back(e); + break; + case OP_ITE: + if (args[1] == args[2]) { + tocollect.push_back(args[1]); + } + else if (is_true(args[1]) && is_true(args[2])) { + todo.append(2, args+1); + } + else if (is_false(args[1]) && is_false(args[2])) { + todo.append(2, args+1); + } + else if (is_true(args[0])) { + todo.append(2, args); + } + else { + SASSERT(is_false(args[0])); + todo.push_back(args[0]); + todo.push_back(args[2]); + } + break; + case OP_AND: + if (v) { + todo.append(sz, args); + } + else { + unsigned i = 0; + for (; !is_false(args[i]) && i < sz; ++i); + if (i == sz) { + fatal_error(1); + } + VERIFY(i < sz); + todo.push_back(args[i]); + } + break; + case OP_OR: + if (v) { + unsigned i = 0; + for (; !is_true(args[i]) && i < sz; ++i); + if (i == sz) { + fatal_error(1); + } + VERIFY(i < sz); + todo.push_back(args[i]); + } + else { + todo.append(sz, args); + } + break; + case OP_XOR: + case OP_NOT: + todo.append(sz, args); + break; + case OP_IMPLIES: + if (v) { + if (is_true(args[1])) { + todo.push_back(args[1]); + } + else if (is_false(args[0])) { + todo.push_back(args[0]); + } + else { + IF_VERBOSE(0, verbose_stream() << "Term not handled " << mk_pp(e, m) << "\n";); + UNREACHABLE(); + } + } + else { + todo.append(sz, args); + } + break; + default: + IF_VERBOSE(0, verbose_stream() << "Term not handled " << mk_pp(e, m) << "\n";); + UNREACHABLE(); + } + } + else { + tocollect.push_back(e); + } + } + + void model_evaluator::collect(ptr_vector const& formulas, ptr_vector& tocollect) { + ptr_vector todo; + todo.append(formulas); + m_visited.reset(); + + VERIFY(check_model(formulas)); + + while (!todo.empty()) { + app* e = to_app(todo.back()); + todo.pop_back(); + if (!m_visited.is_marked(e)) { + process_formula(e, todo, tocollect); + m_visited.mark(e, true); + } + } + m_visited.reset(); + } + + expr_ref_vector model_evaluator::prune_by_cone_of_influence(ptr_vector const & formulas) { + ptr_vector tocollect; + collect(formulas, tocollect); + m1.reset(); + m2.reset(); + for (unsigned i = 0; i < tocollect.size(); ++i) { + TRACE("pdr_verbose", tout << "collect: " << mk_pp(tocollect[i], m) << "\n";); + for_each_expr(*this, m_visited, tocollect[i]); + } + unsigned sz = m_model->get_num_constants(); + expr_ref e(m), eq(m); + expr_ref_vector model(m); + for (unsigned i = 0; i < sz; i++) { + func_decl * d = m_model->get_constant(i); + expr* val = m_model->get_const_interp(d); + e = m.mk_const(d); + if (m_visited.is_marked(e)) { + eq = m.mk_eq(e, val); + model.push_back(eq); + } + } + m_visited.reset(); + TRACE("pdr", tout << sz << " ==> " << model.size() << "\n";); + return model; + + } + + void model_evaluator::eval_arith(app* e) { + rational r, r2; + +#define ARG1 e->get_arg(0) +#define ARG2 e->get_arg(1) + + unsigned arity = e->get_num_args(); + for (unsigned i = 0; i < arity; ++i) { + expr* arg = e->get_arg(i); + if (is_x(arg)) { + set_x(e); + return; + } + SASSERT(!is_unknown(arg)); + } + switch(e->get_decl_kind()) { + case OP_NUM: + VERIFY(m_arith.is_numeral(e, r)); + set_number(e, r); + break; + case OP_IRRATIONAL_ALGEBRAIC_NUM: + set_x(e); + break; + case OP_LE: + set_bool(e, get_number(ARG1) <= get_number(ARG2)); + break; + case OP_GE: + set_bool(e, get_number(ARG1) >= get_number(ARG2)); + break; + case OP_LT: + set_bool(e, get_number(ARG1) < get_number(ARG2)); + break; + case OP_GT: + set_bool(e, get_number(ARG1) > get_number(ARG2)); + break; + case OP_ADD: + r = rational::zero(); + for (unsigned i = 0; i < arity; ++i) { + r += get_number(e->get_arg(i)); + } + set_number(e, r); + break; + case OP_SUB: + r = get_number(e->get_arg(0)); + for (unsigned i = 1; i < arity; ++i) { + r -= get_number(e->get_arg(i)); + } + set_number(e, r); + break; + case OP_UMINUS: + SASSERT(arity == 1); + set_number(e, get_number(e->get_arg(0))); + break; + case OP_MUL: + r = rational::one(); + for (unsigned i = 0; i < arity; ++i) { + r *= get_number(e->get_arg(i)); + } + set_number(e, r); + break; + case OP_DIV: + SASSERT(arity == 2); + r = get_number(ARG2); + if (r.is_zero()) { + set_x(e); } else { - todo.append(sz, args); + set_number(e, get_number(ARG1) / r); } + break; + case OP_IDIV: + SASSERT(arity == 2); + r = get_number(ARG2); + if (r.is_zero()) { + set_x(e); + } + else { + set_number(e, div(get_number(ARG1), r)); + } + break; + case OP_REM: + // rem(v1,v2) = if v2 >= 0 then mod(v1,v2) else -mod(v1,v2) + SASSERT(arity == 2); + r = get_number(ARG2); + if (r.is_zero()) { + set_x(e); + } + else { + r2 = mod(get_number(ARG1), r); + if (r.is_neg()) r2.neg(); + set_number(e, r2); + } + break; + case OP_MOD: + SASSERT(arity == 2); + r = get_number(ARG2); + if (r.is_zero()) { + set_x(e); + } + else { + set_number(e, mod(get_number(ARG1), r)); + } + break; + case OP_TO_REAL: + SASSERT(arity == 1); + set_number(e, get_number(ARG1)); + break; + case OP_TO_INT: + SASSERT(arity == 1); + set_number(e, floor(get_number(ARG1))); + break; + case OP_IS_INT: + SASSERT(arity == 1); + set_bool(e, get_number(ARG1).is_int()); + break; + case OP_POWER: + set_x(e); break; default: IF_VERBOSE(0, verbose_stream() << "Term not handled " << mk_pp(e, m) << "\n";); UNREACHABLE(); + break; } } - else { - tocollect.push_back(e); - } -} - -void model_evaluator::collect(ptr_vector const& formulas, ptr_vector& tocollect) { - ptr_vector todo; - todo.append(formulas); - m_visited.reset(); - VERIFY(check_model(formulas)); - - while (!todo.empty()) { - app* e = to_app(todo.back()); - todo.pop_back(); - if (!m_visited.is_marked(e)) { - process_formula(e, todo, tocollect); - m_visited.mark(e, true); - } - } - m_visited.reset(); -} - -expr_ref_vector model_evaluator::prune_by_cone_of_influence(ptr_vector const & formulas) { - ptr_vector tocollect; - collect(formulas, tocollect); - m1.reset(); - m2.reset(); - for (unsigned i = 0; i < tocollect.size(); ++i) { - TRACE("pdr_verbose", tout << "collect: " << mk_pp(tocollect[i], m) << "\n";); - for_each_expr(*this, m_visited, tocollect[i]); - } - unsigned sz = m_model->get_num_constants(); - expr_ref e(m), eq(m); - expr_ref_vector model(m); - for (unsigned i = 0; i < sz; i++) { - func_decl * d = m_model->get_constant(i); - expr* val = m_model->get_const_interp(d); - e = m.mk_const(d); - if (m_visited.is_marked(e)) { - eq = m.mk_eq(e, val); - model.push_back(eq); - } - } - m_visited.reset(); - TRACE("pdr", tout << sz << " ==> " << model.size() << "\n";); - return model; - -} - -void model_evaluator::eval_arith(app* e) { - rational r, r2; - -#define ARG1 e->get_arg(0) -#define ARG2 e->get_arg(1) - - unsigned arity = e->get_num_args(); - for (unsigned i = 0; i < arity; ++i) { - expr* arg = e->get_arg(i); - if (is_x(arg)) { - set_x(e); - return; - } - SASSERT(!is_unknown(arg)); - } - switch(e->get_decl_kind()) { - case OP_NUM: - VERIFY(m_arith.is_numeral(e, r)); - set_number(e, r); - break; - case OP_IRRATIONAL_ALGEBRAIC_NUM: - set_x(e); - break; - case OP_LE: - set_bool(e, get_number(ARG1) <= get_number(ARG2)); - break; - case OP_GE: - set_bool(e, get_number(ARG1) >= get_number(ARG2)); - break; - case OP_LT: - set_bool(e, get_number(ARG1) < get_number(ARG2)); - break; - case OP_GT: - set_bool(e, get_number(ARG1) > get_number(ARG2)); - break; - case OP_ADD: - r = rational::zero(); - for (unsigned i = 0; i < arity; ++i) { - r += get_number(e->get_arg(i)); - } - set_number(e, r); - break; - case OP_SUB: - r = get_number(e->get_arg(0)); - for (unsigned i = 1; i < arity; ++i) { - r -= get_number(e->get_arg(i)); - } - set_number(e, r); - break; - case OP_UMINUS: - SASSERT(arity == 1); - set_number(e, get_number(e->get_arg(0))); - break; - case OP_MUL: - r = rational::one(); - for (unsigned i = 0; i < arity; ++i) { - r *= get_number(e->get_arg(i)); - } - set_number(e, r); - break; - case OP_DIV: - SASSERT(arity == 2); - r = get_number(ARG2); - if (r.is_zero()) { + void model_evaluator::inherit_value(expr* e, expr* v) { + expr* w; + SASSERT(!is_unknown(v)); + SASSERT(m.get_sort(e) == m.get_sort(v)); + if (is_x(v)) { set_x(e); } - else { - set_number(e, get_number(ARG1) / r); + else if (m.is_bool(e)) { + SASSERT(m.is_bool(v)); + if (is_true(v)) set_true(e); + else if (is_false(v)) set_false(e); + else { + TRACE("pdr", tout << "not inherited:\n" << mk_pp(e, m) << "\n" << mk_pp(v, m) << "\n";); + set_x(e); + } } - break; - case OP_IDIV: - SASSERT(arity == 2); - r = get_number(ARG2); - if (r.is_zero()) { - set_x(e); + else if (m_arith.is_int_real(e)) { + set_number(e, get_number(v)); } - else { - set_number(e, div(get_number(ARG1), r)); + else if (m.is_value(v)) { + set_value(e, v); } - break; - case OP_REM: - // rem(v1,v2) = if v2 >= 0 then mod(v1,v2) else -mod(v1,v2) - SASSERT(arity == 2); - r = get_number(ARG2); - if (r.is_zero()) { - set_x(e); + else if (m_values.find(v, w)) { + set_value(e, w); } - else { - r2 = mod(get_number(ARG1), r); - if (r.is_neg()) r2.neg(); - set_number(e, r2); - } - break; - case OP_MOD: - SASSERT(arity == 2); - r = get_number(ARG2); - if (r.is_zero()) { - set_x(e); - } - else { - set_number(e, mod(get_number(ARG1), r)); - } - break; - case OP_TO_REAL: - SASSERT(arity == 1); - set_number(e, get_number(ARG1)); - break; - case OP_TO_INT: - SASSERT(arity == 1); - set_number(e, floor(get_number(ARG1))); - break; - case OP_IS_INT: - SASSERT(arity == 1); - set_bool(e, get_number(ARG1).is_int()); - break; - case OP_POWER: - set_x(e); - break; - default: - IF_VERBOSE(0, verbose_stream() << "Term not handled " << mk_pp(e, m) << "\n";); - UNREACHABLE(); - break; - } -} - -void model_evaluator::inherit_value(expr* e, expr* v) { - expr* w; - SASSERT(!is_unknown(v)); - SASSERT(m.get_sort(e) == m.get_sort(v)); - if (is_x(v)) { - set_x(e); - } - else if (m.is_bool(e)) { - SASSERT(m.is_bool(v)); - if (is_true(v)) set_true(e); - else if (is_false(v)) set_false(e); else { TRACE("pdr", tout << "not inherited:\n" << mk_pp(e, m) << "\n" << mk_pp(v, m) << "\n";); set_x(e); } } - else if (m_arith.is_int_real(e)) { - set_number(e, get_number(v)); - } - else if (m.is_value(v)) { - set_value(e, v); - } - else if (m_values.find(v, w)) { - set_value(e, w); - } - else { - TRACE("pdr", tout << "not inherited:\n" << mk_pp(e, m) << "\n" << mk_pp(v, m) << "\n";); - set_x(e); - } -} - -void model_evaluator::eval_iff(app* e, expr* arg1, expr* arg2) { - if (arg1 == arg2) { - set_true(e); - } - else if (is_x(arg1) || is_x(arg2)) { - set_x(e); - } - else { - bool val = is_true(arg1) == is_true(arg2); - SASSERT(val == (is_false(arg1) == is_false(arg2))); - if (val) { - set_true(e); + + bool model_evaluator::extract_array_func_interp(expr* a, vector& stores, expr_ref& else_case) { + SASSERT(m_array.is_array(a)); + + while (m_array.is_store(a)) { + expr_ref_vector store(m); + store.append(to_app(a)->get_num_args()-1, to_app(a)->get_args()+1); + stores.push_back(store); + a = to_app(a)->get_arg(0); } - else { - set_false(e); - } - } -} - -void model_evaluator::eval_basic(app* e) { - expr* arg1, *arg2; - expr *argCond, *argThen, *argElse, *arg; - bool has_x = false; - unsigned arity = e->get_num_args(); - switch(e->get_decl_kind()) { - case OP_AND: - for (unsigned j = 0; j < arity; ++j) { - expr * arg = e->get_arg(j); - if (is_false(arg)) { - set_false(e); - return; + + if (m_array.is_const(a)) { + else_case = to_app(a)->get_arg(0); + return true; + } + + if (m_array.is_as_array(a)) { + func_decl* f = m_array.get_as_array_func_decl(to_app(a)); + func_interp* g = m_model->get_func_interp(f); + unsigned sz = g->num_entries(); + unsigned arity = f->get_arity(); + for (unsigned i = 0; i < sz; ++i) { + expr_ref_vector store(m); + func_entry const* fe = g->get_entry(i); + store.append(arity, fe->get_args()); + store.push_back(fe->get_result()); + for (unsigned j = 0; j < store.size(); ++j) { + if (!is_ground(store[j].get())) { + return false; + } + } + stores.push_back(store); + } + else_case = g->get_else(); + if (!else_case) { + return false; } - else if (is_x(arg)) { - has_x = true; + if (!is_ground(else_case)) { + return false; + } + return true; + } + + return false; + } + + /** + best effort evaluator of extensional array equality. + */ + void model_evaluator::eval_array_eq(app* e, expr* arg1, expr* arg2) { + expr_ref v1(m), v2(m); + m_model->eval(arg1, v1); + m_model->eval(arg2, v2); + if (v1 == v2) { + set_true(e); + return; + } + sort* s = m.get_sort(arg1); + sort* r = get_array_range(s); + if (!r->is_infinite() && !r->is_very_big()) { + TRACE("pdr", tout << "equality is unknown: " << mk_pp(e, m) << "\n";); + set_x(e); + return; + } + vector store; + expr_ref else1(m), else2(m); + if (!extract_array_func_interp(v1, store, else1) || + !extract_array_func_interp(v2, store, else2)) { + TRACE("pdr", tout << "equality is unknown: " << mk_pp(e, m) << "\n";); + set_x(e); + return; + } + + if (else1 != else2) { + if (m.is_value(else1) && m.is_value(else2)) { + set_bool(e, false); } else { - SASSERT(is_true(arg)); - } - } - if (has_x) { - set_x(e); - } - else { - set_true(e); - } - break; - case OP_OR: - for (unsigned j = 0; j < arity; ++j) { - expr * arg = e->get_arg(j); - if (is_true(arg)) { - set_true(e); - return; - } - else if (is_x(arg)) { - has_x = true; - } - else { - SASSERT(is_false(arg)); - } - } - if (has_x) { - set_x(e); - } - else { - set_false(e); - } - break; - case OP_NOT: - VERIFY(m.is_not(e, arg)); - if (is_true(arg)) { - set_false(e); - } - else if (is_false(arg)) { - set_true(e); - } - else { - SASSERT(is_x(arg)); - set_x(e); - } - break; - case OP_IMPLIES: - VERIFY(m.is_implies(e, arg1, arg2)); - if (is_false(arg1) || is_true(arg2)) { - set_true(e); - } - else if (arg1 == arg2) { - set_true(e); - } - else if (is_true(arg1) && is_false(arg2)) { - set_false(e); - } - else { - SASSERT(is_x(arg1) || is_x(arg2)); - set_x(e); - } - break; - case OP_IFF: - VERIFY(m.is_iff(e, arg1, arg2)); - eval_iff(e, arg1, arg2); - break; - case OP_ITE: - VERIFY(m.is_ite(e, argCond, argThen, argElse)); - if (is_true(argCond)) { - inherit_value(e, argThen); - } - else if (is_false(argCond)) { - inherit_value(e, argElse); - } - else if (argThen == argElse) { - inherit_value(e, argThen); - } - else if (m.is_bool(e)) { - SASSERT(is_x(argCond)); - if (is_x(argThen) || is_x(argElse)) { + TRACE("pdr", tout << "equality is unknown: " << mk_pp(e, m) << "\n";); set_x(e); } - else if (is_true(argThen) == is_true(argElse)) { - inherit_value(e, argThen); + return; + } + + expr_ref s1(m), s2(m), w1(m), w2(m); + expr_ref_vector args1(m), args2(m); + args1.push_back(v1); + args2.push_back(v2); + for (unsigned i = 0; i < store.size(); ++i) { + args1.resize(1); + args2.resize(1); + args1.append(store[i].size()-1, store[i].c_ptr()); + args2.append(store[i].size()-1, store[i].c_ptr()); + s1 = m_array.mk_select(args1.size(), args1.c_ptr()); + s2 = m_array.mk_select(args2.size(), args2.c_ptr()); + m_model->eval(s1, w1); + m_model->eval(s2, w2); + if (w1 == w2) { + continue; + } + else if (m.is_value(w1) && m.is_value(w2)) { + set_bool(e, false); + return; } else { + TRACE("pdr", tout << "equality is unknown: " << mk_pp(e, m) << "\n";); set_x(e); + return; } } - else { - set_x(e); - } - break; - case OP_TRUE: - set_true(e); - break; - case OP_FALSE: - set_false(e); - break; - case OP_EQ: - VERIFY(m.is_eq(e, arg1, arg2)); - if (m.is_bool(arg1)) { - eval_iff(e, arg1, arg2); - } - else if (arg1 == arg2) { + set_bool(e, true); + } + + void model_evaluator::eval_eq(app* e, expr* arg1, expr* arg2) { + if (arg1 == arg2) { set_true(e); } + else if (m_array.is_array(arg1)) { + eval_array_eq(e, arg1, arg2); + } else if (is_x(arg1) || is_x(arg2)) { set_x(e); } + else if (m.is_bool(arg1)) { + bool val = is_true(arg1) == is_true(arg2); + SASSERT(val == (is_false(arg1) == is_false(arg2))); + if (val) { + set_true(e); + } + else { + set_false(e); + } + } else if (m_arith.is_int_real(arg1)) { set_bool(e, get_number(arg1) == get_number(arg2)); } @@ -648,164 +690,249 @@ void model_evaluator::eval_basic(app* e) { if (m.is_value(e1) && m.is_value(e2)) { set_bool(e, e1 == e2); } + else if (e1 == e2) { + set_bool(e, true); + } else { TRACE("pdr", tout << "not value equal:\n" << mk_pp(e1, m) << "\n" << mk_pp(e2, m) << "\n";); set_x(e); } } - break; - case OP_DISTINCT: { - vector values; - for (unsigned i = 0; i < arity; ++i) { - expr* arg = e->get_arg(i); - if (is_x(arg)) { + } + + void model_evaluator::eval_basic(app* e) { + expr* arg1, *arg2; + expr *argCond, *argThen, *argElse, *arg; + bool has_x = false; + unsigned arity = e->get_num_args(); + switch(e->get_decl_kind()) { + case OP_AND: + for (unsigned j = 0; j < arity; ++j) { + expr * arg = e->get_arg(j); + if (is_false(arg)) { + set_false(e); + return; + } + else if (is_x(arg)) { + has_x = true; + } + else { + SASSERT(is_true(arg)); + } + } + if (has_x) { set_x(e); - return; } - values.push_back(get_number(arg)); - } - std::sort(values.begin(), values.end()); - for (unsigned i = 0; i + 1 < values.size(); ++i) { - if (values[i] == values[i+1]) { + else { + set_true(e); + } + break; + case OP_OR: + for (unsigned j = 0; j < arity; ++j) { + expr * arg = e->get_arg(j); + if (is_true(arg)) { + set_true(e); + return; + } + else if (is_x(arg)) { + has_x = true; + } + else { + SASSERT(is_false(arg)); + } + } + if (has_x) { + set_x(e); + } + else { set_false(e); - return; } + break; + case OP_NOT: + VERIFY(m.is_not(e, arg)); + if (is_true(arg)) { + set_false(e); + } + else if (is_false(arg)) { + set_true(e); + } + else { + SASSERT(is_x(arg)); + set_x(e); + } + break; + case OP_IMPLIES: + VERIFY(m.is_implies(e, arg1, arg2)); + if (is_false(arg1) || is_true(arg2)) { + set_true(e); + } + else if (arg1 == arg2) { + set_true(e); + } + else if (is_true(arg1) && is_false(arg2)) { + set_false(e); + } + else { + SASSERT(is_x(arg1) || is_x(arg2)); + set_x(e); + } + break; + case OP_IFF: + VERIFY(m.is_iff(e, arg1, arg2)); + eval_eq(e, arg1, arg2); + break; + case OP_ITE: + VERIFY(m.is_ite(e, argCond, argThen, argElse)); + if (is_true(argCond)) { + inherit_value(e, argThen); + } + else if (is_false(argCond)) { + inherit_value(e, argElse); + } + else if (argThen == argElse) { + inherit_value(e, argThen); + } + else if (m.is_bool(e)) { + SASSERT(is_x(argCond)); + if (is_x(argThen) || is_x(argElse)) { + set_x(e); + } + else if (is_true(argThen) == is_true(argElse)) { + inherit_value(e, argThen); + } + else { + set_x(e); + } + } + else { + set_x(e); + } + break; + case OP_TRUE: + set_true(e); + break; + case OP_FALSE: + set_false(e); + break; + case OP_EQ: + VERIFY(m.is_eq(e, arg1, arg2)); + eval_eq(e, arg1, arg2); + break; + case OP_DISTINCT: { + vector values; + for (unsigned i = 0; i < arity; ++i) { + expr* arg = e->get_arg(i); + if (is_x(arg)) { + set_x(e); + return; + } + values.push_back(get_number(arg)); + } + std::sort(values.begin(), values.end()); + for (unsigned i = 0; i + 1 < values.size(); ++i) { + if (values[i] == values[i+1]) { + set_false(e); + return; + } + } + set_true(e); + break; + } + default: + IF_VERBOSE(0, verbose_stream() << "Term not handled " << mk_pp(e, m) << "\n";); + UNREACHABLE(); } - set_true(e); - break; } - default: - IF_VERBOSE(0, verbose_stream() << "Term not handled " << mk_pp(e, m) << "\n";); - UNREACHABLE(); - } -} - -bool model_evaluator::check_model(ptr_vector const& formulas) { - ptr_vector todo(formulas); - - while (!todo.empty()) { - expr * curr_e = todo.back(); - - if (!is_app(curr_e)) { + + bool model_evaluator::check_model(ptr_vector const& formulas) { + ptr_vector todo(formulas); + + while (!todo.empty()) { + expr * curr_e = todo.back(); + + if (!is_app(curr_e)) { + todo.pop_back(); + continue; + } + app * curr = to_app(curr_e); + + if (!is_unknown(curr)) { + todo.pop_back(); + continue; + } + unsigned arity = curr->get_num_args(); + for (unsigned i = 0; i < arity; ++i) { + if (is_unknown(curr->get_arg(i))) { + todo.push_back(curr->get_arg(i)); + } + } + if (todo.back() != curr) { + continue; + } todo.pop_back(); - continue; + if (curr->get_family_id() == m_arith.get_family_id()) { + eval_arith(curr); + } + else if (curr->get_family_id() == m.get_basic_family_id()) { + eval_basic(curr); + } + else { + expr_ref vl(m); + m_model->eval(curr, vl); + assign_value(curr, vl); + } + + IF_VERBOSE(35,verbose_stream() << "assigned "<get_num_args(); - for (unsigned i = 0; i < arity; ++i) { - if (is_unknown(curr->get_arg(i))) { - todo.push_back(curr->get_arg(i)); + + bool has_x = false; + for (unsigned i = 0; i < formulas.size(); ++i) { + expr * form = formulas[i]; + SASSERT(!is_unknown(form)); + TRACE("pdr_verbose", + tout << "formula is " << (is_true(form) ? "true" : is_false(form) ? "false" : "unknown") << "\n" <get_family_id() == m_arith.get_family_id()) { - eval_arith(curr); - } - else if (curr->get_family_id() == m.get_basic_family_id()) { - eval_basic(curr); - } - else { - expr_ref vl(m); - m_model->eval(curr, vl); - assign_value(curr, vl); - } - - IF_VERBOSE(35,verbose_stream() << "assigned "<get_num_parameters(); - - ptr_vector domain; - domain.push_back(arr_sort); - - //we push params of the array as remaining arguments of the store. The first - //num_params-1 parameters are indices and the last one is the range of the array - for (unsigned i=0; iget_parameter(i).get_ast())); - } - - return m.mk_func_decl(array_fid, OP_STORE, - arr_sort->get_num_parameters(), arr_sort->get_parameters(), - domain.size(), domain.c_ptr(), arr_sort); + return !has_x; } - void get_as_array_value(const model_core & mdl, expr * arr_e, expr_ref& res) { - ast_manager& m = mdl.get_manager(); - array_util pl(m); - SASSERT(pl.is_as_array(arr_e)); - - app * arr = to_app(arr_e); - - unsigned sz = 0; - func_decl_ref f(pl.get_as_array_func_decl(arr), m); - sort * arr_sort = arr->get_decl()->get_range(); - func_interp* g = mdl.get_func_interp(f); - - res = pl.mk_const_array(arr_sort, g->get_else()); - - unsigned arity = f->get_arity(); - - sz = g->num_entries(); - if (sz) { - func_decl_ref store_fn(mk_store(m, arr_sort), m); - ptr_vector store_args; - for (unsigned i = 0; i < sz; ++i) { - const func_entry * fe = g->get_entry(i); - store_args.reset(); - store_args.push_back(res); - store_args.append(arity, fe->get_args()); - store_args.push_back(fe->get_result()); - res = m.mk_app(store_fn, store_args.size(), store_args.c_ptr()); + expr_ref model_evaluator::eval(model_ref& model, expr* e) { + expr_ref result(m); + m_model = model; + VERIFY(m_model->eval(e, result, true)); + if (m_array.is_array(e)) { + vector stores; + expr_ref_vector args(m); + expr_ref else_case(m); + if (extract_array_func_interp(result, stores, else_case)) { + result = m_array.mk_const_array(m.get_sort(e), else_case); + while (!stores.empty() && stores.back().back() == else_case) { + stores.pop_back(); + } + for (unsigned i = stores.size(); i > 0; ) { + --i; + args.resize(1); + args[0] = result; + args.append(stores[i]); + result = m_array.mk_store(args.size(), args.c_ptr()); + } + return result; } } + return result; } - void get_value_from_model(const model_core & mdl, func_decl * f, expr_ref& res) { - SASSERT(f->get_arity()==0); - ast_manager& m = mdl.get_manager(); - - res = mdl.get_const_interp(f); - - array_util pl(m); - - if (pl.is_as_array(res)) { - get_as_array_value(mdl, res, res); - } - } - + void reduce_disequalities(model& model, unsigned threshold, expr_ref& fml) { ast_manager& m = fml.get_manager(); expr_ref_vector conjs(m); @@ -914,8 +1041,7 @@ bool model_evaluator::check_model(ptr_vector const& formulas) { br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) { return m_r.mk_app_core(f, num, args, result); } - ite_hoister_cfg(ast_manager & m, params_ref const & p):m_r(m) {} - + ite_hoister_cfg(ast_manager & m, params_ref const & p):m_r(m) {} }; class ite_hoister_star : public rewriter_tpl { @@ -1108,5 +1234,6 @@ bool model_evaluator::check_model(ptr_vector const& formulas) { template class rewriter_tpl; +template class rewriter_tpl; diff --git a/src/muz_qe/pdr_util.h b/src/muz_qe/pdr_util.h index 1d1e86262..89598d347 100644 --- a/src/muz_qe/pdr_util.h +++ b/src/muz_qe/pdr_util.h @@ -28,6 +28,7 @@ Revision History: #include "trace.h" #include "vector.h" #include "arith_decl_plugin.h" +#include "array_decl_plugin.h" #include "bv_decl_plugin.h" @@ -56,6 +57,7 @@ namespace pdr { class model_evaluator { ast_manager& m; arith_util m_arith; + array_util m_array; obj_map m_numbers; expr_ref_vector m_refs; obj_map m_values; @@ -78,7 +80,8 @@ namespace pdr { expr_ref_vector prune_by_cone_of_influence(ptr_vector const & formulas); void eval_arith(app* e); void eval_basic(app* e); - void eval_iff(app* e, expr* arg1, expr* arg2); + void eval_eq(app* e, expr* arg1, expr* arg2); + void eval_array_eq(app* e, expr* arg1, expr* arg2); void inherit_value(expr* e, expr* v); inline bool is_unknown(expr* x) { return !m1.is_marked(x) && !m2.is_marked(x); } @@ -99,9 +102,11 @@ namespace pdr { inline void set_value(expr* x, expr* v) { set_v(x); m_refs.push_back(v); m_values.insert(x, v); } bool check_model(ptr_vector const & formulas); + + bool extract_array_func_interp(expr* a, vector& stores, expr_ref& else_case); public: - model_evaluator(ast_manager& m) : m(m), m_arith(m), m_refs(m) {} + model_evaluator(ast_manager& m) : m(m), m_arith(m), m_array(m), m_refs(m) {} /** \brief extract equalities from model that suffice to satisfy formula. @@ -118,12 +123,13 @@ namespace pdr { */ expr_ref_vector minimize_literals(ptr_vector const & formulas, model_ref& mdl); - - // for_each_expr visitor. + /** + for_each_expr visitor. + */ void operator()(expr* e) {} - }; - void get_value_from_model(const model_core & mdl, func_decl * f, expr_ref& res); + expr_ref eval(model_ref& mdl, expr* e); + }; /** \brief replace variables that are used in many disequalities by diff --git a/src/smt/smt_implied_equalities.cpp b/src/smt/smt_implied_equalities.cpp index ef8d27e2f..91784f5f5 100644 --- a/src/smt/smt_implied_equalities.cpp +++ b/src/smt/smt_implied_equalities.cpp @@ -29,6 +29,7 @@ Revision History: #include "array_decl_plugin.h" #include "uint_set.h" #include "model_v2_pp.h" +#include "smt_value_sort.h" namespace smt { @@ -134,44 +135,7 @@ namespace smt { } } } - } - - bool is_simple_type(sort* s) { - arith_util arith(m); - datatype_util data(m); - - ptr_vector sorts; - ast_mark mark; - sorts.push_back(s); - - while (!sorts.empty()) { - s = sorts.back(); - sorts.pop_back(); - if (mark.is_marked(s)) { - continue; - } - mark.mark(s, true); - if (arith.is_int_real(s)) { - // simple - } - else if (m.is_bool(s)) { - // simple - } - else if (data.is_datatype(s)) { - ptr_vector const& cs = *data.get_datatype_constructors(s); - for (unsigned i = 0; i < cs.size(); ++i) { - func_decl* f = cs[i]; - for (unsigned j = 0; j < f->get_arity(); ++j) { - sorts.push_back(f->get_domain(j)); - } - } - } - else { - return false; - } - } - return true; - } + } /** \brief Extract implied equalities for a collection of terms in the current context. @@ -216,7 +180,7 @@ namespace smt { uint_set non_values; - if (!is_simple_type(srt)) { + if (!is_value_sort(m, srt)) { for (unsigned i = 0; i < terms.size(); ++i) { non_values.insert(i); } diff --git a/src/smt/smt_value_sort.cpp b/src/smt/smt_value_sort.cpp new file mode 100644 index 000000000..a840b77b7 --- /dev/null +++ b/src/smt/smt_value_sort.cpp @@ -0,0 +1,74 @@ +/*++ +Copyright (c) 2012 Microsoft Corporation + +Module Name: + + smt_value_sort.cpp + +Abstract: + + Determine if elements of a given sort can be values. + +Author: + + Nikolaj Bjorner (nbjorner) 2012-11-25 + +Revision History: + + +--*/ + +#include "smt_value_sort.h" +#include "bv_decl_plugin.h" +#include "arith_decl_plugin.h" +#include "datatype_decl_plugin.h" + +namespace smt { + + + bool is_value_sort(ast_manager& m, sort* s) { + arith_util arith(m); + datatype_util data(m); + bv_util bv(m); + + ptr_vector sorts; + ast_mark mark; + sorts.push_back(s); + + while (!sorts.empty()) { + s = sorts.back(); + sorts.pop_back(); + if (mark.is_marked(s)) { + continue; + } + mark.mark(s, true); + if (arith.is_int_real(s)) { + // simple + } + else if (m.is_bool(s)) { + // simple + } + else if (bv.is_bv_sort(s)) { + // simple + } + else if (data.is_datatype(s)) { + ptr_vector const& cs = *data.get_datatype_constructors(s); + for (unsigned i = 0; i < cs.size(); ++i) { + func_decl* f = cs[i]; + for (unsigned j = 0; j < f->get_arity(); ++j) { + sorts.push_back(f->get_domain(j)); + } + } + } + else { + return false; + } + } + return true; + } + + bool is_value_sort(ast_manager& m, expr* e) { + return is_value_sort(m, m.get_sort(e)); + } + +} diff --git a/src/smt/smt_value_sort.h b/src/smt/smt_value_sort.h new file mode 100644 index 000000000..ae32be62a --- /dev/null +++ b/src/smt/smt_value_sort.h @@ -0,0 +1,37 @@ +/*++ +Copyright (c) 2012 Microsoft Corporation + +Module Name: + + smt_value_sort.h + +Abstract: + + Determine if elements of a given sort can be values. + +Author: + + Nikolaj Bjorner (nbjorner) 2012-11-25 + +Revision History: + + +--*/ + + +#ifndef __SMT_VALUE_SORT_H__ +#define __SMT_VALUE_SORT_H__ + +#include "ast.h" + + +namespace smt { + + bool is_value_sort(ast_manager& m, sort* s); + + bool is_value_sort(ast_manager& m, expr* e); + +}; + + +#endif